Skip to content

Commit

Permalink
feat(gatsby-graphiql-explorer): allow hiding explorer using query par…
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh authored and DSchau committed May 28, 2019
1 parent 9d59192 commit 45b5a0b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/gatsby-graphiql-explorer/src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ function locationQuery(params) {
return (
`?` +
Object.keys(params)
.filter(function(key) {
return Boolean(params[key])
})
.map(function(key) {
return encodeURIComponent(key) + `=` + encodeURIComponent(params[key])
})
Expand All @@ -42,6 +39,7 @@ const graphqlParamNames = {
query: true,
variables: true,
operationName: true,
explorerIsOpen: true,
}
const otherParams = {}
for (var k in parameters) {
Expand Down Expand Up @@ -135,9 +133,14 @@ ${queryExample}
`
}

const storedExplorerPaneState = window.localStorage
? window.localStorage.getItem(`graphiql:graphiqlExplorerOpen`) !== `false`
: true
const storedExplorerPaneState =
typeof parameters.explorerIsOpen !== `undefined`
? parameters.explorerIsOpen === `false`
? false
: true
: window.localStorage
? window.localStorage.getItem(`graphiql:graphiqlExplorerOpen`) !== `false`
: true

class App extends React.Component {
state = {
Expand Down Expand Up @@ -197,6 +200,8 @@ class App extends React.Component {
newExplorerIsOpen
)
}
parameters.explorerIsOpen = newExplorerIsOpen
updateURL()
this.setState({ explorerIsOpen: newExplorerIsOpen })
}

Expand Down

0 comments on commit 45b5a0b

Please sign in to comment.