-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/metadata-tags' into dev
- Loading branch information
Showing
3 changed files
with
98 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,85 @@ | ||
import { useMemo, useState } from "react" | ||
import { getInstancesOfSeries } from "../../services/orthanc" | ||
import { Input, Spinner } from "../../ui" | ||
import { useCustomQuery } from "../../utils" | ||
import { instanceHeader, instanceTags } from "../../services/instances" | ||
import { useMemo, useState } from "react"; | ||
import { getInstancesOfSeries } from "../../services/orthanc"; | ||
import { Input, Spinner } from "../../ui"; | ||
import { useCustomQuery } from "../../utils"; | ||
import { instanceHeader, instanceTags } from "../../services/instances"; | ||
|
||
type TagsProps = { | ||
seriesId: string | ||
} | ||
seriesId: string; | ||
}; | ||
const Tags = ({ seriesId }: TagsProps) => { | ||
const { data: instances } = useCustomQuery( | ||
["series", seriesId, "instances"], | ||
() => getInstancesOfSeries(seriesId) | ||
); | ||
const [instanceNumber, setInstanceNumber] = useState<number>(1); | ||
|
||
const { data: instances } = useCustomQuery(['series', seriesId, 'instances'], () => getInstancesOfSeries(seriesId)) | ||
const [instanceNumber, setInstanceNumber] = useState<number>(0) | ||
const currentInstanceId = | ||
instanceNumber != null && instances != null | ||
? instances[instanceNumber - 1].id | ||
: null; | ||
|
||
const currentInstanceId = useMemo(()=>{ | ||
if(!instances ) return null | ||
return instances[instanceNumber].id | ||
const { data: header } = useCustomQuery( | ||
["instances", currentInstanceId, "metadata"], | ||
() => instanceHeader(currentInstanceId), | ||
{ | ||
enabled: currentInstanceId !== null, | ||
} | ||
); | ||
|
||
const { data: tags } = useCustomQuery( | ||
["instances", currentInstanceId, "tags"], | ||
() => instanceTags(currentInstanceId), | ||
{ | ||
enabled: currentInstanceId !== null, | ||
} | ||
); | ||
|
||
}, [instances, instanceNumber]) | ||
const metadata = useMemo(() => { | ||
if (!header || !tags) return {}; | ||
return { | ||
...header, | ||
...tags, | ||
}; | ||
}, [header, tags]); | ||
|
||
const getComponent = ( | ||
tagName: string, | ||
tag: string | Record<string, string>[] | ||
) => { | ||
if (Array.isArray(tag)) { | ||
return tag.map((tagItem) => { | ||
return Object.entries(tagItem).map(([key, tag]) => { | ||
return getComponent(key, tag); | ||
}); | ||
}); | ||
} else { | ||
return ( | ||
<span> | ||
<strong>{tagName}:</strong> {tag} | ||
</span> | ||
); | ||
} | ||
}; | ||
|
||
const { data: header } = useCustomQuery( | ||
['instances', currentInstanceId, 'metadata'], | ||
() => instanceHeader(currentInstanceId), | ||
{ | ||
enabled: (currentInstanceId != null) | ||
} | ||
) | ||
if (!instances) return <Spinner />; | ||
|
||
const { data: tags } = useCustomQuery( | ||
['instances', currentInstanceId, 'tags'], | ||
() => instanceTags(currentInstanceId), | ||
{ | ||
enabled: (currentInstanceId !== null) | ||
} | ||
) | ||
return ( | ||
<> | ||
<Input | ||
label="Instance Number" | ||
min={1} | ||
max={instances.length} | ||
value={instanceNumber ?? 1} | ||
onChange={(event) => setInstanceNumber(Number(event.target?.value))} | ||
/> | ||
<ul> | ||
{Object.entries(metadata).map(([key, tag]) => ( | ||
<li key={key}>{getComponent(key, tag)}</li> | ||
))} | ||
</ul> | ||
</> | ||
); | ||
}; | ||
|
||
if (!instances) return <Spinner /> | ||
|
||
return ( | ||
<> | ||
<Input label="Instance Number" min={1} max={instances.length} value={instanceNumber} onChange={(event) => setInstanceNumber(Number(event.target?.value) - 1)} /> | ||
<pre> | ||
{JSON.stringify(header, null, 2)} | ||
{JSON.stringify(tags, null, 2)} | ||
</pre> | ||
</> | ||
) | ||
} | ||
|
||
export default Tags | ||
export default Tags; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters