Skip to content

Commit

Permalink
ui: Fix the cluster version in create node and about page
Browse files Browse the repository at this point in the history
We couldn't retrieve the cluster version is because we call the
fetchClusterAction before we are authenticated to k8s api.

Solution: since we use the `cluster version` only in create node page
and about page, it makes sense to fetch the data only in those two
pages.
  • Loading branch information
ChengYanJin committed Apr 29, 2021
1 parent 8f058a9 commit 41092e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
10 changes: 8 additions & 2 deletions ui/src/containers/About.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import React, { useEffect } from 'react';
import styled from 'styled-components';
import { useSelector } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import { fetchClusterVersionAction } from '../ducks/app/nodes';
import { intl } from '../translations/IntlGlobalProvider';

const Title = styled.h3`
Expand All @@ -18,6 +19,11 @@ const AboutContainer = styled.div`

const About = (props) => {
const clusterVersion = useSelector((state) => state.app.nodes.clusterVersion);
const dispatch = useDispatch();
useEffect(() => {
dispatch(fetchClusterVersionAction());
}, [dispatch]);

return (
<AboutContainer>
<Title>{intl.translate('product_name')}</Title>
Expand Down
8 changes: 1 addition & 7 deletions ui/src/containers/Layout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@flow
import React, { useCallback, useEffect } from 'react';
import React, { useCallback } from 'react';
import { useDispatch } from 'react-redux';
import { ThemeProvider } from 'styled-components';
import { matchPath, RouteProps, Route, Redirect } from 'react-router';
Expand All @@ -15,7 +15,6 @@ import { intl } from '../translations/IntlGlobalProvider';
import { toggleSideBarAction } from '../ducks/app/layout';
import { removeNotificationAction } from '../ducks/app/notifications';
import CreateVolume from './CreateVolume';
import { fetchClusterVersionAction } from '../ducks/app/nodes';
import { useTypedSelector } from '../hooks';
import { Navbar } from '../components/Navbar';
import { Suspense } from 'react';
Expand Down Expand Up @@ -45,10 +44,6 @@ const Layout = () => {
const history = useHistory();
const location = useLocation();

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

const doesRouteMatch = useCallback(
(path: RouteProps) => {
const location = history.location;
Expand Down Expand Up @@ -82,7 +77,6 @@ const Layout = () => {
}),
'data-cy': 'sidebar_item_dashboard',
},
// TODO: Will move to the global navbar
{
label: intl.translate('nodes'),
icon: <i className="fas fa-server" />,
Expand Down
2 changes: 2 additions & 0 deletions ui/src/containers/NodeCreateForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import isEmpty from 'lodash.isempty';
import {
createNodeAction,
clearCreateNodeErrorAction,
fetchClusterVersionAction,
} from '../ducks/app/nodes';
import { intl } from '../translations/IntlGlobalProvider';
import {
Expand Down Expand Up @@ -135,6 +136,7 @@ const NodeCreateForm = () => {
const history = useHistory();

useEffect(() => {
dispatch(fetchClusterVersionAction());
return () => {
dispatch(clearCreateNodeErrorAction());
};
Expand Down

0 comments on commit 41092e9

Please sign in to comment.