From 00b08c50a6c8227ae62dfe84c01b92b96cbedfcf Mon Sep 17 00:00:00 2001 From: agatha197 Date: Thu, 31 Oct 2024 12:48:03 +0900 Subject: [PATCH] feat: add `AliasedImageDoubleTags` --- .../src/components/AliasedImageDoubleTags.tsx | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 react/src/components/AliasedImageDoubleTags.tsx diff --git a/react/src/components/AliasedImageDoubleTags.tsx b/react/src/components/AliasedImageDoubleTags.tsx new file mode 100644 index 0000000000..09eb4066dd --- /dev/null +++ b/react/src/components/AliasedImageDoubleTags.tsx @@ -0,0 +1,77 @@ +import { useBackendAIImageMetaData } from '../hooks'; +import DoubleTag, { DoubleTagObjectValue } from './DoubleTag'; +import Flex from './Flex'; +import TextHighlighter from './TextHighlighter'; +import { AliasedImageDoubleTagsFragment$key } from './__generated__/AliasedImageDoubleTagsFragment.graphql'; +import graphql from 'babel-plugin-relay/macro'; +import _ from 'lodash'; +import React from 'react'; +import { useFragment } from 'react-relay'; + +interface AliasedImageDoubleTagsProps extends DoubleTagObjectValue { + imageFrgmt?: AliasedImageDoubleTagsFragment$key | null; + highlightKeyword?: string; +} + +const AliasedImageDoubleTags: React.FC = ({ + imageFrgmt, + highlightKeyword, + ...doubleTagProps +}) => { + const images = useFragment( + graphql` + fragment AliasedImageDoubleTagsFragment on ImageNode { + labels { + key + value + } + tags @since(version: "24.09.1") { + key + value + } + } + `, + imageFrgmt, + ); + const [, { tagAlias }] = useBackendAIImageMetaData(); + + return ( + + {_.map(images?.tags, (tag: { key: string; value: string }) => { + const isCustomized = _.includes(tag.key, 'customized_'); + // If the tag is customized, we need to find the corresponding label instead of using the tag value (hash). + const tagValue = isCustomized + ? _.find(images?.labels, { + key: 'ai.backend.customized-image.name', + })?.value + : tag.value; + return ( + + {tagAlias(tag.key)} + + ), + color: isCustomized ? 'cyan' : doubleTagProps.color, + }, + { + label: ( + + {tagValue} + + ), + color: isCustomized ? 'cyan' : doubleTagProps.color, + }, + ]} + {...doubleTagProps} + /> + ); + })} + + ); +}; + +export default AliasedImageDoubleTags;