fix(user-models): hold empty state until infra queries resolve

Managers start in a loading state and gate the empty state on the
cluster/worker fetch, so the 'no clusters/workers' guidance no longer
flashes before the real infra data lands.
This commit is contained in:
jialin
2026-07-14 17:37:53 +08:00
committed by jialin
parent 6e321d2d99
commit 8eb871d0f5
+14 -4
View File
@@ -9,7 +9,7 @@ import {
import { useAccess, useIntl, useNavigate } from '@umijs/max'; import { useAccess, useIntl, useNavigate } from '@umijs/max';
import useMemoizedFn from 'ahooks/lib/useMemoizedFn'; import useMemoizedFn from 'ahooks/lib/useMemoizedFn';
import { Button, Input, Space } from 'antd'; import { Button, Input, Space } from 'antd';
import React, { useCallback, useEffect, useMemo } from 'react'; import React, { useCallback, useEffect, useMemo, useState } from 'react';
import PageBox from '../_components/page-box'; import PageBox from '../_components/page-box';
import { MY_MODELS_API, queryMyModels } from './apis'; import { MY_MODELS_API, queryMyModels } from './apis';
import APIAccessInfoModal from './components/api-access-info'; import APIAccessInfoModal from './components/api-access-info';
@@ -72,10 +72,18 @@ const UserModels: React.FC = () => {
const { getClusterList, getWorkerList, clusterList, workerList } = const { getClusterList, getWorkerList, clusterList, workerList } =
useFormInitialValues(); useFormInitialValues();
// Managers start in a loading state so the empty state waits for the
// infra queries to resolve — otherwise the initially-empty
// cluster/worker lists briefly flash the "no clusters" / "no workers"
// guidance before the real data lands.
const [infraLoading, setInfraLoading] = useState(!!canManageResources);
useEffect(() => { useEffect(() => {
if (canManageResources) { if (canManageResources) {
getClusterList(); setInfraLoading(true);
getWorkerList(); Promise.all([getClusterList(), getWorkerList()]).finally(() => {
setInfraLoading(false);
});
} }
}, [canManageResources]); }, [canManageResources]);
@@ -173,7 +181,9 @@ const UserModels: React.FC = () => {
}; };
const { noResourceResult } = useNoResourceResult({ const { noResourceResult } = useNoResourceResult({
loading: dataSource.loading, // Hold the empty state until infra queries resolve so managers don't
// see a "no clusters/workers" flash before the real data arrives.
loading: dataSource.loading || infraLoading,
loadend: dataSource.loadend, loadend: dataSource.loadend,
dataSource: dataList, dataSource: dataList,
// Preserve the original filters heuristic: only treat the current // Preserve the original filters heuristic: only treat the current