Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace name with namespace #2787

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions react/src/components/ImageEnvironmentSelectFormItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const ImageEnvironmentSelectFormItems: React.FC<
const form = Form.useFormInstance<ImageEnvironmentFormInput>();
const environments = Form.useWatch('environments', { form, preserve: true });
const baiClient = useSuspendedBackendaiClient();
const supportExtendedImageInfo = baiClient?.supports('extended-image-info');

const [environmentSearch, setEnvironmentSearch] = useState('');
const [versionSearch, setVersionSearch] = useState('');
Expand All @@ -111,7 +112,7 @@ const ImageEnvironmentSelectFormItems: React.FC<
query ImageEnvironmentSelectFormItemsQuery($installed: Boolean) {
images(is_installed: $installed) {
id
name
name @deprecatedSince(version: "24.09.1")
humanized_name
tag
registry
Expand All @@ -127,6 +128,7 @@ const ImageEnvironmentSelectFormItems: React.FC<
key
value
}
namespace @since(version: "24.09.1")
}
}
`,
Expand Down Expand Up @@ -266,7 +268,9 @@ const ImageEnvironmentSelectFormItems: React.FC<
// metadata?.imageInfo[
// getImageMeta(getImageFullName(image) || "").key
// ]?.name || image?.name
image?.registry + '/' + image?.name
`${image?.registry}/${
supportExtendedImageInfo ? image?.namespace : image?.name
}`
);
})
.map((images, environmentName) => {
Expand Down Expand Up @@ -365,7 +369,10 @@ const ImageEnvironmentSelectFormItems: React.FC<
if (fullNameMatchedImage) {
form.setFieldsValue({
environments: {
environment: fullNameMatchedImage?.name || '',
environment:
(supportExtendedImageInfo
? fullNameMatchedImage?.namespace
: fullNameMatchedImage?.name) || '',
version: getImageFullName(fullNameMatchedImage),
image: fullNameMatchedImage,
},
Expand All @@ -379,7 +386,10 @@ const ImageEnvironmentSelectFormItems: React.FC<
.images[0];
form.setFieldsValue({
environments: {
environment: firstInListImage?.name || '',
environment:
(supportExtendedImageInfo
? firstInListImage?.namespace
: firstInListImage?.name) || '',
version: getImageFullName(firstInListImage),
image: firstInListImage,
},
Expand All @@ -393,7 +403,11 @@ const ImageEnvironmentSelectFormItems: React.FC<
>
{fullNameMatchedImage ? (
<Select.Option
value={fullNameMatchedImage?.name}
value={
supportExtendedImageInfo
? fullNameMatchedImage?.namespace
: fullNameMatchedImage?.name
}
filterValue={getImageFullName(fullNameMatchedImage)}
>
<Flex
Expand Down
3 changes: 2 additions & 1 deletion react/src/components/ResourceAllocationFormItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ describe('getAllocatablePresetNames', () => {

const image_has_cuda_shares_min1_max1: Image = {
id: 'id1',
name: 'image1',
namespace: 'image1',
name: undefined,
digest: 'digest1',
architecture: 'arm64',
humanized_name: 'Image 1',
Expand Down
2 changes: 1 addition & 1 deletion react/src/helper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export const getImageFullName = (
image: Image | CommittedImage | EnvironmentImage,
) => {
return image
? `${image.registry}/${image.name}:${image.tag}@${image.architecture}`
? `${image.registry}/${image.namespace ?? image.name}:${image.tag}@${image.architecture}`
agatha197 marked this conversation as resolved.
Show resolved Hide resolved
: undefined;
};

Expand Down
3 changes: 2 additions & 1 deletion react/src/hooks/useBackendAIImageMetaData.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ describe('useBackendAIImageMetaData', () => {

const { key, tags } = getImageMeta(
getImageFullName({
name: 'abc/def/training',
namespace: 'abc/def/training',
name: undefined,
humanized_name: 'abc/def/training',
tag: '01-py3-abc-v1',
registry: '192.168.0.1:7080',
Expand Down
103 changes: 55 additions & 48 deletions react/src/pages/MyEnvironmentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import {
LangTags,
} from '../components/ImageTags';
import TableColumnsSettingModal from '../components/TableColumnsSettingModal';
import { getImageFullName } from '../helper';
import { useBackendAIImageMetaData, useUpdatableState } from '../hooks';
import { getImageFullName, localeCompare } from '../helper';
import {
useBackendAIImageMetaData,
useSuspendedBackendaiClient,
useUpdatableState,
} from '../hooks';
import { MyEnvironmentPageForgetAndUntagMutation } from './__generated__/MyEnvironmentPageForgetAndUntagMutation.graphql';
import {
MyEnvironmentPageQuery,
Expand Down Expand Up @@ -40,6 +44,8 @@ const MyEnvironmentPage: React.FC<PropsWithChildren> = ({ children }) => {
const { t } = useTranslation();
const { token } = theme.useToken();
const { message } = App.useApp();
const baiClient = useSuspendedBackendaiClient();
const supportExtendedImageInfo = baiClient?.supports('extended-image-info');

const [isOpenColumnsSetting, setIsOpenColumnsSetting] = useState(false);
const [selectedTab] = useState<TabKey>('images');
Expand All @@ -63,7 +69,7 @@ const MyEnvironmentPage: React.FC<PropsWithChildren> = ({ children }) => {
query MyEnvironmentPageQuery {
customized_images {
id
name
name @deprecatedSince(version: "24.09.1")
humanized_name
tag
registry
Expand All @@ -74,6 +80,7 @@ const MyEnvironmentPage: React.FC<PropsWithChildren> = ({ children }) => {
value
}
supported_accelerators
namespace @since(version: "24.09.1")
}
}
`,
Expand Down Expand Up @@ -106,68 +113,72 @@ const MyEnvironmentPage: React.FC<PropsWithChildren> = ({ children }) => {
title: t('environment.Registry'),
dataIndex: 'registry',
key: 'registry',
sorter: (a, b) =>
a?.registry && b?.registry ? a.registry.localeCompare(b.registry) : 0,
sorter: (a, b) => localeCompare(a?.registry, b?.registry),
},
{
title: t('environment.Architecture'),
dataIndex: 'architecture',
key: 'architecture',
sorter: (a, b) =>
a?.architecture && b?.architecture
? a.architecture.localeCompare(b.architecture)
: 0,
},
{
title: t('environment.Namespace'),
key: 'namespace',
sorter: (a, b) => {
const namespaceA = getNamespace(getImageFullName(a) || '');
const namespaceB = getNamespace(getImageFullName(b) || '');
return namespaceA && namespaceB
? namespaceA.localeCompare(namespaceB)
: 0;
},
render: (text, row) => (
<span>{getNamespace(getImageFullName(row) || '')}</span>
),
sorter: (a, b) => localeCompare(a?.architecture, b?.architecture),
},
...(supportExtendedImageInfo
? [
{
title: t('environment.Namespace'),
key: 'namespace',
dataIndex: 'namespace',
sorter: (a: CommittedImage, b: CommittedImage) =>
localeCompare(a?.namespace, b?.namespace),
},
]
: [
{
title: t('environment.Namespace'),
key: 'name',
dataIndex: 'name',
sorter: (a: CommittedImage, b: CommittedImage) =>
localeCompare(
getNamespace(getImageFullName(a) || ''),
getNamespace(getImageFullName(b) || ''),
),
render: (text: string, row: CommittedImage) => (
<span>{getNamespace(getImageFullName(row) || '')}</span>
),
},
]),
{
title: t('environment.Language'),
key: 'lang',
sorter: (a, b) => {
const langA = getImageLang(getImageFullName(a) || '');
const langB = getImageLang(getImageFullName(b) || '');
return langA && langB ? langA.localeCompare(langB) : 0;
},
sorter: (a, b) =>
localeCompare(
getImageLang(getImageFullName(a) || ''),
getImageLang(getImageFullName(b) || ''),
),

render: (text, row) => (
<LangTags image={getImageFullName(row) || ''} color="green" />
),
},
{
title: t('environment.Version'),
key: 'baseversion',
sorter: (a, b) => {
const baseversionA = getBaseVersion(getImageFullName(a) || '');
const baseversionB = getBaseVersion(getImageFullName(b) || '');
return baseversionA && baseversionB
? baseversionA.localeCompare(baseversionB)
: 0;
},
sorter: (a, b) =>
localeCompare(
getBaseVersion(getImageFullName(a) || ''),
getBaseVersion(getImageFullName(b) || ''),
),
render: (text, row) => (
<BaseVersionTags image={getImageFullName(row) || ''} color="green" />
),
},
{
title: t('environment.Base'),
key: 'baseimage',
sorter: (a, b) => {
const baseimageA = getBaseImage(getImageFullName(a) || '');
const baseimageB = getBaseImage(getImageFullName(b) || '');
return baseimageA && baseimageB
? baseimageA.localeCompare(baseimageB)
: 0;
},
sorter: (a, b) =>
localeCompare(
getBaseImage(getImageFullName(a) || ''),
getBaseImage(getImageFullName(b) || ''),
),
render: (text, row) => (
<BaseImageTags image={getImageFullName(row) || ''} />
),
Expand All @@ -190,10 +201,7 @@ const MyEnvironmentPage: React.FC<PropsWithChildren> = ({ children }) => {
b?.labels as { key: string; value: string }[],
)[0] || ''
: '';
if (requirementA === '' && requirementB === '') return 0;
if (requirementA === '') return -1;
if (requirementB === '') return 1;
return requirementA.localeCompare(requirementB);
return localeCompare(requirementA, requirementB);
},
render: (text, row) =>
row?.tag ? (
Expand All @@ -207,8 +215,7 @@ const MyEnvironmentPage: React.FC<PropsWithChildren> = ({ children }) => {
title: t('environment.Digest'),
dataIndex: 'digest',
key: 'digest',
sorter: (a, b) =>
a?.digest && b?.digest ? a.digest.localeCompare(b.digest) : 0,
sorter: (a, b) => localeCompare(a?.digest || '', b?.digest || ''),
},
{
title: t('general.Control'),
Expand Down
3 changes: 3 additions & 0 deletions src/lib/backend.ai-client-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ class Client {
if (this.isManagerVersionCompatibleWith('24.09.1')) {
this._features['extended-image-info'] = true;
}
if (this.isManagerVersionCompatibleWith('24.09.1')) {
this._features['extended-image-info'] = true;
}
}

/**
Expand Down
Loading