-
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.
- Loading branch information
1 parent
f8040a1
commit e6e76d6
Showing
3 changed files
with
110 additions
and
91 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,78 +1,85 @@ | ||
import { 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>(1) | ||
const currentInstanceId = | ||
instanceNumber != null && instances != null | ||
? instances[instanceNumber - 1].id | ||
: null; | ||
|
||
const currentInstanceId = (instanceNumber != null && instances != null) ? instances[instanceNumber - 1].id : null | ||
const { data: header } = useCustomQuery( | ||
["instances", currentInstanceId, "metadata"], | ||
() => instanceHeader(currentInstanceId), | ||
{ | ||
enabled: currentInstanceId !== null, | ||
} | ||
); | ||
|
||
const { data: header } = useCustomQuery( | ||
['instances', currentInstanceId, 'metadata'], | ||
() => instanceHeader(currentInstanceId), | ||
{ | ||
enabled: (currentInstanceId !== null) | ||
} | ||
) | ||
const { data: tags } = useCustomQuery( | ||
["instances", currentInstanceId, "tags"], | ||
() => instanceTags(currentInstanceId), | ||
{ | ||
enabled: currentInstanceId !== null, | ||
} | ||
); | ||
|
||
const { data: tags } = useCustomQuery( | ||
['instances', currentInstanceId, 'tags'], | ||
() => instanceTags(currentInstanceId), | ||
{ | ||
enabled: (currentInstanceId !== null) | ||
} | ||
) | ||
const metadata = useMemo(() => { | ||
if (!header || !tags) return {}; | ||
return { | ||
...header, | ||
...tags, | ||
}; | ||
}, [header, tags]); | ||
|
||
const json = JSON.parse(JSON.stringify(header, null, 2)) | ||
const json_values = Object.values(json) | ||
var names_list = [] | ||
var values_list = [] | ||
for (var index = 0; index < json_values.length; index++) { | ||
names_list.push(json_values[index]["Name"]) | ||
values_list.push(json_values[index]["Value"]) | ||
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 jsonNameValues = Object.fromEntries(names_list.map((key, index) => [key, values_list[index]])); | ||
}; | ||
|
||
const json2 = JSON.parse(JSON.stringify(tags, null, 2)) | ||
const json_values2 = Object.values(json2) | ||
var names_list2 = [] | ||
var values_list2 = [] | ||
for (var index = 0; index < json_values2.length; index++) { | ||
names_list2.push(json_values2[index]["Name"]) | ||
values_list2.push(json_values2[index]["Value"]) | ||
} | ||
const jsonNameValues2 = Object.fromEntries(names_list2.map((key, index) => [key, values_list2[index]])); | ||
if (!instances) return <Spinner />; | ||
|
||
if (!instances) return <Spinner /> | ||
return ( | ||
<> | ||
<Input label="Instance Number" min={1} max={instances.length} value={instanceNumber ?? 1} onChange={(event) => setInstanceNumber(Number(event.target?.value))} /> | ||
<pre> | ||
{Object.entries(jsonNameValues).map(([key, value]) => ( | ||
<div key={key}> | ||
<strong>{key}:</strong> {JSON.stringify(value)} | ||
<hr/> | ||
</div> | ||
))} | ||
<hr/><hr/><hr/><hr/><hr/> | ||
{Object.entries(jsonNameValues2).map(([key, value]) => ( | ||
<div key={key}> | ||
<strong>{key}:</strong> {JSON.stringify(value)} | ||
<hr/> | ||
</div> | ||
))} | ||
{/* {JSON.stringify(header, null, 2)} */} | ||
{/* {JSON.stringify(tags, null, 2)} */} | ||
</pre> | ||
</> | ||
) | ||
} | ||
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> | ||
</> | ||
); | ||
}; | ||
|
||
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