feat: per-page extra-columns slot for list tables
Add `usePluginListColumns(pageKey)` so a registered plugin can splice extra columns into a list page's columns hook keyed by page id. The slot is wired into 11 list pages (Models, Model Routes, Clusters, Cloud Credentials, MaaS Providers, Model Files, Model Instances, GPU Service Instances / Public Keys / Storage / Storage Types) so any consumer of the seam reaches every org-scoped list without per-page plumbing. The slot accepts either a static array or a hook function — the hook form lets the registrant use React hooks to decide visibility without the host having to evaluate it. Columns carry a `placement`: `after-name` is the default (sits next to the row's identifying column); `before-time` / `before-operation` are kept for back-compat with the existing per-page `modelRoutes.extraColumns` slot. SealTable-grid pages (Models / Model Routes / Clusters) absorb the plugin column's span by shrinking the widest right-side columns so the 24-unit grid stays balanced. Model Routes' `CREATE_TIME_MIN_SPAN` drops from 3 to 2 because with two plugin columns active the grid was 1 unit over and the action dropdown wrapped onto a new row; the date string ellipsizes cleanly at the lower min. ListItem types for Model Instances, MaaS Providers, Cloud Credentials, and Model Files gain an optional `owner_principal_id` field — the backend already emits it (denormalized from the parent resource), the TS types just hadn't declared it. The GPU Instances page splices the plugin column right before the Cluster column (rather than after Name); the two read together since Cluster narrows down to one Org.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// columns.ts
|
||||
import { tableSorter } from '@/config/settings';
|
||||
import { ListItem as workerListItem } from '@/pages/resources/config/types';
|
||||
import { usePluginListColumns } from '@/plugins/list-extra-columns';
|
||||
import { convertFileSize } from '@/utils';
|
||||
import { ThunderboltFilled } from '@ant-design/icons';
|
||||
import { AutoTooltip, IconFont } from '@gpustack/core-ui';
|
||||
@@ -67,6 +68,7 @@ const useInstancesColumns = (options: {
|
||||
const intl = useIntl();
|
||||
const { workerList, clusterList, modelList, handleSelect, onCellClick } =
|
||||
options;
|
||||
const pluginCols = usePluginListColumns('modelInstances');
|
||||
|
||||
const renderWorkerCell = (text: number, record: ListItem) => {
|
||||
if (text) {
|
||||
@@ -84,6 +86,12 @@ const useInstancesColumns = (options: {
|
||||
};
|
||||
|
||||
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' }),
|
||||
@@ -118,6 +126,7 @@ const useInstancesColumns = (options: {
|
||||
</>
|
||||
)
|
||||
},
|
||||
...pluginRendered,
|
||||
{
|
||||
title: intl.formatMessage({ id: 'clusters.title' }),
|
||||
dataIndex: 'cluster_id',
|
||||
@@ -202,7 +211,15 @@ const useInstancesColumns = (options: {
|
||||
)
|
||||
}
|
||||
];
|
||||
}, [handleSelect, onCellClick, workerList, clusterList, modelList]);
|
||||
}, [
|
||||
handleSelect,
|
||||
onCellClick,
|
||||
workerList,
|
||||
clusterList,
|
||||
modelList,
|
||||
intl,
|
||||
pluginCols
|
||||
]);
|
||||
};
|
||||
|
||||
export default useInstancesColumns;
|
||||
|
||||
Reference in New Issue
Block a user