From f915ea8ceec737d8b8fa3d86d9dafbd7c6dfa80c Mon Sep 17 00:00:00 2001 From: Julien VIGNAU-ESPINE <91631890+Julien-VIGNAU-ESPINE@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:03:03 +0000 Subject: [PATCH] :feat: adding expend list --- src/content/series/Tags.tsx | 68 ++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/src/content/series/Tags.tsx b/src/content/series/Tags.tsx index b6e9001..114c2c3 100644 --- a/src/content/series/Tags.tsx +++ b/src/content/series/Tags.tsx @@ -3,23 +3,27 @@ import { getInstancesOfSeries } from "../../services/orthanc"; import { Input, Spinner } from "../../ui"; import { useCustomQuery } from "../../utils"; import { instanceHeader, instanceTags } from "../../services/instances"; +import { Metadata, Tag } from "../../utils/types"; +import { Meta } from "@storybook/react"; type TagsProps = { seriesId: string; }; + const Tags = ({ seriesId }: TagsProps) => { const { data: instances } = useCustomQuery( ["series", seriesId, "instances"], () => getInstancesOfSeries(seriesId) ); const [instanceNumber, setInstanceNumber] = useState(1); + const [expanded, setExpanded] = useState<{ [key: string]: boolean }>({}); const currentInstanceId = instanceNumber != null && instances != null ? instances[instanceNumber - 1].id : null; - const { data: header } = useCustomQuery( + const { data: header } = useCustomQuery( ["instances", currentInstanceId, "metadata"], () => instanceHeader(currentInstanceId), { @@ -27,7 +31,7 @@ const Tags = ({ seriesId }: TagsProps) => { } ); - const { data: tags } = useCustomQuery( + const { data: tags } = useCustomQuery( ["instances", currentInstanceId, "tags"], () => instanceTags(currentInstanceId), { @@ -43,21 +47,43 @@ const Tags = ({ seriesId }: TagsProps) => { }; }, [header, tags]); - const getComponent = ( - tagName: string, - tag: string | Record[] - ) => { - if (Array.isArray(tag)) { - return tag.map((tagItem) => { - return Object.entries(tagItem).map(([key, tag]) => { - return getComponent(key, tag); - }); - }); + const toggleExpand = (key: string) => { + setExpanded((prev) => ({ + ...prev, + [key]: !prev[key], + })); + }; + + const getComponent = (tagAddress: string, tag: Tag) => { + if (Array.isArray(tag.Value)) { + return ( +
  • + + {expanded[tagAddress] && ( +
      + {tag.Value.map((metadata, index) => ( +
    • +
        + {Object.entries(metadata).map(([addressTag, tag]) => + getComponent(addressTag, tag) + )} +
      +
    • + ))} +
    + )} +
  • + ); } else { return ( - - {tagName}: {tag} - +
  • + {tag.Name} - {tag.Value} +
  • ); } }; @@ -73,11 +99,13 @@ const Tags = ({ seriesId }: TagsProps) => { value={instanceNumber ?? 1} onChange={(event) => setInstanceNumber(Number(event.target?.value))} /> -
      - {Object.entries(metadata).map(([key, tag]) => ( -
    • {getComponent(key, tag)}
    • - ))} -
    +
    +
      + {Object.entries(metadata).map(([tagAddress, tag]) => + getComponent(tagAddress, tag) + )} +
    +
    ); };