MCPcopy Create free account
hub / github.com/TanStack/query / Explorer

Function Explorer

packages/query-devtools/src/Explorer.tsx:269–537  ·  view source on GitHub ↗
(props: ExplorerProps)

Source from the content-addressed store, hash-verified

267}
268
269export default function Explorer(props: ExplorerProps) {
270 const theme = useTheme()
271 const css = useQueryDevtoolsContext().shadowDOMTarget
272 ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget })
273 : goober.css
274 const styles = createMemo(() => {
275 return theme() === 'dark' ? darkStyles(css) : lightStyles(css)
276 })
277 const queryClient = useQueryDevtoolsContext().client
278
279 const [expanded, setExpanded] = createSignal(
280 (props.defaultExpanded || []).includes(props.label),
281 )
282 const toggleExpanded = () => setExpanded((old) => !old)
283 const [expandedPages, setExpandedPages] = createSignal<Array<number>>([])
284
285 const subEntries = createMemo(() => {
286 if (Array.isArray(props.value)) {
287 return props.value.map((d, i) => ({
288 label: i.toString(),
289 value: d,
290 }))
291 } else if (
292 props.value !== null &&
293 typeof props.value === 'object' &&
294 isIterable(props.value) &&
295 typeof props.value[Symbol.iterator] === 'function'
296 ) {
297 if (props.value instanceof Map) {
298 return Array.from(props.value, ([key, val]) => ({
299 label: key,
300 value: val,
301 }))
302 }
303 return Array.from(props.value, (val, i) => ({
304 label: i.toString(),
305 value: val,
306 }))
307 } else if (typeof props.value === 'object' && props.value !== null) {
308 return Object.entries(props.value).map(([key, val]) => ({
309 label: key,
310 value: val,
311 }))
312 }
313 return []
314 })
315
316 const type = createMemo<string>(() => {
317 if (Array.isArray(props.value)) {
318 return 'array'
319 } else if (
320 props.value !== null &&
321 typeof props.value === 'object' &&
322 isIterable(props.value) &&
323 typeof props.value[Symbol.iterator] === 'function'
324 ) {
325 return 'Iterable'
326 } else if (typeof props.value === 'object' && props.value !== null) {

Callers

nothing calls this directly

Calls 10

useThemeFunction · 0.90
useQueryDevtoolsContextFunction · 0.90
displayValueFunction · 0.90
updateNestedDataByPathFunction · 0.90
isIterableFunction · 0.85
chunkArrayFunction · 0.85
toggleExpandedFunction · 0.85
darkStylesFunction · 0.70
lightStylesFunction · 0.70
setQueryDataMethod · 0.45

Tested by

no test coverage detected