From e706afe8a672679f53751325bf7778d0b7a78167 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:06:57 +1100 Subject: [PATCH] feat(ui): add `valueOrNull` to `useMetadataItem` In order to allow for null and undefined metadata values, this hook returned a symbol to indicate that parsing failed or was pending. For values where the parsed value will never be null or undefined, it is useful get the value or null (instead of a symbol). --- .../web/src/features/metadata/hooks/useMetadataItem.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/invokeai/frontend/web/src/features/metadata/hooks/useMetadataItem.tsx b/invokeai/frontend/web/src/features/metadata/hooks/useMetadataItem.tsx index 206d373aa7..5928a3067d 100644 --- a/invokeai/frontend/web/src/features/metadata/hooks/useMetadataItem.tsx +++ b/invokeai/frontend/web/src/features/metadata/hooks/useMetadataItem.tsx @@ -72,5 +72,12 @@ export const useMetadataItem = (metadata: unknown, handlers: MetadataHandler handlers.recall(value, true); }, [handlers, value]); - return { label, isDisabled, value, renderedValue, onRecall }; + const valueOrNull = useMemo(() => { + if (value === MetadataParsePendingToken || value === MetadataParseFailedToken) { + return null; + } + return value; + }, [value]); + + return { label, isDisabled, value, renderedValue, onRecall, valueOrNull }; };