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

expose variableEditorOpen to set a default value #744

Merged
merged 14 commits into from Aug 13, 2019

Conversation

christieb7007
Copy link
Contributor

@christieb7007
Copy link
Contributor Author

can this be merged?

@acao
Copy link
Member

acao commented Jun 1, 2019

@christieb7007 looks good to me, other than the unneeded diff to package.json. can you remove that change from the PR?

Copy link
Member

@benjie benjie left a 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.

@christieb7007
Copy link
Contributor Author

I've updated the PR so that the variableEditorOpen prop is evaluated in the render() method as well as update tests/README/example

Copy link
Member

@benjie benjie left a 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:

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:

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?

@@ -140,6 +140,7 @@
operationName: parameters.operationName,
onEditQuery: onEditQuery,
onEditVariables: onEditVariables,
variableEditorOpen: true,
Copy link
Member

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.

Suggested change
variableEditorOpen: true,

@christieb7007
Copy link
Contributor Author

Apologies for the delay.
The functionality I was thinking of was actually just the defaultVariableEditorOpen - maybe the controlled component part can be in a separate PR.

Copy link
Member

@benjie benjie left a 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
variableEditorOpen: true,
defaultVariableEditorOpen: true,

Copy link
Contributor Author

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);
Copy link
Member

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.)

Copy link
Member

@benjie benjie left a 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 👍

@benjie benjie merged commit 3537316 into graphql:master Aug 13, 2019
marceloverdijk added a commit to micronaut-projects/micronaut-graphql that referenced this pull request Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants