fix: remove instance from cache after deleting
This commit is contained in:
@@ -35,3 +35,5 @@ export const workerListAtom = atom<
|
|||||||
>([]);
|
>([]);
|
||||||
|
|
||||||
export const backendOptionsAtom = atom<BackendOption[]>([]);
|
export const backendOptionsAtom = atom<BackendOption[]>([]);
|
||||||
|
|
||||||
|
export const resourceOverviewAtom = atom<Record<string, any>>({});
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const CellWrapper = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const TableCell: React.FC<SealColumnProps> = (props) => {
|
const TableCell: React.FC<SealColumnProps> = (props) => {
|
||||||
const { dataIndex, render, align, editable } = props;
|
const { dataIndex, render, align, editable, dataField } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CellWrapper
|
<CellWrapper
|
||||||
@@ -40,7 +40,7 @@ const TableCell: React.FC<SealColumnProps> = (props) => {
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<CellContent
|
<CellContent
|
||||||
dataIndex={dataIndex}
|
dataIndex={dataField || dataIndex}
|
||||||
render={render}
|
render={render}
|
||||||
editable={editable}
|
editable={editable}
|
||||||
></CellContent>
|
></CellContent>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export interface SealColumnProps {
|
|||||||
render?: (text: any, record: any) => React.ReactNode;
|
render?: (text: any, record: any) => React.ReactNode;
|
||||||
dataIndex: string;
|
dataIndex: string;
|
||||||
key?: string;
|
key?: string;
|
||||||
|
dataField?: string; // Added dataField property, aviods conflict with dataIndex, because dataIndex maybe used in sorting
|
||||||
width?: number;
|
width?: number;
|
||||||
span: number;
|
span: number;
|
||||||
align?: 'left' | 'center' | 'right';
|
align?: 'left' | 'center' | 'right';
|
||||||
@@ -90,7 +91,7 @@ export interface SealTableProps {
|
|||||||
watchChildren?: boolean;
|
watchChildren?: boolean;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
loadend?: boolean;
|
loadend?: boolean;
|
||||||
onCell?: (record: any, dataIndex: string) => void;
|
onCell?: (record: any, extra: any) => void;
|
||||||
onTableSort?: (order: TableOrder | Array<TableOrder>) => void;
|
onTableSort?: (order: TableOrder | Array<TableOrder>) => void;
|
||||||
onExpand?: (expanded: boolean, record: any, rowKey: any) => void;
|
onExpand?: (expanded: boolean, record: any, rowKey: any) => void;
|
||||||
onExpandAll?: (expanded: boolean) => void;
|
onExpandAll?: (expanded: boolean) => void;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import routeCachekey from '@/config/route-cachekey';
|
|||||||
import { DEFAULT_ENTER_PAGE } from '@/config/settings';
|
import { DEFAULT_ENTER_PAGE } from '@/config/settings';
|
||||||
import useOverlayScroller from '@/hooks/use-overlay-scroller';
|
import useOverlayScroller from '@/hooks/use-overlay-scroller';
|
||||||
import useUserSettings from '@/hooks/use-user-settings';
|
import useUserSettings from '@/hooks/use-user-settings';
|
||||||
|
import useAddResource from '@/pages/dashboard/hooks/use-add-resource';
|
||||||
import { logout } from '@/pages/login/apis';
|
import { logout } from '@/pages/login/apis';
|
||||||
import { useAccessMarkedRoutes } from '@@/plugin-access';
|
import { useAccessMarkedRoutes } from '@@/plugin-access';
|
||||||
import { useModel } from '@@/plugin-model';
|
import { useModel } from '@@/plugin-model';
|
||||||
@@ -48,6 +49,13 @@ const NO_CONTAINER_PAGES = [
|
|||||||
'clusterCreate'
|
'clusterCreate'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const CHECK_RESOURCE_PATH = [
|
||||||
|
'/resources/workers',
|
||||||
|
'/cluster-management/clusters/list',
|
||||||
|
'/cluster-management/credentials',
|
||||||
|
'/cluster-management/clusters/create'
|
||||||
|
];
|
||||||
|
|
||||||
const loginPath = DEFAULT_ENTER_PAGE.login;
|
const loginPath = DEFAULT_ENTER_PAGE.login;
|
||||||
|
|
||||||
// Filter out the routes that need to be displayed, where filterFn indicates the levels that should not be shown
|
// Filter out the routes that need to be displayed, where filterFn indicates the levels that should not be shown
|
||||||
@@ -104,6 +112,12 @@ export default (props: any) => {
|
|||||||
const { initialize: initialize } = useOverlayScroller({
|
const { initialize: initialize } = useOverlayScroller({
|
||||||
defer: false
|
defer: false
|
||||||
});
|
});
|
||||||
|
const {
|
||||||
|
setLoadingStatus,
|
||||||
|
fetchResourceData,
|
||||||
|
NoResourceModal,
|
||||||
|
loadingStatus
|
||||||
|
} = useAddResource();
|
||||||
const [modal, contextHolder] = Modal.useModal();
|
const [modal, contextHolder] = Modal.useModal();
|
||||||
const { themeData, setUserSettings, userSettings } = useUserSettings();
|
const { themeData, setUserSettings, userSettings } = useUserSettings();
|
||||||
const [userInfo] = useAtom(userAtom);
|
const [userInfo] = useAtom(userAtom);
|
||||||
@@ -241,6 +255,10 @@ export default (props: any) => {
|
|||||||
const { location } = history;
|
const { location } = history;
|
||||||
const { pathname } = location;
|
const { pathname } = location;
|
||||||
|
|
||||||
|
if (!CHECK_RESOURCE_PATH.includes(pathname)) {
|
||||||
|
// fetchResourceData();
|
||||||
|
}
|
||||||
|
|
||||||
initRouteCacheValue(pathname);
|
initRouteCacheValue(pathname);
|
||||||
dropRouteCache(pathname);
|
dropRouteCache(pathname);
|
||||||
|
|
||||||
@@ -347,6 +365,7 @@ export default (props: any) => {
|
|||||||
</PageContainerInner>
|
</PageContainerInner>
|
||||||
)}
|
)}
|
||||||
</Exception>
|
</Exception>
|
||||||
|
{NoResourceModal}
|
||||||
</ProLayout>
|
</ProLayout>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
</ConfigProvider>
|
</ConfigProvider>
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ const useClusterColumns = (
|
|||||||
title: intl.formatMessage({ id: 'clusters.table.provider' }),
|
title: intl.formatMessage({ id: 'clusters.table.provider' }),
|
||||||
dataIndex: 'provider',
|
dataIndex: 'provider',
|
||||||
sorter: tableSorter(2),
|
sorter: tableSorter(2),
|
||||||
span: 4,
|
span: 3,
|
||||||
render: (value: string) => (
|
render: (value: string) => (
|
||||||
<AutoTooltip ghost minWidth={20}>
|
<AutoTooltip ghost minWidth={20}>
|
||||||
{ProviderLabelMap[value]}
|
{ProviderLabelMap[value]}
|
||||||
@@ -55,17 +55,20 @@ const useClusterColumns = (
|
|||||||
title: 'GPUs',
|
title: 'GPUs',
|
||||||
dataIndex: 'gpus',
|
dataIndex: 'gpus',
|
||||||
span: 2,
|
span: 2,
|
||||||
|
sorter: tableSorter(3),
|
||||||
render: (value: number) => <span>{value}</span>
|
render: (value: number) => <span>{value}</span>
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({ id: 'clusters.table.deployments' }),
|
title: intl.formatMessage({ id: 'clusters.table.deployments' }),
|
||||||
dataIndex: 'models',
|
dataIndex: 'models',
|
||||||
span: 2,
|
sorter: tableSorter(4),
|
||||||
|
span: 3,
|
||||||
render: (value: number) => <span>{value}</span>
|
render: (value: number) => <span>{value}</span>
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({ id: 'resources.nodes' }),
|
title: intl.formatMessage({ id: 'resources.nodes' }),
|
||||||
dataIndex: 'workers',
|
dataIndex: 'workers',
|
||||||
|
sorter: tableSorter(5),
|
||||||
span: 3,
|
span: 3,
|
||||||
render: (value: number, record: ClusterListItem) => (
|
render: (value: number, record: ClusterListItem) => (
|
||||||
<span>
|
<span>
|
||||||
@@ -90,7 +93,7 @@ const useClusterColumns = (
|
|||||||
title: intl.formatMessage({ id: 'common.table.createTime' }),
|
title: intl.formatMessage({ id: 'common.table.createTime' }),
|
||||||
dataIndex: 'created_at',
|
dataIndex: 'created_at',
|
||||||
defaultSortOrder: 'descend',
|
defaultSortOrder: 'descend',
|
||||||
sorter: tableSorter(5),
|
sorter: tableSorter(6),
|
||||||
span: 4,
|
span: 4,
|
||||||
render: (value: string) => (
|
render: (value: string) => (
|
||||||
<AutoTooltip ghost minWidth={20}>
|
<AutoTooltip ghost minWidth={20}>
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import { clusterListAtom, workerListAtom } from '@/atoms/models';
|
import {
|
||||||
|
clusterListAtom,
|
||||||
|
resourceOverviewAtom,
|
||||||
|
workerListAtom
|
||||||
|
} from '@/atoms/models';
|
||||||
import { queryClusterList } from '@/pages/cluster-management/apis';
|
import { queryClusterList } from '@/pages/cluster-management/apis';
|
||||||
import { queryWorkersList } from '@/pages/resources/apis';
|
import { queryWorkersList } from '@/pages/resources/apis';
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { queryDashboardData } from '../../dashboard/apis';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Currently fetch the cluster list and worker list for checking resource existence.
|
* Currently fetch the cluster list and worker list for checking resource existence.
|
||||||
@@ -32,6 +37,11 @@ export default function useClusterList() {
|
|||||||
>([]);
|
>([]);
|
||||||
const [clustersAtom, setClusterListAtom] = useAtom(clusterListAtom);
|
const [clustersAtom, setClusterListAtom] = useAtom(clusterListAtom);
|
||||||
const [workersAtom, setWorkerListAtom] = useAtom(workerListAtom);
|
const [workersAtom, setWorkerListAtom] = useAtom(workerListAtom);
|
||||||
|
const [resourceAtom, setResourceOverview] = useAtom(resourceOverviewAtom);
|
||||||
|
const [resourceCount, setResourceCount] = useState<Record<string, any>>({
|
||||||
|
cluster_count: 0,
|
||||||
|
worker_count: 0
|
||||||
|
});
|
||||||
|
|
||||||
const fetchClusterList = async () => {
|
const fetchClusterList = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -67,7 +77,7 @@ export default function useClusterList() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchAll = async () => {
|
const fetchData = async () => {
|
||||||
const [clusters, workers] = await Promise.all([
|
const [clusters, workers] = await Promise.all([
|
||||||
fetchClusterList(),
|
fetchClusterList(),
|
||||||
fetchWorkerList()
|
fetchWorkerList()
|
||||||
@@ -82,12 +92,33 @@ export default function useClusterList() {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchResource = async () => {
|
||||||
|
try {
|
||||||
|
const res = await queryDashboardData();
|
||||||
|
setResourceOverview(res.resource_counts);
|
||||||
|
setResourceCount(res.resource_counts);
|
||||||
|
return {
|
||||||
|
hasClusters: res.resource_counts?.cluster_count > 0,
|
||||||
|
hasWorkers: res.resource_counts?.worker_count > 0
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
setResourceOverview({});
|
||||||
|
setResourceCount({});
|
||||||
|
return {
|
||||||
|
hasClusters: false,
|
||||||
|
hasWorkers: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
clusterList,
|
clusterList,
|
||||||
workerList,
|
workerList,
|
||||||
clustersAtom,
|
clustersAtom,
|
||||||
workersAtom,
|
workersAtom,
|
||||||
fetchAll,
|
resourceAtom,
|
||||||
|
resourceCount,
|
||||||
|
fetchResource,
|
||||||
fetchWorkerList,
|
fetchWorkerList,
|
||||||
fetchClusterList
|
fetchClusterList
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import CardWrapper from '@/components/card-wrapper';
|
|||||||
import GaugeChart from '@/components/echarts/gauge';
|
import GaugeChart from '@/components/echarts/gauge';
|
||||||
import PageTools from '@/components/page-tools';
|
import PageTools from '@/components/page-tools';
|
||||||
import BaseSelect from '@/components/seal-form/base/select';
|
import BaseSelect from '@/components/seal-form/base/select';
|
||||||
|
import { queryClusterList } from '@/pages/cluster-management/apis';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Col, Row } from 'antd';
|
import { Col, Row } from 'antd';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
@@ -15,8 +16,11 @@ const resourceChartHeight = 400;
|
|||||||
|
|
||||||
const SystemLoad = () => {
|
const SystemLoad = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const { system_load, fetchData, clusterList } = useContext(DashboardContext);
|
const { system_load, fetchData } = useContext(DashboardContext);
|
||||||
const [systemLoadData, setSystemLoadData] = useState<any>(system_load || {});
|
const [systemLoadData, setSystemLoadData] = useState<any>(system_load || {});
|
||||||
|
const [clusterList, setClusterList] = useState<Global.BaseOption<number>[]>(
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const chartData = useMemo(() => {
|
const chartData = useMemo(() => {
|
||||||
const data = systemLoadData?.current || {};
|
const data = systemLoadData?.current || {};
|
||||||
@@ -49,6 +53,22 @@ const SystemLoad = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchClusters = async () => {
|
||||||
|
try {
|
||||||
|
const res = await queryClusterList({ page: -1 });
|
||||||
|
const options = res.items.map((cluster: any) => ({
|
||||||
|
label: cluster.name,
|
||||||
|
value: cluster.id
|
||||||
|
}));
|
||||||
|
setClusterList(options);
|
||||||
|
} catch (error) {
|
||||||
|
setClusterList([]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchClusters();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="system-load">
|
<div className="system-load">
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { DashboardProps } from './types';
|
|||||||
export const DashboardContext = createContext<
|
export const DashboardContext = createContext<
|
||||||
DashboardProps & {
|
DashboardProps & {
|
||||||
fetchData: (params?: { [key: string]: any }) => Promise<void>;
|
fetchData: (params?: { [key: string]: any }) => Promise<void>;
|
||||||
clusterList: Global.BaseOption<
|
clusterList?: Global.BaseOption<
|
||||||
number,
|
number,
|
||||||
{ provider: string; state: string | number }
|
{ provider: string; state: string | number }
|
||||||
>[];
|
>[];
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ export default function useAddResource() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [, setClusterSession] = useAtom(clusterSessionAtom);
|
const [, setClusterSession] = useAtom(clusterSessionAtom);
|
||||||
|
|
||||||
const { fetchAll, clusterList, workerList, clustersAtom, workersAtom } =
|
const { fetchResource, resourceCount, resourceAtom } = useClusterList();
|
||||||
useClusterList();
|
|
||||||
|
|
||||||
const [hiddenModal, setHiddenModal] = useState(false);
|
const [hiddenModal, setHiddenModal] = useState(false);
|
||||||
const [loadingStatus, setLoadingStatus] = useState({
|
const [loadingStatus, setLoadingStatus] = useState({
|
||||||
@@ -68,12 +67,14 @@ export default function useAddResource() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const isNoResource = useMemo(() => {
|
const isNoResource = useMemo(() => {
|
||||||
const noResource = workerList.length === 0 || clusterList.length === 0;
|
const noResource =
|
||||||
|
!resourceAtom?.cluster_count || !resourceAtom?.worker_count;
|
||||||
return noResource && !loadingStatus.loading && loadingStatus.loadend;
|
return noResource && !loadingStatus.loading && loadingStatus.loadend;
|
||||||
}, [workersAtom.length, clustersAtom.length, loadingStatus]);
|
}, [resourceAtom, loadingStatus]);
|
||||||
|
|
||||||
const contentInfo = useMemo(() => {
|
const contentInfo = useMemo(() => {
|
||||||
if (clusterList.length === 0) {
|
console.log('resourceCount=', resourceCount);
|
||||||
|
if (!resourceCount.cluster_count) {
|
||||||
return {
|
return {
|
||||||
title: intl.formatMessage({ id: 'noresult.cluster.title' }),
|
title: intl.formatMessage({ id: 'noresult.cluster.title' }),
|
||||||
subTitle: intl.formatMessage({ id: 'noresult.resources.cluster' }),
|
subTitle: intl.formatMessage({ id: 'noresult.resources.cluster' }),
|
||||||
@@ -85,14 +86,14 @@ export default function useAddResource() {
|
|||||||
subTitle: intl.formatMessage({ id: 'noresult.resources.worker' }),
|
subTitle: intl.formatMessage({ id: 'noresult.resources.worker' }),
|
||||||
btnText: intl.formatMessage({ id: 'noresult.workers.button.add' })
|
btnText: intl.formatMessage({ id: 'noresult.workers.button.add' })
|
||||||
};
|
};
|
||||||
}, [clusterList.length, workerList.length, intl]);
|
}, [resourceCount, intl]);
|
||||||
|
|
||||||
const open: boolean = useMemo(() => {
|
const open: boolean = useMemo(() => {
|
||||||
return isNoResource && !hiddenModal;
|
return isNoResource && !hiddenModal;
|
||||||
}, [isNoResource, hiddenModal]);
|
}, [isNoResource, hiddenModal]);
|
||||||
|
|
||||||
const handleCreate = () => {
|
const handleCreate = () => {
|
||||||
if (clusterList.length === 0) {
|
if (!resourceCount.cluster_count) {
|
||||||
setClusterSession({
|
setClusterSession({
|
||||||
firstAddWorker: false,
|
firstAddWorker: false,
|
||||||
firstAddCluster: true
|
firstAddCluster: true
|
||||||
@@ -104,7 +105,7 @@ export default function useAddResource() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (workerList.length === 0) {
|
if (!resourceCount.worker_count) {
|
||||||
setClusterSession({
|
setClusterSession({
|
||||||
firstAddWorker: true,
|
firstAddWorker: true,
|
||||||
firstAddCluster: false
|
firstAddCluster: false
|
||||||
@@ -117,12 +118,20 @@ export default function useAddResource() {
|
|||||||
setHiddenModal(true);
|
setHiddenModal(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Modal = (
|
const fetchResourceData = async () => {
|
||||||
|
setLoadingStatus({ loading: true, loadend: false });
|
||||||
|
setHiddenModal(false);
|
||||||
|
await fetchResource();
|
||||||
|
setLoadingStatus({ loading: false, loadend: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
const NoResourceModal = (
|
||||||
<ScrollerModal
|
<ScrollerModal
|
||||||
open={open}
|
open={open}
|
||||||
footer={null}
|
footer={null}
|
||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
closeIcon={null}
|
closeIcon={null}
|
||||||
|
destroyOnHidden={false}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
>
|
>
|
||||||
<Content>
|
<Content>
|
||||||
@@ -149,11 +158,11 @@ export default function useAddResource() {
|
|||||||
open,
|
open,
|
||||||
contentInfo,
|
contentInfo,
|
||||||
loadingStatus,
|
loadingStatus,
|
||||||
clusterList,
|
NoResourceModal,
|
||||||
Modal,
|
|
||||||
handleCreate,
|
handleCreate,
|
||||||
setLoadingStatus,
|
setLoadingStatus,
|
||||||
handleCancel,
|
handleCancel,
|
||||||
fetchAll
|
fetchResource,
|
||||||
|
fetchResourceData
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,57 +6,36 @@ import { queryDashboardData } from './apis';
|
|||||||
import DashboardInner from './components/dahboard-inner';
|
import DashboardInner from './components/dahboard-inner';
|
||||||
import DashboardContext from './config/dashboard-context';
|
import DashboardContext from './config/dashboard-context';
|
||||||
import { DashboardProps } from './config/types';
|
import { DashboardProps } from './config/types';
|
||||||
import useAddResource from './hooks/use-add-resource';
|
|
||||||
|
|
||||||
const Dashboard: React.FC = () => {
|
const Dashboard: React.FC = () => {
|
||||||
const { setLoadingStatus, fetchAll, Modal, loadingStatus, clusterList } =
|
|
||||||
useAddResource();
|
|
||||||
const [data, setData] = useState<DashboardProps>({} as DashboardProps);
|
const [data, setData] = useState<DashboardProps>({} as DashboardProps);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const fetchDashboardData = useMemoizedFn(async () => {
|
const fetchDashboardData = useMemoizedFn(async () => {
|
||||||
try {
|
try {
|
||||||
|
setLoading(true);
|
||||||
const res = await queryDashboardData();
|
const res = await queryDashboardData();
|
||||||
setData(res);
|
setData(res);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setData({} as DashboardProps);
|
setData({} as DashboardProps);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const initData = useMemoizedFn(async () => {
|
|
||||||
try {
|
|
||||||
setLoadingStatus({
|
|
||||||
loading: true,
|
|
||||||
loadend: false
|
|
||||||
});
|
|
||||||
const { hasClusters, hasWorkers } = await fetchAll();
|
|
||||||
if (!hasClusters || !hasWorkers) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await fetchDashboardData();
|
|
||||||
} catch (error) {
|
|
||||||
// ignore
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingStatus({
|
setLoading(false);
|
||||||
loading: false,
|
|
||||||
loadend: true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initData();
|
fetchDashboardData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardContext.Provider
|
<DashboardContext.Provider
|
||||||
value={{ ...data, fetchData: fetchDashboardData, clusterList }}
|
value={{ ...data, fetchData: fetchDashboardData }}
|
||||||
>
|
>
|
||||||
<PageBox>
|
<PageBox>
|
||||||
<Spin spinning={loadingStatus.loading} style={{ minHeight: 300 }}>
|
<Spin spinning={loading} style={{ minHeight: 300 }}>
|
||||||
<DashboardInner />
|
<DashboardInner />
|
||||||
</Spin>
|
</Spin>
|
||||||
</PageBox>
|
</PageBox>
|
||||||
{Modal}
|
|
||||||
</DashboardContext.Provider>
|
</DashboardContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -693,8 +693,8 @@ const InstanceItem: React.FC<InstanceItemProps> = ({
|
|||||||
</Col>
|
</Col>
|
||||||
<Col span={4}>
|
<Col span={4}>
|
||||||
<span
|
<span
|
||||||
style={{ paddingLeft: '62px', gap: 4 }}
|
style={{ paddingLeft: '50px', gap: 4 }}
|
||||||
className="flex-center justify-center"
|
className="flex-center"
|
||||||
>
|
>
|
||||||
<InstanceStatusTag
|
<InstanceStatusTag
|
||||||
instanceData={instanceData}
|
instanceData={instanceData}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ interface ModelsProps {
|
|||||||
onStart?: () => void;
|
onStart?: () => void;
|
||||||
onTableSort?: (order: TableOrder | Array<TableOrder>) => void;
|
onTableSort?: (order: TableOrder | Array<TableOrder>) => void;
|
||||||
onStatusChange: (value?: any) => void;
|
onStatusChange: (value?: any) => void;
|
||||||
|
onDeleteInstanceFromCache?: (instanceId: number) => void;
|
||||||
sortOrder: string[];
|
sortOrder: string[];
|
||||||
queryParams: {
|
queryParams: {
|
||||||
page: number;
|
page: number;
|
||||||
@@ -122,6 +123,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
onStart,
|
onStart,
|
||||||
onTableSort,
|
onTableSort,
|
||||||
onStatusChange,
|
onStatusChange,
|
||||||
|
onDeleteInstanceFromCache,
|
||||||
sortOrder,
|
sortOrder,
|
||||||
deleteIds,
|
deleteIds,
|
||||||
dataSource,
|
dataSource,
|
||||||
@@ -231,7 +233,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
|
|
||||||
const handleOnCell = useMemoizedFn(async (record: any, extra: any) => {
|
const handleOnCell = useMemoizedFn(async (record: any, extra: any) => {
|
||||||
try {
|
try {
|
||||||
await updateModel(getFormattedData(record));
|
await updateModel(getFormattedData(record, { replicas: extra.newValue }));
|
||||||
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
||||||
if (extra.newValue > extra.oldValue) {
|
if (extra.newValue > extra.oldValue) {
|
||||||
updateExpandedRowKeys([record.id, ...expandedRowKeys]);
|
updateExpandedRowKeys([record.id, ...expandedRowKeys]);
|
||||||
@@ -367,41 +369,37 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
navigate(`/playground/chat?model=${row.name}`);
|
navigate(`/playground/chat?model=${row.name}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleViewLogs = useCallback(
|
const handleViewLogs = async (row: any) => {
|
||||||
async (row: any) => {
|
try {
|
||||||
try {
|
setCurrentInstance({
|
||||||
setCurrentInstance({
|
url: `${MODEL_INSTANCE_API}/${row.id}/logs`,
|
||||||
url: `${MODEL_INSTANCE_API}/${row.id}/logs`,
|
status: row.state,
|
||||||
status: row.state,
|
id: row.id,
|
||||||
id: row.id,
|
modelId: row.model_id,
|
||||||
modelId: row.model_id,
|
tail: InstanceRealtimeLogStatus.includes(row.state)
|
||||||
tail: InstanceRealtimeLogStatus.includes(row.state)
|
? undefined
|
||||||
? undefined
|
: PageSize - 1
|
||||||
: PageSize - 1
|
|
||||||
});
|
|
||||||
setOpenLogModal(true);
|
|
||||||
onViewLogs();
|
|
||||||
saveScrollHeight();
|
|
||||||
} catch (error) {
|
|
||||||
console.log('error:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[onViewLogs]
|
|
||||||
);
|
|
||||||
const handleDeleteInstace = useCallback(
|
|
||||||
(row: any) => {
|
|
||||||
modalRef.current?.show({
|
|
||||||
content: 'models.instances',
|
|
||||||
okText: 'common.button.delrecreate',
|
|
||||||
operation: 'common.delete.single.confirm',
|
|
||||||
name: row.name,
|
|
||||||
async onOk() {
|
|
||||||
await deleteModelInstance(row.id);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
setOpenLogModal(true);
|
||||||
[deleteModelInstance]
|
onViewLogs();
|
||||||
);
|
saveScrollHeight();
|
||||||
|
} catch (error) {
|
||||||
|
console.log('error:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteInstace = (row: any) => {
|
||||||
|
modalRef.current?.show({
|
||||||
|
content: 'models.instances',
|
||||||
|
okText: 'common.button.delrecreate',
|
||||||
|
operation: 'common.delete.single.confirm',
|
||||||
|
name: row.name,
|
||||||
|
async onOk() {
|
||||||
|
await deleteModelInstance(row.id);
|
||||||
|
onDeleteInstanceFromCache?.(row.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const getModelInstances = useCallback(async (row: any, options?: any) => {
|
const getModelInstances = useCallback(async (row: any, options?: any) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -107,7 +107,8 @@ const useModelsColumns = ({
|
|||||||
),
|
),
|
||||||
dataIndex: 'ready_replicas',
|
dataIndex: 'ready_replicas',
|
||||||
key: 'ready_replicas',
|
key: 'ready_replicas',
|
||||||
align: 'center',
|
dataField: 'replicas',
|
||||||
|
align: 'left',
|
||||||
sorter: tableSorter(4),
|
sorter: tableSorter(4),
|
||||||
span: 4,
|
span: 4,
|
||||||
editable: {
|
editable: {
|
||||||
|
|||||||
@@ -331,6 +331,13 @@ const Models: React.FC = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDeleteInstanceFromCache = (id: number) => {
|
||||||
|
cacheInsDataListRef.current = cacheInsDataListRef.current.filter(
|
||||||
|
(item) => item.id !== id
|
||||||
|
);
|
||||||
|
setModelInstances(cacheInsDataListRef.current);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let timer: any = null;
|
let timer: any = null;
|
||||||
// fetch data first time
|
// fetch data first time
|
||||||
@@ -436,6 +443,7 @@ const Models: React.FC = () => {
|
|||||||
onStop={handleSearchBySilent}
|
onStop={handleSearchBySilent}
|
||||||
onStart={handleSearchBySilent}
|
onStart={handleSearchBySilent}
|
||||||
onTableSort={handleOnSortChange}
|
onTableSort={handleOnSortChange}
|
||||||
|
onDeleteInstanceFromCache={handleDeleteInstanceFromCache}
|
||||||
sortOrder={sortOrder}
|
sortOrder={sortOrder}
|
||||||
queryParams={queryParams}
|
queryParams={queryParams}
|
||||||
loading={dataSource.loading}
|
loading={dataSource.loading}
|
||||||
|
|||||||
Reference in New Issue
Block a user