Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding switching tabs with numbers 🚀 #354

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/graphql-playground-electron/src/ElectronApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ cd ${folderPath}; graphql playground`)
this.prevTab()
} else if (e.key === '}' && e.metaKey) {
this.nextTab()
} else if (e.key >= 1 && e.key <= 9 && e.metaKey) {
this.playground.switchTab(e.key)
}
}

Expand Down
15 changes: 15 additions & 0 deletions packages/graphql-playground/src/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,21 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
}
}

public switchTab = (index: number) => {
const arrayIndex = index - 1
const { sessions, selectedSessionIndex } = this.state
const numberOfSessions = sessions.length

if (arrayIndex !== selectedSessionIndex || arrayIndex <= numberOfSessions) {
this.setState(state => {
return {
...state,
selectedSessionIndex: arrayIndex,
}
})
}
}

public handleNewSession = (newIndexZero: boolean = false) => {
const session = this.createSession()
if (session.query === defaultQuery) {
Expand Down