Resource names are unique per owning principal, so different users can legally create same-name GPU instances, templates, SSH public keys, storage volumes and storage types — but the admin's cross-tenant lists and the instance-create template picker rendered them indistinguishably. - Group the template picker by owning scope: Your Templates, Global Templates, then — admin cross-tenant view only — one group per owner. A single group renders flat without headers. A plugin can take over grouping via hooks.useTemplateOwnerGroups when its principal model scopes templates beyond USER owners; a plugin without the hook keeps the flat list. - Add an admin-only Creator column to the Instances, SSH Public Keys, Storage and Storage Types tables, sitting right before Created (mirroring the API Keys page convention). Resolves creator_id to a username via the user directory, falling back to owner_principal_id for legacy rows — a personal-scope row's creator IS its owner. - Tag template cards with their owner scope (Global / username) for admins. The Creator column and the card tag defer to a plugin that registers the page's list columns / the OwnerScopeTag slot. Requires the gpustack server change that records creator_id on templates, SSH public keys and storage types.
128 lines
3.7 KiB
TypeScript
128 lines
3.7 KiB
TypeScript
import useCreatorColumn from '@/pages/gpu-service/hooks/use-creator-column';
|
|
import { usePluginListColumns } from '@/plugins/list-extra-columns';
|
|
import { AutoTooltip, DropdownButtons } from '@gpustack/core-ui';
|
|
import { useIntl } from '@umijs/max';
|
|
import type { ColumnsType } from 'antd/lib/table';
|
|
import dayjs from 'dayjs';
|
|
import { useMemo } from 'react';
|
|
import { rowActionList } from '../config';
|
|
import { ListItem } from '../config/types';
|
|
|
|
interface ColumnsHookProps {
|
|
handleSelect: (val: string, record: ListItem) => void;
|
|
storageClassList: Global.BaseOption<string>[];
|
|
sortOrder: string[];
|
|
}
|
|
|
|
const useStorageColumns = ({
|
|
handleSelect,
|
|
storageClassList,
|
|
sortOrder
|
|
}: ColumnsHookProps): ColumnsType<ListItem> => {
|
|
const intl = useIntl();
|
|
const pluginCols = usePluginListColumns('gpuStorage');
|
|
const creatorCols = useCreatorColumn<ListItem>('gpuStorage');
|
|
return useMemo(() => {
|
|
const pluginRendered = pluginCols.map((c) => ({
|
|
title: intl.formatMessage({ id: c.titleId }),
|
|
key: c.key,
|
|
ellipsis: { showTitle: false },
|
|
render: (_text: any, record: ListItem) => c.render(record)
|
|
}));
|
|
return [
|
|
{
|
|
title: intl.formatMessage({ id: 'common.table.name' }),
|
|
dataIndex: 'name',
|
|
key: 'name',
|
|
sorter: true,
|
|
ellipsis: {
|
|
showTitle: false
|
|
},
|
|
render: (text: string, record: ListItem) => (
|
|
<AutoTooltip
|
|
ghost
|
|
style={{ maxWidth: 360 }}
|
|
title={<span>{record.displayName || text}</span>}
|
|
>
|
|
<span className="text-primary">{record.displayName || text}</span>
|
|
</AutoTooltip>
|
|
)
|
|
},
|
|
...pluginRendered,
|
|
{
|
|
title: intl.formatMessage({ id: 'common.table.type' }),
|
|
dataIndex: ['spec', 'type'],
|
|
key: 'type',
|
|
sorter: false,
|
|
render: (value: string) => {
|
|
return (
|
|
<AutoTooltip ghost>
|
|
{storageClassList.find((item) => item.value === value)?.label ||
|
|
'-'}
|
|
</AutoTooltip>
|
|
);
|
|
}
|
|
},
|
|
{
|
|
title: intl.formatMessage({ id: 'gpuservice.storage.capacity' }),
|
|
dataIndex: ['spec', 'capacity'],
|
|
key: 'capacity',
|
|
sorter: false,
|
|
render: (value: string) => (value ? value.replace(/Gi$/, 'GB') : '-')
|
|
},
|
|
...creatorCols,
|
|
// {
|
|
// title: intl.formatMessage({ id: 'common.table.status' }),
|
|
// dataIndex: ['status', 'phase'],
|
|
// key: 'status',
|
|
// sorter: false,
|
|
// render: (value: string) =>
|
|
// value ? (
|
|
// <StatusTag
|
|
// statusValue={{
|
|
// status: status[value],
|
|
// text: StoragePhaseLabelMap[value] || value
|
|
// }}
|
|
// ></StatusTag>
|
|
// ) : (
|
|
// '-'
|
|
// )
|
|
// },
|
|
{
|
|
title: intl.formatMessage({ id: 'common.table.createTime' }),
|
|
dataIndex: 'created_at',
|
|
key: 'created_at',
|
|
sorter: false,
|
|
ellipsis: {
|
|
showTitle: false
|
|
},
|
|
render: (text: string) => (
|
|
<AutoTooltip ghost>
|
|
{text ? dayjs(text).format('YYYY-MM-DD HH:mm:ss') : '-'}
|
|
</AutoTooltip>
|
|
)
|
|
},
|
|
{
|
|
title: intl.formatMessage({ id: 'common.table.operation' }),
|
|
key: 'operation',
|
|
dataIndex: 'operation',
|
|
render: (_text, record) => (
|
|
<DropdownButtons
|
|
items={rowActionList}
|
|
onSelect={(val) => handleSelect(val, record)}
|
|
/>
|
|
)
|
|
}
|
|
];
|
|
}, [
|
|
handleSelect,
|
|
sortOrder,
|
|
storageClassList,
|
|
intl,
|
|
pluginCols,
|
|
creatorCols
|
|
]);
|
|
};
|
|
|
|
export default useStorageColumns;
|