Fix stringifying

This commit is contained in:
Nathan Bierema 2023-01-02 09:15:23 -05:00
parent 438d08dd7c
commit 02cb2bbaba
3 changed files with 9 additions and 6 deletions

View File

@ -176,12 +176,14 @@ const defaultOptions: Options = {
export interface Node { export interface Node {
name: string; name: string;
children?: this[] | null; children?: this[] | null;
object?: unknown;
value?: unknown; value?: unknown;
} }
export interface InternalNode { export interface InternalNode {
name: string; name: string;
children?: this[] | null; children?: this[] | null;
object?: unknown;
value?: unknown; value?: unknown;
id: string | number; id: string | number;
} }

View File

@ -83,11 +83,11 @@ export function getNodeGroupByDepthCount(rootNode: InternalNode) {
} }
export function getTooltipString( export function getTooltipString(
node: unknown, node: HierarchyPointNodeWithPrivateChildren<InternalNode>,
i: number | undefined, i: number | undefined,
{ indentationSize = 4 } { indentationSize = 4 }
) { ) {
if (!is(Object, node)) return ''; if (!is(Object, node.data)) return '';
const spacer = join('&nbsp;&nbsp;'); const spacer = join('&nbsp;&nbsp;');
const cr2br = replace(/\n/g, '<br/>'); const cr2br = replace(/\n/g, '<br/>');
@ -96,9 +96,9 @@ export function getTooltipString(
const children = node.children || node._children; const children = node.children || node._children;
if (typeof node.value !== 'undefined') return json2html(node.value); if (typeof node.data.value !== 'undefined') return json2html(node.data.value);
if (typeof node.object !== 'undefined') return json2html(node.object); if (typeof node.data.object !== 'undefined')
if (children && children.length) return json2html(node.data.object);
return `childrenCount: ${(children as unknown[]).length}`; if (children && children.length) return `childrenCount: ${children.length}`;
return 'empty'; return 'empty';
} }

View File

@ -5,6 +5,7 @@ import mapValues from 'lodash/mapValues';
export interface Node { export interface Node {
name: string; name: string;
children?: Node[] | null; children?: Node[] | null;
object?: unknown;
value?: unknown; value?: unknown;
} }