Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: ClusterNotFoundPopup: Fix to work with multi clusters #2512

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions frontend/src/components/App/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 (
Expand All @@ -46,7 +46,9 @@ function ClusterNotFoundPopup() {
p={0.5}
alignItems="center"
>
<Box p={0.5}>{t(`Something went wrong with cluster {{ cluster }}`, { cluster })}</Box>
<Box p={0.5}>
{t(`Something went wrong with cluster {{ cluster }}`, { cluster: problemCluster })}
</Box>
<Button variant="contained" size="small" href={window.desktopApi ? '#' : '/'}>
{t('Choose another cluster')}
</Button>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 (
<>
<Link
Expand All @@ -203,13 +210,9 @@ export default function Layout({}: LayoutProps) {
<TopBar />
<Sidebar />
<Main id="main" sx={{ flexGrow: 1, marginLeft: 'initial' }}>
{allClusters &&
!!clusterInURL &&
!Object.keys(allClusters).includes(getCluster() || '') ? (
<ClusterNotFoundPopup />
) : (
''
)}
{clustersNotInURL.length > 0
? clustersNotInURL.map(clusterName => <ClusterNotFoundPopup cluster={clusterName} />)
: ''}
<AlertNotification />
<Box>
<Div sx={theme.mixins.toolbar} />
Expand Down
Loading