Extract the JSON visualizer component in twenty-ui (#10937)

- Move the JsonTree component and the other components to twenty-ui
- Rely on a React Context to provide translations

## Future work

It would be good to migrate the `createRequiredContext` function to
`twenty-ui`. I didn't want to migrate it in this PR but would have liked
to use it.
This commit is contained in:
Baptiste Devessier
2025-03-17 16:00:06 +01:00
committed by GitHub
parent 428499e222
commit 093d6c0a1a
22 changed files with 189 additions and 89 deletions

View File

@ -0,0 +1,34 @@
import { IconBrackets } from '@ui/display';
import { JsonNestedNode } from '@ui/json-visualizer/components/JsonNestedNode';
import { useJsonTreeContextOrThrow } from '@ui/json-visualizer/hooks/useJsonTreeContextOrThrow';
import { JsonArray } from 'type-fest';
export const JsonArrayNode = ({
label,
value,
depth,
keyPath,
}: {
label?: string;
value: JsonArray;
depth: number;
keyPath: string;
}) => {
const { emptyArrayLabel } = useJsonTreeContextOrThrow();
return (
<JsonNestedNode
elements={[...value.entries()].map(([key, value]) => ({
id: key,
label: String(key),
value,
}))}
renderElementsCount={(count) => `[${count}]`}
label={label}
Icon={IconBrackets}
depth={depth}
emptyElementsText={emptyArrayLabel}
keyPath={keyPath}
/>
);
};