import { isArray, isNonNullable } from 'lib/utils' import { useRef, useState } from 'react' type Primitive = string | number | bigint | boolean | symbol | null | undefined export type GenericObj = { type?: string [key: string]: GenericObj | Primitive | Array } /** * Display an array of objects or primitives for debug purposes. Nullable values * are displayed so that relative indexes are preserved. */ export function DebugDisplayArray({ arr, filterKeys, }: { arr: Array filterKeys: string[] }) { return ( <> {arr.map((obj, index) => { return (
{obj && typeof obj === 'object' ? ( ) : isNonNullable(obj) ? ( {obj.toString()} ) : ( {obj} )}
) })} ) } /** * Display an object as a tree for debug purposes. Nullable values are omitted. * The only other property treated specially is the type property, which is * assumed to be a string. */ export function DebugDisplayObj({ obj, filterKeys, }: { obj: GenericObj filterKeys: string[] }) { const ref = useRef(null) const hasCursor = false const [isCollapsed, setIsCollapsed] = useState(false) return (
      {isCollapsed ? (
        
      ) : (
        
          
          
    {Object.entries(obj).map(([key, value]) => { if (filterKeys.includes(key)) { return null } else if (isArray(value)) { return (
  • {`${key}: [`} {']'}
  • ) } else if (typeof value === 'object' && value !== null) { return (
  • {key}:
  • ) } else if (isNonNullable(value)) { return (
  • {key}: {value.toString()}
  • ) } return null })}
)}
) }