2018-12-21 22:18:05 +03:00
|
|
|
import React from 'react';
|
2024-04-08 00:04:45 +03:00
|
|
|
import JSONNestedNode from './JSONNestedNode.js';
|
|
|
|
import type { CommonInternalProps } from './types.js';
|
2018-12-21 22:18:05 +03:00
|
|
|
|
|
|
|
// Returns the "n Items" string for this node,
|
|
|
|
// generating and caching it if it hasn't been created yet.
|
2023-01-05 07:17:44 +03:00
|
|
|
function createItemString(data: unknown) {
|
2018-12-21 22:18:05 +03:00
|
|
|
const len = Object.getOwnPropertyNames(data).length;
|
|
|
|
return `${len} ${len !== 1 ? 'keys' : 'key'}`;
|
|
|
|
}
|
|
|
|
|
2023-01-05 07:17:44 +03:00
|
|
|
interface Props extends CommonInternalProps {
|
|
|
|
data: unknown;
|
2020-08-22 03:13:24 +03:00
|
|
|
nodeType: string;
|
|
|
|
}
|
|
|
|
|
2018-12-21 22:18:05 +03:00
|
|
|
// Configures <JSONNestedNode> to render an Object
|
2023-01-05 07:17:44 +03:00
|
|
|
export default function JSONObjectNode({ data, ...props }: Props) {
|
|
|
|
return (
|
|
|
|
<JSONNestedNode
|
|
|
|
{...props}
|
|
|
|
data={data}
|
|
|
|
nodeType="Object"
|
|
|
|
nodeTypeIndicator={props.nodeType === 'Error' ? 'Error()' : '{}'}
|
|
|
|
createItemString={createItemString}
|
|
|
|
expandable={Object.getOwnPropertyNames(data).length > 0}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|