mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add getIsVisible
to metadata handlers
This commit is contained in:
parent
bfad814862
commit
ccd399e277
@ -3,6 +3,7 @@ import { MetadataItemView } from 'features/metadata/components/MetadataItemView'
|
|||||||
import { useMetadataItem } from 'features/metadata/hooks/useMetadataItem';
|
import { useMetadataItem } from 'features/metadata/hooks/useMetadataItem';
|
||||||
import type { MetadataHandlers } from 'features/metadata/types';
|
import type { MetadataHandlers } from 'features/metadata/types';
|
||||||
import { MetadataParseFailedToken } from 'features/metadata/util/parsers';
|
import { MetadataParseFailedToken } from 'features/metadata/util/parsers';
|
||||||
|
import { isSymbol } from 'lodash-es';
|
||||||
|
|
||||||
type MetadataItemProps<T> = {
|
type MetadataItemProps<T> = {
|
||||||
metadata: unknown;
|
metadata: unknown;
|
||||||
@ -17,6 +18,10 @@ const _MetadataItem = typedMemo(<T,>({ metadata, handlers, direction = 'row' }:
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handlers.getIsVisible && !isSymbol(value) && !handlers.getIsVisible(value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MetadataItemView
|
<MetadataItemView
|
||||||
label={label}
|
label={label}
|
||||||
|
@ -50,6 +50,14 @@ export type MetadataParseFunc<T = unknown> = (metadata: unknown) => Promise<T>;
|
|||||||
*/
|
*/
|
||||||
export type MetadataValidateFunc<T> = (value: T) => Promise<T>;
|
export type MetadataValidateFunc<T> = (value: T) => Promise<T>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<T> = (value: T) => boolean;
|
||||||
|
|
||||||
export type MetadataHandlers<TValue = unknown, TItem = unknown> = {
|
export type MetadataHandlers<TValue = unknown, TItem = unknown> = {
|
||||||
/**
|
/**
|
||||||
* Gets the label of the current metadata item as a string.
|
* Gets the label of the current metadata item as a string.
|
||||||
@ -111,6 +119,14 @@ export type MetadataHandlers<TValue = unknown, TItem = unknown> = {
|
|||||||
* @returns The rendered item.
|
* @returns The rendered item.
|
||||||
*/
|
*/
|
||||||
renderItemValue?: MetadataRenderValueFunc<TItem>;
|
renderItemValue?: MetadataRenderValueFunc<TItem>;
|
||||||
|
/**
|
||||||
|
* 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<TValue>;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO(psyche): The types for item handlers should be able to be inferred from the type of the value:
|
// 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<TValue, TItem> = {
|
|||||||
getLabel: MetadataGetLabelFunc;
|
getLabel: MetadataGetLabelFunc;
|
||||||
renderValue?: MetadataRenderValueFunc<TValue>;
|
renderValue?: MetadataRenderValueFunc<TValue>;
|
||||||
renderItemValue?: MetadataRenderValueFunc<TItem>;
|
renderItemValue?: MetadataRenderValueFunc<TItem>;
|
||||||
|
getIsVisible?: MetadataGetIsVisibleFunc<TValue>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BuildMetadataHandlers = <TValue, TItem>(
|
export type BuildMetadataHandlers = <TValue, TItem>(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user