Skip to content

Commit

Permalink
fix: get clusters (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
CristhianF7 authored Sep 4, 2023
1 parent 7de1c4b commit e2d1b07
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 9 deletions.
5 changes: 1 addition & 4 deletions charts/console/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ spec:
- name: INSTALL_METHOD
value: {{ .Values.installMethod | default "helm" }}
- name: K1_ACCESS_TOKEN
valueFrom:
secretKeyRef:
name: {{ .Values.existingSecret | default "kubefirst-initial-secrets" }}
key: K1_ACCESS_TOKEN
value: feedkray
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
Expand Down
24 changes: 22 additions & 2 deletions containers/header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import React, { FunctionComponent } from 'react';
import React, { FunctionComponent, useEffect } from 'react';

import { setSelectedCluster } from '../../redux/slices/cluster.slice';
import { getClusters } from '../../redux/thunks/api.thunk';
import { useAppDispatch, useAppSelector } from '../../redux/store';

import { Container } from './header.styled';

const Header: FunctionComponent = () => <Container />;
const Header: FunctionComponent = () => {
const dispatch = useAppDispatch();
const { managementCluster } = useAppSelector(({ api }) => api);

useEffect(() => {
dispatch(getClusters());
}, [dispatch]);

useEffect(() => {
if (managementCluster && managementCluster.id) {
dispatch(setSelectedCluster(managementCluster));
}
}, [dispatch, managementCluster]);

return <Container />;
};

export default Header;
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const nextConfig = {
dangerouslyAllowSVG: true,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
remotePatterns: [],
unoptimized: false,
unoptimized: true,
remotePatterns: [
{
protocol: 'https',
Expand Down
35 changes: 33 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
import Provision from './provision';
import React, { FunctionComponent, useEffect } from 'react';
import { useRouter } from 'next/router';

import { useAppDispatch, useAppSelector } from '../redux/store';
import { getClusters } from '../redux/thunks/api.thunk';
import withConfig from '../hoc/withConfig';
import { setSelectedCluster } from '../redux/slices/cluster.slice';
export { getServerSideProps } from '../hoc/withConfig';

export default Provision;
const MainPage: FunctionComponent = () => {
const dispatch = useAppDispatch();
const { push } = useRouter();

const { managementCluster } = useAppSelector(({ api }) => api);

useEffect(() => {
dispatch(getClusters())
.unwrap()
.then(() => {
push('/services');
})
.catch(() => {
push('/provision');
});
}, [dispatch, push]);

useEffect(() => {
if (managementCluster && managementCluster.id) {
dispatch(setSelectedCluster(managementCluster));
}
}, [dispatch, managementCluster]);

return null;
};

export default withConfig(MainPage);
4 changes: 4 additions & 0 deletions redux/thunks/api.thunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ export const getClusters = createAsyncThunk<
throw res.error;
}

if (!res.data && !res.data[0]) {
throw new Error('No clusters found');
}

// only process single expected management cluster
return mapClusterFromRaw(res.data[0]);
});
Expand Down

0 comments on commit e2d1b07

Please sign in to comment.