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

[graphiql] remove unnecessary <div /> wrappers #3235

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-penguins-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphiql': patch
---

remove unnecessary `<div />` wrappers
25 changes: 11 additions & 14 deletions packages/graphiql-react/src/utility/resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,16 @@ export function useDragResize({
const store = useMemo(
() =>
debounce(500, (value: string) => {
if (storage && storageKey) {
storage.set(storageKey, value);
if (storageKey) {
storage?.set(storageKey, value);
}
}),
[storage, storageKey],
);

const [hiddenElement, setHiddenElement] = useState<ResizableElement | null>(
() => {
const storedValue =
storage && storageKey ? storage.get(storageKey) : null;
const storedValue = storageKey && storage?.get(storageKey);
if (storedValue === HIDE_FIRST || initiallyHidden === 'first') {
return 'first';
}
Expand Down Expand Up @@ -105,14 +104,10 @@ export function useDragResize({
*/
useLayoutEffect(() => {
const storedValue =
storage && storageKey
? storage.get(storageKey) || defaultFlexRef.current
: defaultFlexRef.current;
const flexDirection = direction === 'horizontal' ? 'row' : 'column';
(storageKey && storage?.get(storageKey)) || defaultFlexRef.current;

if (firstRef.current) {
firstRef.current.style.display = 'flex';
firstRef.current.style.flexDirection = flexDirection;
firstRef.current.style.flex =
storedValue === HIDE_FIRST || storedValue === HIDE_SECOND
? defaultFlexRef.current
Expand All @@ -121,13 +116,11 @@ export function useDragResize({

if (secondRef.current) {
secondRef.current.style.display = 'flex';
secondRef.current.style.flexDirection = flexDirection;
secondRef.current.style.flex = '1';
}

if (dragBarRef.current) {
dragBarRef.current.style.display = 'flex';
dragBarRef.current.style.flexDirection = flexDirection;
}
}, [direction, storage, storageKey]);

Expand Down Expand Up @@ -172,9 +165,13 @@ export function useDragResize({
element.style.position = '';
element.style.left = '';

if (firstRef.current && storage && storageKey) {
const storedValue = storage?.get(storageKey);
if (storedValue !== HIDE_FIRST && storedValue !== HIDE_SECOND) {
if (storage && storageKey) {
const storedValue = storage.get(storageKey);
if (
firstRef.current &&
storedValue !== HIDE_FIRST &&
storedValue !== HIDE_SECOND
) {
firstRef.current.style.flex = storedValue || defaultFlexRef.current;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql/cypress/e2e/headers.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('Headers', () => {
it('should have default headers while open new tabs', () => {
cy.visit(`/?query={test}&defaultHeaders=${DEFAULT_HEADERS}`);
cy.assertHasValues({ query: '{test}', headersString: DEFAULT_HEADERS });
cy.get('.graphiql-add-tab-wrapper').click();
cy.get('.graphiql-tab-add').click();
cy.assertHasValues({ query: '', headersString: DEFAULT_HEADERS });
cy.get('.graphiql-tab-add').click();
cy.assertHasValues({ query: '', headersString: DEFAULT_HEADERS });
Expand All @@ -17,7 +17,7 @@ describe('Headers', () => {
`/?query={test}&defaultHeaders=${DEFAULT_HEADERS}&headers=${HEADERS}`,
);
cy.assertHasValues({ query: '{test}', headersString: HEADERS });
cy.get('.graphiql-add-tab-wrapper').click();
cy.get('.graphiql-tab-add').click();
cy.assertHasValues({ query: '', headersString: DEFAULT_HEADERS });
cy.get('.graphiql-tab-add').click();
cy.assertHasValues({ query: '', headersString: DEFAULT_HEADERS });
Expand Down
Loading