refactor: list watch trigger

This commit is contained in:
jialin
2026-02-13 16:12:56 +08:00
parent af9890b16c
commit 88aafbaf7b
6 changed files with 79 additions and 88 deletions
@@ -10,7 +10,8 @@ import { ClusterListItem } from '../config/types';
*
* @returns loading, fetch, dataList
*/
export const useQueryClusterList = () => {
export const useQueryClusterList = (options?: { useStateData?: boolean }) => {
const { useStateData = true } = options || {};
const axiosTokenRef = useRef<CancelTokenSource | null>(null);
const [dataList, setDataList] = useState<
Array<Partial<ClusterListItem> & { label: string; value: number }>
@@ -27,13 +28,15 @@ export const useQueryClusterList = () => {
const res = await queryClusterList(params, {
token: axiosTokenRef.current.token
});
setDataList(
res.items?.map((item: ClusterListItem) => ({
...item,
label: item.name,
value: item.id
})) || []
);
if (useStateData) {
setDataList(
res.items?.map((item: ClusterListItem) => ({
...item,
label: item.name,
value: item.id
})) || []
);
}
return res.items || [];
},
{