From a1a6a6c1e7392de749545991675a65fe0de4b154 Mon Sep 17 00:00:00 2001 From: Fernando Hoyos Date: Tue, 2 Apr 2024 11:27:45 +0200 Subject: [PATCH] Initialize error on namespace switch --- plugin/src/openshift/pages/IstioConfigListPage.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugin/src/openshift/pages/IstioConfigListPage.tsx b/plugin/src/openshift/pages/IstioConfigListPage.tsx index 49cdde32..7ba7357e 100644 --- a/plugin/src/openshift/pages/IstioConfigListPage.tsx +++ b/plugin/src/openshift/pages/IstioConfigListPage.tsx @@ -165,8 +165,8 @@ const newIstioResourceList = { const IstioConfigListPage = () => { const { ns } = useParams<{ ns: string }>(); const [loaded, setLoaded] = React.useState(false); - const [listItems, setListItems] = React.useState([]); - const [loadError, setLoadError] = React.useState(); + const [listItems, setListItems] = React.useState([]); + const [loadError, setLoadError] = React.useState(null); const history = useHistory(); const promises = React.useMemo(() => new PromisesRegistry(), []); @@ -221,6 +221,10 @@ const IstioConfigListPage = () => { }; React.useEffect(() => { + // initialize page + setLoaded(false); + setLoadError(null); + fetchIstioConfigs() .then(istioConfigs => { const istioConfigObjects = istioConfigs.map(istioConfig => { @@ -232,11 +236,12 @@ const IstioConfigListPage = () => { }); setListItems(istioConfigObjects); - setLoaded(true); }) .catch(error => { setLoadError({ title: error.response.statusText, message: error.response.data.error }); - return []; + }) + .finally(() => { + setLoaded(true); }); }, [ns, fetchIstioConfigs]);