From ccd399e277e6caf4a24d26af2a6f2c9294c0e8ce Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 7 May 2024 17:44:50 +1000 Subject: [PATCH] feat(ui): add `getIsVisible` to metadata handlers --- .../metadata/components/MetadataItem.tsx | 5 +++++ .../frontend/web/src/features/metadata/types.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/invokeai/frontend/web/src/features/metadata/components/MetadataItem.tsx b/invokeai/frontend/web/src/features/metadata/components/MetadataItem.tsx index 66d101f458..7489b05158 100644 --- a/invokeai/frontend/web/src/features/metadata/components/MetadataItem.tsx +++ b/invokeai/frontend/web/src/features/metadata/components/MetadataItem.tsx @@ -3,6 +3,7 @@ import { MetadataItemView } from 'features/metadata/components/MetadataItemView' import { useMetadataItem } from 'features/metadata/hooks/useMetadataItem'; import type { MetadataHandlers } from 'features/metadata/types'; import { MetadataParseFailedToken } from 'features/metadata/util/parsers'; +import { isSymbol } from 'lodash-es'; type MetadataItemProps = { metadata: unknown; @@ -17,6 +18,10 @@ const _MetadataItem = typedMemo(({ metadata, handlers, direction = 'row' }: return null; } + if (handlers.getIsVisible && !isSymbol(value) && !handlers.getIsVisible(value)) { + return null; + } + return ( = (metadata: unknown) => Promise; */ export type MetadataValidateFunc = (value: T) => Promise; +/** + * A function that determines whether a metadata item should be visible. + * + * @param value The value to check. + * @returns True if the item should be visible, false otherwise. + */ +export type MetadataGetIsVisibleFunc = (value: T) => boolean; + export type MetadataHandlers = { /** * Gets the label of the current metadata item as a string. @@ -111,6 +119,14 @@ export type MetadataHandlers = { * @returns The rendered item. */ renderItemValue?: MetadataRenderValueFunc; + /** + * Checks if a parsed metadata value should be visible. + * If not provided, the item is always visible. + * + * @param value The value to check. + * @returns True if the item should be visible, false otherwise. + */ + getIsVisible?: MetadataGetIsVisibleFunc; }; // TODO(psyche): The types for item handlers should be able to be inferred from the type of the value: @@ -127,6 +143,7 @@ type BuildMetadataHandlersArg = { getLabel: MetadataGetLabelFunc; renderValue?: MetadataRenderValueFunc; renderItemValue?: MetadataRenderValueFunc; + getIsVisible?: MetadataGetIsVisibleFunc; }; export type BuildMetadataHandlers = (