Skip to content

Commit 9f8c78c

Browse files
fix: render query history panel only when it's toggled (#1821)
Use application to hide query history panel instead of CSS. Improves perf, reduces regression surface area. Co-authored-by: Rikki Schulte <[email protected]>
1 parent 2d91916 commit 9f8c78c

6 files changed

Lines changed: 45 additions & 20 deletions

File tree

.changeset/metal-cougars-fry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphiql': patch
3+
---
4+
5+
fix: render query history panel only when it's toggled, instead of hiding with CSS

.github/workflows/deploy-preview.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
- '**.md'
77
- 'examples'
88
- '!examples/monaco-graphql-webpack'
9+
pull_request:
10+
types: [opened, synchronize]
911

1012
jobs:
1113
build:

.github/workflows/license-check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ on:
33
push:
44
paths:
55
- 'yarn.lock'
6+
pull_request:
7+
types: [opened, synchronize]
68

79
jobs:
810
check:

.github/workflows/push-pr.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: CI
2-
on: [push]
2+
on:
3+
pull_request:
4+
types: [opened, synchronize]
35

46
jobs:
57
lint:

packages/graphiql/src/components/GraphiQL.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -482,25 +482,27 @@ export class GraphiQL extends React.Component<GraphiQLProps, GraphiQLState> {
482482
this.graphiqlContainer = n;
483483
}}
484484
className="graphiql-container">
485-
<div className="historyPaneWrap" style={historyPaneStyle}>
486-
<QueryHistory
487-
ref={node => {
488-
this._queryHistory = node;
489-
}}
490-
operationName={this.state.operationName}
491-
query={this.state.query}
492-
variables={this.state.variables}
493-
onSelectQuery={this.handleSelectHistoryQuery}
494-
storage={this._storage}
495-
queryID={this._editorQueryID}>
496-
<button
497-
className="docExplorerHide"
498-
onClick={this.handleToggleHistory}
499-
aria-label="Close History">
500-
{'\u2715'}
501-
</button>
502-
</QueryHistory>
503-
</div>
485+
{this.state.historyPaneOpen && (
486+
<div className="historyPaneWrap" style={historyPaneStyle}>
487+
<QueryHistory
488+
ref={node => {
489+
this._queryHistory = node;
490+
}}
491+
operationName={this.state.operationName}
492+
query={this.state.query}
493+
variables={this.state.variables}
494+
onSelectQuery={this.handleSelectHistoryQuery}
495+
storage={this._storage}
496+
queryID={this._editorQueryID}>
497+
<button
498+
className="docExplorerHide"
499+
onClick={this.handleToggleHistory}
500+
aria-label="Close History">
501+
{'\u2715'}
502+
</button>
503+
</QueryHistory>
504+
</div>
505+
)}
504506
<div className="editorWrap">
505507
<div className="topBarWrap">
506508
<div className="topBar">

packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ describe('GraphiQL', () => {
170170
expect(queryVariables3?.style.height).toEqual('');
171171
});
172172

173+
it('defaults to closed history panel', () => {
174+
const { container } = render(<GraphiQL fetcher={noOpFetcher} />);
175+
expect(container.querySelector('.historyPaneWrap')).not.toBeInTheDocument();
176+
});
177+
173178
it('adds a history item when the execute query function button is clicked', () => {
174179
const { getByTitle, container } = render(
175180
<GraphiQL
@@ -180,6 +185,7 @@ describe('GraphiQL', () => {
180185
fetcher={noOpFetcher}
181186
/>,
182187
);
188+
fireEvent.click(getByTitle('Show History'));
183189
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
184190
expect(container.querySelectorAll('.history-contents li')).toHaveLength(1);
185191
});
@@ -188,6 +194,7 @@ describe('GraphiQL', () => {
188194
const { getByTitle, container } = render(
189195
<GraphiQL query={mockBadQuery} fetcher={noOpFetcher} />,
190196
);
197+
fireEvent.click(getByTitle('Show History'));
191198
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
192199
expect(container.querySelectorAll('.history-contents li')).toHaveLength(0);
193200
});
@@ -202,6 +209,7 @@ describe('GraphiQL', () => {
202209
headers={mockHeaders1}
203210
/>,
204211
);
212+
fireEvent.click(getByTitle('Show History'));
205213
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
206214
expect(container.querySelectorAll('.history-contents li')).toHaveLength(1);
207215
});
@@ -216,6 +224,7 @@ describe('GraphiQL', () => {
216224
headers={mockHeaders1}
217225
/>,
218226
);
227+
fireEvent.click(getByTitle('Show History'));
219228
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
220229
expect(container.querySelectorAll('.history-contents li')).toHaveLength(1);
221230
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
@@ -232,6 +241,7 @@ describe('GraphiQL', () => {
232241
headers={mockHeaders1}
233242
/>,
234243
);
244+
fireEvent.click(getByTitle('Show History'));
235245
const executeQueryButton = getByTitle('Execute Query (Ctrl-Enter)');
236246
fireEvent.click(executeQueryButton);
237247
expect(container.querySelectorAll('.history-contents li')).toHaveLength(1);
@@ -260,6 +270,7 @@ describe('GraphiQL', () => {
260270
headers={mockHeaders1}
261271
/>,
262272
);
273+
fireEvent.click(getByTitle('Show History'));
263274
const executeQueryButton = getByTitle('Execute Query (Ctrl-Enter)');
264275
fireEvent.click(executeQueryButton);
265276
expect(container.querySelectorAll('.history-label')).toHaveLength(1);
@@ -286,6 +297,7 @@ describe('GraphiQL', () => {
286297
headerEditorEnabled
287298
/>,
288299
);
300+
fireEvent.click(getByTitle('Show History'));
289301
const executeQueryButton = getByTitle('Execute Query (Ctrl-Enter)');
290302
fireEvent.click(executeQueryButton);
291303
expect(container.querySelectorAll('.history-label')).toHaveLength(1);

0 commit comments

Comments
 (0)