From 5c326c807232cc6a0cebeda58774d385760b9c49 Mon Sep 17 00:00:00 2001 From: Prou Yann Date: Thu, 22 Aug 2024 08:26:52 -0400 Subject: [PATCH] New props added to Devtools component for better control - withCloseButton prop: display the close button - withDragPositionPanel prop: can drag position panel - withPIPButton prop: display the Picture In Picture button - withPositionButton prop: display the position button --- examples/react/simple/src/index.tsx | 4 +- packages/query-devtools/src/Devtools.tsx | 274 +++++++++--------- .../src/DevtoolsPanelComponent.tsx | 9 +- 3 files changed, 151 insertions(+), 136 deletions(-) diff --git a/examples/react/simple/src/index.tsx b/examples/react/simple/src/index.tsx index 6a137cb9e2..f7c7e65f3a 100644 --- a/examples/react/simple/src/index.tsx +++ b/examples/react/simple/src/index.tsx @@ -5,14 +5,14 @@ import { QueryClientProvider, useQuery, } from '@tanstack/react-query' -import { ReactQueryDevtools } from '@tanstack/react-query-devtools' +import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools' const queryClient = new QueryClient() export default function App() { return ( - + ) diff --git a/packages/query-devtools/src/Devtools.tsx b/packages/query-devtools/src/Devtools.tsx index d8ad455b23..d88f911419 100644 --- a/packages/query-devtools/src/Devtools.tsx +++ b/packages/query-devtools/src/Devtools.tsx @@ -2,14 +2,13 @@ import { For, Show, batch, - createContext, createEffect, createMemo, createSignal, + mergeProps, on, onCleanup, onMount, - useContext, } from 'solid-js' import { rankItem } from '@tanstack/match-sorter-utils' import * as goober from 'goober' @@ -18,7 +17,7 @@ import { TransitionGroup } from 'solid-transition-group' import { Key } from '@solid-primitives/keyed' import { createResizeObserver } from '@solid-primitives/resize-observer' import { DropdownMenu, RadioGroup } from '@kobalte/core' -import { Portal, clearDelegatedEvents, delegateEvents } from 'solid-js/web' +import { Portal } from 'solid-js/web' import { tokens } from './theme' import { convertRemToPixels, @@ -77,6 +76,10 @@ import type { Accessor, Component, JSX, Setter } from 'solid-js' interface DevtoolsPanelProps { localStore: StorageObject setLocalStore: StorageSetter + withCloseButton?: boolean + withDragPositionPanel?: boolean + withPIPButton?: boolean + withPositionButton?: boolean } interface QueryStatusProps { @@ -108,7 +111,13 @@ const [selectedMutationId, setSelectedMutationId] = createSignal( const [panelWidth, setPanelWidth] = createSignal(0) const [offline, setOffline] = createSignal(false) -export const Devtools: Component = (props) => { +export const Devtools: Component = (_props) => { + const props = mergeProps({ + withCloseButton: true, + withDragPositionPanel: true, + withPIPButton: true, + withPositionButton: true + }, _props) const theme = useTheme() const css = useQueryDevtoolsContext().shadowDOMTarget ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget }) @@ -181,10 +190,7 @@ export const Devtools: Component = (props) => { - + @@ -232,10 +238,7 @@ export const Devtools: Component = (props) => { > - + @@ -509,29 +512,30 @@ const DevtoolsPanel: Component = (props) => { ref={panelRef} aria-label="Tanstack query devtools" > -
- - + {props.withDragPositionPanel && ( +
+ )} + {props.withCloseButton && ( + + )} + ) } @@ -539,7 +543,7 @@ const DevtoolsPanel: Component = (props) => { const ContentView: Component = (props) => { setupQueryCacheSubscription() setupMutationCacheSubscription() - + console.log('ContentView ', props); let containerRef!: HTMLDivElement const theme = useTheme() const css = useQueryDevtoolsContext().shadowDOMTarget @@ -906,25 +910,27 @@ const ContentView: Component = (props) => { > {offline() ? : } - - - + {props.withPIPButton && ( + + + + )} = (props) => { > Settings - - - Position - - - setComputedVariables(el as HTMLDivElement)} - mount={ - pip().pipWindow - ? pip().pipWindow!.document.body - : document.body - } - > - + - { - setDevtoolsPosition('top') - }} - as="button" - class={cx( - styles().settingsSubButton, - 'tsqd-settings-menu-position-btn', - 'tsqd-settings-menu-position-btn-top', - )} - > - Top - - - { - setDevtoolsPosition('bottom') - }} - as="button" - class={cx( - styles().settingsSubButton, - 'tsqd-settings-menu-position-btn', - 'tsqd-settings-menu-position-btn-bottom', - )} - > - Bottom - - - { - setDevtoolsPosition('left') - }} - as="button" - class={cx( - styles().settingsSubButton, - 'tsqd-settings-menu-position-btn', - 'tsqd-settings-menu-position-btn-left', - )} - > - Left - - - { - setDevtoolsPosition('right') - }} - as="button" + Position + + + setComputedVariables(el as HTMLDivElement)} + mount={ + pip().pipWindow + ? pip().pipWindow!.document.body + : document.body + } + > + - Right - - - - - + { + setDevtoolsPosition('top') + }} + as="button" + class={cx( + styles().settingsSubButton, + 'tsqd-settings-menu-position-btn', + 'tsqd-settings-menu-position-btn-top', + )} + > + Top + + + { + setDevtoolsPosition('bottom') + }} + as="button" + class={cx( + styles().settingsSubButton, + 'tsqd-settings-menu-position-btn', + 'tsqd-settings-menu-position-btn-bottom', + )} + > + Bottom + + + { + setDevtoolsPosition('left') + }} + as="button" + class={cx( + styles().settingsSubButton, + 'tsqd-settings-menu-position-btn', + 'tsqd-settings-menu-position-btn-left', + )} + > + Left + + + { + setDevtoolsPosition('right') + }} + as="button" + class={cx( + styles().settingsSubButton, + 'tsqd-settings-menu-position-btn', + 'tsqd-settings-menu-position-btn-right', + )} + > + Right + + + + + + )} { - +