fix: catalog size

This commit is contained in:
jialin
2026-01-12 12:24:34 +08:00
parent 05ad296b43
commit fc76822bdf
13 changed files with 413 additions and 35 deletions
@@ -2,9 +2,11 @@ import { createAxiosToken } from '@/hooks/use-chunk-request';
import { useRequest } from 'ahooks';
import { CancelTokenSource } from 'axios';
import { useEffect, useRef, useState } from 'react';
import { queryClusterDetail } from '../apis';
import { queryClusterDetail, queryClusterItem } from '../apis';
import { ClusterListItem } from '../config/types';
export const useClusterSystemLoad = () => {
const axiosTokenRef = useRef<CancelTokenSource | null>(null);
const [systemLoad, setSystemLoad] = useState<{
current: {
cpu: number;
@@ -22,7 +24,6 @@ export const useClusterSystemLoad = () => {
},
history: {}
});
const axiosTokenRef = useRef<CancelTokenSource | null>(null);
const {
run: fetchClusterSystemLoad,
@@ -71,3 +72,46 @@ export const useClusterSystemLoad = () => {
fetchClusterSystemLoad
};
};
export const useClusterDetail = () => {
const axiosTokenRef = useRef<CancelTokenSource | null>(null);
const [clusterDetail, setClusterDetail] = useState<ClusterListItem>(
{} as ClusterListItem
);
const {
run: fetchClusterDetail,
loading,
cancel
} = useRequest(
async (params) => {
axiosTokenRef.current?.cancel();
axiosTokenRef.current = createAxiosToken();
return await queryClusterItem(params, {
token: axiosTokenRef.current.token
});
},
{
manual: true,
onSuccess: (response) => {
setClusterDetail(response);
},
onError: () => {
setClusterDetail({} as ClusterListItem);
}
}
);
useEffect(() => {
return () => {
cancel();
axiosTokenRef.current?.cancel();
};
}, []);
return {
clusterDetail,
loading,
fetchClusterDetail
};
};