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

Function Explorer

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

Source from the content-addressed store, hash-verified

434 * @returns The tree view.
435 */
436export default function Explorer(props: ExplorerProps) {
437 const theme = useTheme()
438 const themed = createThemed(theme)
439 const queryClient = useQueryDevtoolsContext().client
440
441 const [expanded, setExpanded] = createSignal(
442 (props.defaultExpanded || []).includes(props.label),
443 )
444 const hasSearchMatchingChild = () =>
445 !!props.search &&
446 [...props.search.match.children.values()].some((child) => child.hasMatch)
447 const isExpanded = () => expanded() || hasSearchMatchingChild()
448 const toggleExpanded = () => {
449 if (!hasSearchMatchingChild()) setExpanded((old) => !old)
450 }
451 const [expandedPages, setExpandedPages] = createSignal<Array<number>>([])
452 const nativeObjectType = createMemo(() => getNativeObjectType(props.value))
453 const childrenEditable = createMemo(
454 () =>
455 props.editable &&
456 (Array.isArray(props.value) ||
457 nativeObjectType() === 'Map' ||
458 nativeObjectType() === 'Set' ||
459 isPlainObject(props.value)),
460 )
461
462 const subEntries = createMemo(() => {
463 if (props.search) {
464 return props.search.match.kind === 'branch'
465 ? (searchEntries(props.value) ?? [])
466 : []
467 }
468 if (Array.isArray(props.value)) {
469 return props.value.map((d, i) => ({
470 label: i.toString(),
471 key: i.toString(),
472 value: d,
473 }))
474 } else if (nativeObjectType() === 'Map') {
475 return Array.from(
476 Map.prototype.entries.call(props.value),
477 ([key, val]) => ({
478 label: primitiveText(key) ?? '[Object key]',
479 key,
480 value: val,
481 }),
482 )
483 } else if (nativeObjectType() === 'Set') {
484 return Array.from(Set.prototype.values.call(props.value), (val, i) => ({
485 label: i.toString(),
486 key: i.toString(),
487 value: val,
488 }))
489 } else if (
490 props.value !== null &&
491 typeof props.value === 'object' &&
492 isIterable(props.value) &&
493 typeof props.value[Symbol.iterator] === 'function'

Callers

nothing calls this directly

Calls 15

useThemeFunction · 0.90
createThemedFunction · 0.90
useQueryDevtoolsContextFunction · 0.90
getNativeObjectTypeFunction · 0.90
isPlainObjectFunction · 0.90
searchEntriesFunction · 0.90
primitiveTextFunction · 0.90
updateNestedDataByPathFunction · 0.90
isIterableFunction · 0.85
chunkArrayFunction · 0.85
pageHasMatchFunction · 0.85
toggleExpandedFunction · 0.85

Tested by

no test coverage detected