fix: template display after initialized
This commit is contained in:
@@ -90,6 +90,7 @@ const AddModal: React.FC<AddModalProps> = ({
|
|||||||
const [instanceKeyword, setInstanceKeyword] = useState('');
|
const [instanceKeyword, setInstanceKeyword] = useState('');
|
||||||
const [templateKeyword, setTemplateKeyword] = useState('');
|
const [templateKeyword, setTemplateKeyword] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const initializedRef = useRef(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
detailData: instanceTypeList,
|
detailData: instanceTypeList,
|
||||||
@@ -279,6 +280,8 @@ const AddModal: React.FC<AddModalProps> = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
applySelection(first, template);
|
applySelection(first, template);
|
||||||
|
|
||||||
|
// initially finise
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch the (tenant-scoped) instance types + templates and auto-select.
|
// Fetch the (tenant-scoped) instance types + templates and auto-select.
|
||||||
@@ -287,19 +290,25 @@ const AddModal: React.FC<AddModalProps> = ({
|
|||||||
// picker settling on its default) the latest scope's result wins.
|
// picker settling on its default) the latest scope's result wins.
|
||||||
const loadCreateResources = (orgId?: number | null) => {
|
const loadCreateResources = (orgId?: number | null) => {
|
||||||
const session = ++sessionRef.current;
|
const session = ++sessionRef.current;
|
||||||
Promise.all([
|
try {
|
||||||
fetchData({ page: -1 }),
|
Promise.all([
|
||||||
fetchTemplates({ page: -1 }),
|
fetchData({ page: -1 }),
|
||||||
fetchClusterList({ page: -1 })
|
fetchTemplates({ page: -1 }),
|
||||||
]).then(([instanceResItems, templatesRes, clusters]) => {
|
fetchClusterList({ page: -1 })
|
||||||
if (sessionRef.current !== session) return;
|
]).then(([instanceResItems, templatesRes, clusters]) => {
|
||||||
applyAutoSelection(
|
if (sessionRef.current !== session) return;
|
||||||
instanceResItems || [],
|
applyAutoSelection(
|
||||||
templatesRes?.items || [],
|
instanceResItems || [],
|
||||||
(Array.isArray(clusters) ? clusters : (clusters as any)?.items) || [],
|
templatesRes?.items || [],
|
||||||
orgId
|
(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
|
// Platform admin retargeted the create to another org (or Global). The
|
||||||
@@ -324,11 +333,13 @@ const AddModal: React.FC<AddModalProps> = ({
|
|||||||
form.current?.applyInstanceType?.(undefined);
|
form.current?.applyInstanceType?.(undefined);
|
||||||
form.current?.setFieldValue?.('clusterId', null);
|
form.current?.setFieldValue?.('clusterId', null);
|
||||||
form.current?.setFieldValue?.(['spec', 'type'], undefined);
|
form.current?.setFieldValue?.(['spec', 'type'], undefined);
|
||||||
|
initializedRef.current = false;
|
||||||
loadCreateResources(orgId);
|
loadCreateResources(orgId);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) {
|
if (!open) {
|
||||||
|
initializedRef.current = false;
|
||||||
sessionRef.current += 1;
|
sessionRef.current += 1;
|
||||||
setInstanceTypeSelection({
|
setInstanceTypeSelection({
|
||||||
instanceType: undefined,
|
instanceType: undefined,
|
||||||
@@ -507,7 +518,7 @@ const AddModal: React.FC<AddModalProps> = ({
|
|||||||
onChange={(e) => setTemplateKeyword(e.target.value)}
|
onChange={(e) => setTemplateKeyword(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{filteredTemplates.length > 0 ? (
|
{filteredTemplates.length > 0 && initializedRef.current ? (
|
||||||
<TemplateSelector
|
<TemplateSelector
|
||||||
value={templateId}
|
value={templateId}
|
||||||
dataList={filteredTemplates}
|
dataList={filteredTemplates}
|
||||||
|
|||||||
Reference in New Issue
Block a user