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

Function Explorer

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

Source from the content-addressed store, hash-verified

466 * @returns The tree view.
467 */
468export default function Explorer(props: ExplorerProps) {
469 const theme = useTheme()
470 const css = useQueryDevtoolsContext().shadowDOMTarget
471 ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget })
472 : goober.css
473 const styles = createMemo(() => {
474 return theme() === 'dark' ? darkStyles(css) : lightStyles(css)
475 })
476 const queryClient = useQueryDevtoolsContext().client
477
478 const [expanded, setExpanded] = createSignal(
479 (props.defaultExpanded || []).includes(props.label),
480 )
481 const hasSearchMatchingChild = () =>
482 !!props.search &&
483 [...props.search.match.children.values()].some((child) => child.hasMatch)
484 const isExpanded = () => expanded() || hasSearchMatchingChild()
485 const toggleExpanded = () => {
486 if (!hasSearchMatchingChild()) setExpanded((old) => !old)
487 }
488 const [expandedPages, setExpandedPages] = createSignal<Array<number>>([])
489 const nativeObjectType = createMemo(() => getNativeObjectType(props.value))
490 const childrenEditable = createMemo(
491 () =>
492 props.editable &&
493 (Array.isArray(props.value) ||
494 nativeObjectType() === 'Map' ||
495 nativeObjectType() === 'Set' ||
496 isPlainObject(props.value)),
497 )
498
499 const subEntries = createMemo(() => {
500 if (props.search) {
501 return props.search.match.kind === 'branch'
502 ? (searchEntries(props.value) ?? [])
503 : []
504 }
505 if (Array.isArray(props.value)) {
506 return props.value.map((d, i) => ({
507 label: i.toString(),
508 key: i.toString(),
509 value: d,
510 }))
511 } else if (nativeObjectType() === 'Map') {
512 return Array.from(
513 Map.prototype.entries.call(props.value),
514 ([key, val]) => ({
515 label: primitiveText(key) ?? '[Object key]',
516 key,
517 value: val,
518 }),
519 )
520 } else if (nativeObjectType() === 'Set') {
521 return Array.from(Set.prototype.values.call(props.value), (val, i) => ({
522 label: i.toString(),
523 key: i.toString(),
524 value: val,
525 }))

Callers

nothing calls this directly

Calls 15

useThemeFunction · 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
isExpandedFunction · 0.85

Tested by

no test coverage detected