{this.props.beforeTopBarContent}
@@ -806,9 +829,10 @@ class GraphiQLWithContext extends React.Component<
keyMap={this.props.keyMap}
onClickReference={() => {
if (
- this.props.docResize.hiddenElement === 'first'
+ this.props.pluginResize.hiddenElement ===
+ 'first'
) {
- this.props.docResize.setHiddenElement(null);
+ this.props.pluginResize.setHiddenElement(null);
}
}}
onCopyQuery={this.props.onCopyQuery}
diff --git a/packages/graphiql/src/components/QueryHistory.tsx b/packages/graphiql/src/components/QueryHistory.tsx
deleted file mode 100644
index e933176602c..00000000000
--- a/packages/graphiql/src/components/QueryHistory.tsx
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * Copyright (c) 2021 GraphQL Contributors.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-
-import {
- HistoryContextType,
- useHistoryContext,
- useSelectHistoryItem,
-} from '@graphiql/react';
-import { QueryStoreItem } from '@graphiql/toolkit';
-import React, { useEffect, useRef, useState } from 'react';
-
-export function QueryHistory() {
- const { hide, items } = useHistoryContext({
- nonNull: true,
- }) as HistoryContextType;
-
- return (
-
-
-
History
-
- hide()}
- aria-label="Close History">
- {'\u2715'}
-
-
-
-
- {items
- .slice()
- .reverse()
- .map((item, i) => {
- return (
-
- );
- })}
-
-
- );
-}
-
-type QueryHistoryItemProps = {
- item: QueryStoreItem;
-};
-
-export function QueryHistoryItem(props: QueryHistoryItemProps) {
- const { editLabel, toggleFavorite } = useHistoryContext({ nonNull: true });
- const selectHistoryItem = useSelectHistoryItem();
- const editField = useRef
(null);
- const [isEditable, setIsEditable] = useState(false);
-
- useEffect(() => {
- if (isEditable && editField.current) {
- editField.current.focus();
- }
- }, [isEditable]);
-
- const displayName =
- props.item.label ||
- props.item.operationName ||
- props.item.query
- ?.split('\n')
- .filter(line => line.indexOf('#') !== 0)
- .join('');
- const starIcon = props.item.favorite ? '\u2605' : '\u2606';
- return (
-
- {isEditable ? (
- {
- e.stopPropagation();
- setIsEditable(false);
- editLabel({ ...props.item, label: e.target.value });
- }}
- onKeyDown={e => {
- if (e.keyCode === 13) {
- e.stopPropagation();
- setIsEditable(false);
- editLabel({ ...props.item, label: e.currentTarget.value });
- }
- }}
- placeholder="Type a label"
- />
- ) : (
- {
- selectHistoryItem(props.item);
- }}>
- {displayName}
-
- )}
- {
- e.stopPropagation();
- setIsEditable(true);
- }}
- aria-label="Edit label">
- {'\u270e'}
-
- {
- e.stopPropagation();
- toggleFavorite(props.item);
- }}
- aria-label={props.item.favorite ? 'Remove favorite' : 'Add favorite'}>
- {starIcon}
-
-
- );
-}
diff --git a/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx b/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx
index d0959f015cb..49586570a06 100644
--- a/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx
+++ b/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx
@@ -127,11 +127,11 @@ describe('GraphiQL', () => {
const { container } = render(
,
);
- expect(container.querySelector('.docExplorerWrap')).toBeInTheDocument();
+ expect(container.querySelector('.graphiql-plugin')).toBeInTheDocument();
});
it('defaults to closed docExplorer', () => {
const { container } = render( );
- expect(container.querySelector('.docExplorerWrap')).not.toBeVisible();
+ expect(container.querySelector('.graphiql-plugin')).not.toBeVisible();
});
it('accepts a defaultVariableEditorOpen param', () => {
@@ -167,7 +167,9 @@ describe('GraphiQL', () => {
it('defaults to closed history panel', () => {
const { container } = render( );
- expect(container.querySelector('.historyPaneWrap')).not.toBeInTheDocument();
+ expect(
+ container.querySelector('.graphiql-history'),
+ ).not.toBeInTheDocument();
});
it('will save history item even when history panel is closed', () => {
@@ -182,7 +184,9 @@ describe('GraphiQL', () => {
);
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
fireEvent.click(getByTitle('Show History'));
- expect(container.querySelectorAll('.history-contents li')).toHaveLength(1);
+ expect(
+ container.querySelectorAll('.graphiql-history-items li'),
+ ).toHaveLength(1);
});
it('adds a history item when the execute query function button is clicked', () => {
@@ -197,7 +201,9 @@ describe('GraphiQL', () => {
);
fireEvent.click(getByTitle('Show History'));
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
- expect(container.querySelectorAll('.history-contents li')).toHaveLength(1);
+ expect(
+ container.querySelectorAll('.graphiql-history-items li'),
+ ).toHaveLength(1);
});
it('will not save invalid queries', () => {
@@ -206,7 +212,9 @@ describe('GraphiQL', () => {
);
fireEvent.click(getByTitle('Show History'));
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
- expect(container.querySelectorAll('.history-contents li')).toHaveLength(0);
+ expect(
+ container.querySelectorAll('.graphiql-history-items li'),
+ ).toHaveLength(0);
});
it('will save if there was not a previously saved query', () => {
@@ -221,7 +229,9 @@ describe('GraphiQL', () => {
);
fireEvent.click(getByTitle('Show History'));
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
- expect(container.querySelectorAll('.history-contents li')).toHaveLength(1);
+ expect(
+ container.querySelectorAll('.graphiql-history-items li'),
+ ).toHaveLength(1);
});
it('will not save a query if the query is the same as previous query', () => {
@@ -236,9 +246,13 @@ describe('GraphiQL', () => {
);
fireEvent.click(getByTitle('Show History'));
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
- expect(container.querySelectorAll('.history-contents li')).toHaveLength(1);
+ expect(
+ container.querySelectorAll('.graphiql-history-items li'),
+ ).toHaveLength(1);
fireEvent.click(getByTitle('Execute Query (Ctrl-Enter)'));
- expect(container.querySelectorAll('.history-contents li')).toHaveLength(1);
+ expect(
+ container.querySelectorAll('.graphiql-history-items li'),
+ ).toHaveLength(1);
});
it('will save if new query is different than previous query', async () => {
@@ -255,7 +269,9 @@ describe('GraphiQL', () => {
fireEvent.click(getByTitle('Show History'));
const executeQueryButton = getByTitle('Execute Query (Ctrl-Enter)');
fireEvent.click(executeQueryButton);
- expect(container.querySelectorAll('.history-contents li')).toHaveLength(1);
+ expect(container.querySelectorAll('.graphiql-history-item')).toHaveLength(
+ 1,
+ );
fireEvent.change(
container.querySelector('[data-testid="query-editor"] .mockCodeMirror'),
@@ -268,7 +284,9 @@ describe('GraphiQL', () => {
await sleep(150);
fireEvent.click(executeQueryButton);
- expect(container.querySelectorAll('.history-label')).toHaveLength(2);
+ expect(container.querySelectorAll('.graphiql-history-item')).toHaveLength(
+ 2,
+ );
});
it('will save query if variables are different', async () => {
@@ -285,7 +303,9 @@ describe('GraphiQL', () => {
fireEvent.click(getByTitle('Show History'));
const executeQueryButton = getByTitle('Execute Query (Ctrl-Enter)');
fireEvent.click(executeQueryButton);
- expect(container.querySelectorAll('.history-label')).toHaveLength(1);
+ expect(container.querySelectorAll('.graphiql-history-item')).toHaveLength(
+ 1,
+ );
await wait();
fireEvent.change(
@@ -296,7 +316,9 @@ describe('GraphiQL', () => {
);
fireEvent.click(executeQueryButton);
- expect(container.querySelectorAll('.history-label')).toHaveLength(2);
+ expect(container.querySelectorAll('.graphiql-history-item')).toHaveLength(
+ 2,
+ );
});
it('will save query if headers are different', async () => {
@@ -315,7 +337,9 @@ describe('GraphiQL', () => {
fireEvent.click(getByTitle('Show History'));
const executeQueryButton = getByTitle('Execute Query (Ctrl-Enter)');
fireEvent.click(executeQueryButton);
- expect(container.querySelectorAll('.history-label')).toHaveLength(1);
+ expect(container.querySelectorAll('.graphiql-history-item')).toHaveLength(
+ 1,
+ );
await wait();
fireEvent.click(getByText('Headers'));
@@ -328,7 +352,9 @@ describe('GraphiQL', () => {
);
fireEvent.click(executeQueryButton);
- expect(container.querySelectorAll('.history-label')).toHaveLength(2);
+ expect(container.querySelectorAll('.graphiql-history-item')).toHaveLength(
+ 2,
+ );
});
describe('children overrides', () => {
@@ -564,7 +590,7 @@ describe('GraphiQL', () => {
// 797 / (1200 - 797) = 1.977667493796526
expect(
- container.querySelector('.docExplorerWrap').parentElement.style.flex,
+ container.querySelector('.graphiql-plugin').parentElement.style.flex,
).toBe('1.977667493796526');
clientWidthSpy.mockRestore();
diff --git a/packages/graphiql/src/components/__tests__/QueryHistory.spec.tsx b/packages/graphiql/src/components/__tests__/QueryHistory.spec.tsx
deleted file mode 100644
index b43c5021287..00000000000
--- a/packages/graphiql/src/components/__tests__/QueryHistory.spec.tsx
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * Copyright (c) 2021 GraphQL Contributors.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
-import React, { ComponentProps } from 'react';
-import { render, fireEvent } from '@testing-library/react';
-
-import { QueryHistoryItem } from '../QueryHistory';
-import {
- mockOperationName1,
- mockQuery1,
- mockVariables1,
- mockHeaders1,
-} from './fixtures';
-import {
- EditorContextProvider,
- HistoryContextProvider,
- useHeaderEditor,
- useQueryEditor,
- useVariableEditor,
-} from '@graphiql/react';
-
-type QueryHistoryItemProps = ComponentProps;
-
-function QueryHistoryItemWithContext(props: QueryHistoryItemProps) {
- return (
-
-
-
-
-
-
- );
-}
-
-function Editors() {
- const queryRef = useQueryEditor({});
- const variableRef = useVariableEditor({});
- const headerRef = useHeaderEditor({});
- return (
- <>
-
-
-
- >
- );
-}
-
-const baseMockProps: QueryHistoryItemProps = {
- item: {
- query: mockQuery1,
- variables: mockVariables1,
- headers: mockHeaders1,
- favorite: false,
- },
-};
-
-function getMockProps(
- customProps?: Partial,
-): QueryHistoryItemProps {
- return {
- ...baseMockProps,
- ...customProps,
- item: { ...baseMockProps.item, ...customProps?.item },
- };
-}
-
-describe('QueryHistoryItem', () => {
- it('renders operationName if label is not provided', () => {
- const otherMockProps = { item: { operationName: mockOperationName1 } };
- const props = getMockProps(otherMockProps);
- const { container } = render( );
- expect(container.querySelector('button.history-label')!.textContent).toBe(
- mockOperationName1,
- );
- });
-
- it('renders a string version of the query if label or operation name are not provided', () => {
- const { container } = render(
- ,
- );
- expect(container.querySelector('button.history-label')!.textContent).toBe(
- mockQuery1
- .split('\n')
- .filter(line => line.indexOf('#') !== 0)
- .join(''),
- );
- });
-
- it('sets the editor values when history label button is clicked', () => {
- const otherMockProps = { item: { operationName: mockOperationName1 } };
- const mockProps = getMockProps(otherMockProps);
- const { container, getByTestId } = render(
- ,
- );
- fireEvent.click(container.querySelector('button.history-label')!);
- expect(getByTestId('query-editor').querySelector('textarea')).toHaveValue(
- mockProps.item.query,
- );
- expect(
- getByTestId('variable-editor').querySelector('textarea'),
- ).toHaveValue(mockProps.item.variables);
- expect(getByTestId('header-editor').querySelector('textarea')).toHaveValue(
- mockProps.item.headers,
- );
- });
-
- it('renders label input if the edit label button is clicked', () => {
- const { container } = render(
- ,
- );
- fireEvent.click(container.querySelector('[aria-label="Edit label"]')!);
- expect(container.querySelectorAll('li.editable').length).toBe(1);
- expect(container.querySelectorAll('input').length).toBe(1);
- expect(container.querySelectorAll('button.history-label').length).toBe(0);
- });
-});
diff --git a/packages/graphiql/src/css/app.css b/packages/graphiql/src/css/app.css
index fc351be8ab2..06fb746a320 100644
--- a/packages/graphiql/src/css/app.css
+++ b/packages/graphiql/src/css/app.css
@@ -72,15 +72,6 @@
width: 9px;
}
-.graphiql-container .docExplorerWrap,
-.graphiql-container .historyPaneWrap {
- background: white;
- box-shadow: 0 0 8px rgba(0, 0, 0, 0.15);
- position: relative;
- width: 100%;
- z-index: 3;
-}
-
.graphiql-container .historyPaneWrap {
min-width: 230px;
z-index: 5;
@@ -157,9 +148,7 @@
.graphiql-container .toolbar-menu-items > li:hover,
.graphiql-container .toolbar-select-options > li.hover,
.graphiql-container .toolbar-select-options > li:active,
-.graphiql-container .toolbar-select-options > li:hover,
-.graphiql-container .history-contents > li:hover,
-.graphiql-container .history-contents > li:active {
+.graphiql-container .toolbar-select-options > li:hover {
background: #e10098;
color: #fff;
}
diff --git a/packages/graphiql/src/css/doc-explorer.css b/packages/graphiql/src/css/doc-explorer.css
index e24096aa490..167b5ca5237 100644
--- a/packages/graphiql/src/css/doc-explorer.css
+++ b/packages/graphiql/src/css/doc-explorer.css
@@ -2,8 +2,7 @@
background: white;
}
-.graphiql-container .doc-explorer-title-bar,
-.graphiql-container .history-title-bar {
+.graphiql-container .doc-explorer-title-bar {
cursor: default;
display: flex;
height: 34px;
@@ -13,8 +12,7 @@
user-select: none;
}
-.graphiql-container .doc-explorer-title,
-.graphiql-container .history-title {
+.graphiql-container .doc-explorer-title {
flex: 1;
font-weight: bold;
overflow-x: hidden;
@@ -54,17 +52,11 @@
position: relative;
}
-.graphiql-container .doc-explorer-contents,
-.graphiql-container .history-contents {
+.graphiql-container .doc-explorer-contents {
background-color: #ffffff;
border-top: 1px solid #d6d6d6;
- bottom: 0;
- left: 0;
overflow-y: auto;
padding: 20px 15px;
- position: absolute;
- right: 0;
- top: 47px;
}
.graphiql-container .doc-type-description p:first-child,
diff --git a/packages/graphiql/src/css/history.css b/packages/graphiql/src/css/history.css
deleted file mode 100644
index 0946fd2b082..00000000000
--- a/packages/graphiql/src/css/history.css
+++ /dev/null
@@ -1,63 +0,0 @@
-.graphiql-container .history-contents {
- font-family: 'Consolas', 'Inconsolata', 'Droid Sans Mono', 'Monaco', monospace;
-}
-
-.graphiql-container .history-contents {
- margin: 0;
- padding: 0;
-}
-
-.graphiql-container .history-contents li {
- align-items: center;
- display: flex;
- font-size: 12px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- margin: 0;
- padding: 8px;
- border-bottom: 1px solid #e0e0e0;
-}
-
-.graphiql-container .history-contents li button:not(.history-label) {
- display: none;
- margin-left: 10px;
-}
-
-.graphiql-container .history-contents li:hover button:not(.history-label),
-.graphiql-container
- .history-contents
- li:focus-within
- button:not(.history-label) {
- display: inline-block;
-}
-
-.graphiql-container .history-contents input,
-.graphiql-container .history-contents button {
- padding: 0;
- background: 0;
- border: 0;
- font-size: inherit;
- font-family: inherit;
- line-height: 14px;
- color: inherit;
-}
-
-.graphiql-container .history-contents input {
- flex-grow: 1;
-}
-
-.graphiql-container .history-contents input::placeholder {
- color: inherit;
-}
-
-.graphiql-container .history-contents button {
- cursor: pointer;
- text-align: left;
-}
-
-.graphiql-container .history-contents .history-label {
- flex-grow: 1;
- overflow: hidden;
- text-overflow: ellipsis;
-}
diff --git a/packages/graphiql/src/style.css b/packages/graphiql/src/style.css
index bca08e138f7..44f5509c032 100644
--- a/packages/graphiql/src/style.css
+++ b/packages/graphiql/src/style.css
@@ -137,6 +137,14 @@
border-top: 1px solid var(--color-neutral-15);
}
+/* The plugin container */
+.graphiql-container .graphiql-plugin {
+ border-left: 1px solid var(--color-neutral-15);
+ flex: 1;
+ max-width: calc(100% - 2 * var(--px-16));
+ padding: var(--px-16);
+}
+
/* Generic loading spinner */
.graphiql-container .graphiql-spinner {
height: 56px;