diff --git a/src/pages/gpu-service/instances/components/add-modal.tsx b/src/pages/gpu-service/instances/components/add-modal.tsx index dc3162a4..a92b978a 100644 --- a/src/pages/gpu-service/instances/components/add-modal.tsx +++ b/src/pages/gpu-service/instances/components/add-modal.tsx @@ -90,6 +90,7 @@ const AddModal: React.FC = ({ const [instanceKeyword, setInstanceKeyword] = useState(''); const [templateKeyword, setTemplateKeyword] = useState(''); const [loading, setLoading] = useState(false); + const initializedRef = useRef(false); const { detailData: instanceTypeList, @@ -279,6 +280,8 @@ const AddModal: React.FC = ({ ); applySelection(first, template); + + // initially finise }; // Fetch the (tenant-scoped) instance types + templates and auto-select. @@ -287,19 +290,25 @@ const AddModal: React.FC = ({ // picker settling on its default) the latest scope's result wins. const loadCreateResources = (orgId?: number | null) => { const session = ++sessionRef.current; - Promise.all([ - fetchData({ page: -1 }), - fetchTemplates({ page: -1 }), - fetchClusterList({ page: -1 }) - ]).then(([instanceResItems, templatesRes, clusters]) => { - if (sessionRef.current !== session) return; - applyAutoSelection( - instanceResItems || [], - templatesRes?.items || [], - (Array.isArray(clusters) ? clusters : (clusters as any)?.items) || [], - orgId - ); - }); + try { + Promise.all([ + fetchData({ page: -1 }), + fetchTemplates({ page: -1 }), + fetchClusterList({ page: -1 }) + ]).then(([instanceResItems, templatesRes, clusters]) => { + if (sessionRef.current !== session) return; + applyAutoSelection( + instanceResItems || [], + templatesRes?.items || [], + (Array.isArray(clusters) ? clusters : (clusters as any)?.items) || [], + orgId + ); + initializedRef.current = true; + }); + } catch (error) { + } finally { + initializedRef.current = true; + } }; // Platform admin retargeted the create to another org (or Global). The @@ -324,11 +333,13 @@ const AddModal: React.FC = ({ form.current?.applyInstanceType?.(undefined); form.current?.setFieldValue?.('clusterId', null); form.current?.setFieldValue?.(['spec', 'type'], undefined); + initializedRef.current = false; loadCreateResources(orgId); }; useEffect(() => { if (!open) { + initializedRef.current = false; sessionRef.current += 1; setInstanceTypeSelection({ instanceType: undefined, @@ -507,7 +518,7 @@ const AddModal: React.FC = ({ onChange={(e) => setTemplateKeyword(e.target.value)} /> - {filteredTemplates.length > 0 ? ( + {filteredTemplates.length > 0 && initializedRef.current ? (