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
expose variableEditorOpen to set a default value #744
Conversation
can this be merged? |
@christieb7007 looks good to me, other than the unneeded diff to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your pull request! The prop name variableEditorOpen
implies the parent controls whether the variable editor is open or not; however this PR only uses this prop for the initial state. Renaming it to defaultVariableEditorOpen
would more accurately describe what the current implementation does.
I'd rather that we give the parent full control by using the variableEditorOpen
prop in render()
(falling back to state if not provided) and calling a callback onVariableEditorOpenChange
to update parent state when the variable editor is toggled.
As @acao mentions, please revert changes to package.json
.
I've updated the PR so that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the PR!
There are a few minor issues that this change introduces to the user experience. One that's easy to address is that if variableEditorOpen={false}
and the user hovers the closed variable panel the n-resize
cursor shows. We can fix that here:
graphiql/src/components/GraphiQL.js
Line 372 in 5b9012e
style={{ cursor: variableOpen ? 'row-resize' : 'n-resize' }} |
However the other issue that remains is the drag resizing of the variables pane. It would be a shame to lose that, but I think it will currently behave oddly because it thinks it's setting the variableEditorOpen
state to false, and changing the panel height too:
graphiql/src/components/GraphiQL.js
Line 988 in 5b9012e
variableEditorOpen: false, |
I think it would be good to solve these issues by making the component "controlled" so that it can send the open/close signals up to the parent component. However I think there still might be some complexity around the panel size. What do you think?
example/index.html
Outdated
@@ -140,6 +140,7 @@ | |||
operationName: parameters.operationName, | |||
onEditQuery: onEditQuery, | |||
onEditVariables: onEditVariables, | |||
variableEditorOpen: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this line, I don't think we should lock the variable editor open in this example.
variableEditorOpen: true, |
Apologies for the delay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just a minor issue with the example 👍
@@ -143,6 +143,7 @@ | |||
operationName: parameters.operationName, | |||
onEditQuery: onEditQuery, | |||
onEditVariables: onEditVariables, | |||
variableEditorOpen: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variableEditorOpen: true, | |
defaultVariableEditorOpen: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -120,6 +121,9 @@ export class GraphiQL extends React.Component { | |||
docExplorerOpen = this._storage.get('docExplorerOpen') === 'true'; | |||
} | |||
|
|||
// initial variable editor pane open | |||
const variableEditorOpen = props.defaultVariableEditorOpen !== undefined ? props.defaultVariableEditorOpen : Boolean(variables); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Note to self: comparing against undefined
should be safe in modern browsers; I think this is okay.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spot on! Thanks for your work on this PR 👍
#741