From fed44283525d0d24e049c866d675d9cbce35ec0a Mon Sep 17 00:00:00 2001 From: Montse Ortega Date: Tue, 24 Dec 2024 08:18:05 +0100 Subject: [PATCH] Wait to load the sources table until agents and sources are loaded Signed-off-by: Montse Ortega --- .../contexts/discovery-sources/Provider.tsx | 4 ++-- .../steps/connect/sources-table/SourcesTable.tsx | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/demo/src/migration-wizard/contexts/discovery-sources/Provider.tsx b/apps/demo/src/migration-wizard/contexts/discovery-sources/Provider.tsx index 1aae687..3b0022e 100644 --- a/apps/demo/src/migration-wizard/contexts/discovery-sources/Provider.tsx +++ b/apps/demo/src/migration-wizard/contexts/discovery-sources/Provider.tsx @@ -97,9 +97,9 @@ export const Provider: React.FC = (props) => { }, [listSourcesState.value]); - const selectAgent = useCallback((agent: Agent) => { + const selectAgent = useCallback(async (agent: Agent) => { setAgentSelected(agent); - if (agent && agent.sourceId!==null) selectSourceById(agent.sourceId ?? ''); + if (agent && agent.sourceId!==null) await selectSourceById(agent.sourceId ?? ''); }, [selectSourceById]); diff --git a/apps/demo/src/migration-wizard/steps/connect/sources-table/SourcesTable.tsx b/apps/demo/src/migration-wizard/steps/connect/sources-table/SourcesTable.tsx index c1d6f8d..9c00b4d 100644 --- a/apps/demo/src/migration-wizard/steps/connect/sources-table/SourcesTable.tsx +++ b/apps/demo/src/migration-wizard/steps/connect/sources-table/SourcesTable.tsx @@ -7,7 +7,7 @@ import { Columns } from "./Columns"; import { DEFAULT_POLLING_DELAY, VALUE_NOT_AVAILABLE } from "./Constants"; import { SourceStatusView } from "./SourceStatusView"; import { useDiscoverySources } from "#/migration-wizard/contexts/discovery-sources/Context"; -import { Radio } from "@patternfly/react-core"; +import { Radio, Spinner } from "@patternfly/react-core"; import { Link } from "react-router-dom"; export const SourcesTable: React.FC = () => { @@ -15,10 +15,12 @@ export const SourcesTable: React.FC = () => { const hasAgents = discoverySourcesContext.agents && discoverySourcesContext.agents.length > 0; const [firstAgent, ..._otherAgents] = discoverySourcesContext.agents ?? []; - useMount(() => { + useMount(async () => { if (!discoverySourcesContext.isPolling) { - discoverySourcesContext.listSources(); - discoverySourcesContext.listAgents(); + await Promise.all([ + discoverySourcesContext.listSources(), + discoverySourcesContext.listAgents() + ]); } }); @@ -40,8 +42,9 @@ export const SourcesTable: React.FC = () => { // eslint-disable-next-line react-hooks/exhaustive-deps }, [discoverySourcesContext.agentSelected?.status]); - - + if (!discoverySourcesContext.agentSelected && !discoverySourcesContext.sourceSelected) { + return ; // Loading agent and source + } return ( {hasAgents && (