From 948359bd68c52e44f18be30646be930848494bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Dudfield?= Date: Sun, 3 Nov 2024 16:10:35 +0100 Subject: [PATCH] frontend: ClusterNotFoundPopup: Fix to work with multi clusters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now when there's a wrong cluster name in the URL when using multiple clusters it also gives a cluster not found alert message for each cluster not found. Signed-off-by: René Dudfield --- frontend/src/components/App/Layout.tsx | 27 ++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/App/Layout.tsx b/frontend/src/components/App/Layout.tsx index 7d21938d19..ea80eb4497 100644 --- a/frontend/src/components/App/Layout.tsx +++ b/frontend/src/components/App/Layout.tsx @@ -10,7 +10,7 @@ import { useDispatch } from 'react-redux'; import { useClustersConf } from '../../lib/k8s'; import { request } from '../../lib/k8s/apiProxy'; import { Cluster } from '../../lib/k8s/cluster'; -import { getCluster } from '../../lib/util'; +import { getCluster, getClusterGroup } from '../../lib/util'; import { setConfig } from '../../redux/configSlice'; import { ConfigState } from '../../redux/configSlice'; import { useTypedSelector } from '../../redux/reducers/reducers'; @@ -27,8 +27,8 @@ export interface LayoutProps {} const CLUSTER_FETCH_INTERVAL = 10 * 1000; // ms -function ClusterNotFoundPopup() { - const cluster = getCluster(); +function ClusterNotFoundPopup({ cluster }: { cluster?: string }) { + const problemCluster = cluster || getCluster(); const { t } = useTranslation(); return ( @@ -46,7 +46,9 @@ function ClusterNotFoundPopup() { p={0.5} alignItems="center" > - {t(`Something went wrong with cluster {{ cluster }}`, { cluster })} + + {t(`Something went wrong with cluster {{ cluster }}`, { cluster: problemCluster })} + @@ -100,7 +102,6 @@ export default function Layout({}: LayoutProps) { const clusters = useTypedSelector(state => state.config.clusters); const { t } = useTranslation(); const allClusters = useClustersConf(); - const clusterInURL = getCluster(); const theme = useTheme(); /** This fetches the cluster config from the backend and updates the redux store on an interval. @@ -179,6 +180,12 @@ export default function Layout({}: LayoutProps) { }); }; + const urlClusters = getClusterGroup(); + const clustersNotInURL = + allClusters && urlClusters.length !== 0 + ? urlClusters.filter(clusterName => !Object.keys(allClusters).includes(clusterName)) + : []; + return ( <>
- {allClusters && - !!clusterInURL && - !Object.keys(allClusters).includes(getCluster() || '') ? ( - - ) : ( - '' - )} + {clustersNotInURL.length > 0 + ? clustersNotInURL.map(clusterName => ) + : ''}