Skip to content

Commit

Permalink
feat: add AliasedImageDoubleTags
Browse files Browse the repository at this point in the history
  • Loading branch information
agatha197 committed Nov 4, 2024
1 parent 70a122e commit c2cf13b
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 4 deletions.
77 changes: 77 additions & 0 deletions react/src/components/AliasedImageDoubleTags.tsx
Original file line number Diff line number Diff line change
@@ -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<AliasedImageDoubleTagsProps> = ({
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 (
<Flex direction="row" align="start" gap={'xxs'}>
{_.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 (
<DoubleTag
key={tag.key}
values={[
{
label: (
<TextHighlighter keyword={highlightKeyword} key={tag.key}>
{tagAlias(tag.key)}
</TextHighlighter>
),
color: isCustomized ? 'cyan' : doubleTagProps.color,
},
{
label: (
<TextHighlighter keyword={highlightKeyword} key={tagValue}>
{tagValue}
</TextHighlighter>
),
color: isCustomized ? 'cyan' : doubleTagProps.color,
},
]}
{...doubleTagProps}
/>
);
})}
</Flex>
);
};

export default AliasedImageDoubleTags;
50 changes: 46 additions & 4 deletions react/src/components/ImageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,54 @@ const ImageList: React.FC<{ style?: React.CSSProperties }> = ({ style }) => {
title: t('environment.Tags'),
key: 'tags',
dataIndex: 'tags',
render: (text: Array<{ key: string; value: string }>) => {
render: (
text: Array<{ key: string; value: string }>,
row: EnvironmentImage,
) => {
return (
// <AliasedImageDoubleTags
// imageFrgmt={row}
// label={undefined}
// highlightKeyword={imageSearch}
// />
<Flex direction="row" align="start">
{_.map(text, (tag) => (
<DoubleTag values={[tag.key, tag.value]} />
))}
{_.map(text, (tag: { key: string; value: string }) => {
const isCustomized = _.includes(tag.key, 'customized_');
const tagValue = isCustomized
? _.find(row?.labels, {
key: 'ai.backend.customized-image.name',
})?.value
: tag.value;
return (
<DoubleTag
key={tag.key}
values={[
{
label: (
<TextHighlighter
keyword={imageSearch}
key={tag.key}
>
{tagAlias(tag.key)}
</TextHighlighter>
),
color: isCustomized ? 'cyan' : 'blue',
},
{
label: (
<TextHighlighter
keyword={imageSearch}
key={tagValue}
>
{tagValue}
</TextHighlighter>
),
color: isCustomized ? 'cyan' : 'blue',
},
]}
/>
);
})}
</Flex>
);
},
Expand Down

0 comments on commit c2cf13b

Please sign in to comment.