fix: catalog size
This commit is contained in:
+46
-2
@@ -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
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user