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

ui: Remove useLogoutEffect and display an error instead of logging out in case of an issue while authenticating on Salt API #3330

Merged
merged 6 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# CHANGELOG

## Release 2.9.1 (in development)
### Bug fixes

- Re-support MetalK8s UI on Firefox
(PR[#3399](https://github.com/scality/metalk8s/pull/3330),

- Remove unnecessary `View logical alerts` toggle in the Alert page
(PR[#3399](https://github.com/scality/metalk8s/pull/3330),

## Release 2.9.0
### Features Added
Expand Down
2 changes: 1 addition & 1 deletion eve/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ models:
name: Init terraform
command: |-
for try in $(seq 1 $MAX_RETRIES); do
if terraform init; then
if terraform init --verify-plugins=false; then
break
elif [ $try -lt $MAX_RETRIES ]; then
rm -rf .terraform/
Expand Down
31 changes: 3 additions & 28 deletions ui/src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,7 @@ function useNavbarVersion(navbarRef: { current: NavbarWebComponent | null }): st
function useLoginEffect(navbarRef: { current: NavbarWebComponent | null }, version: string | null) {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const dispatch = useDispatch();
const user = useTypedSelector((state) => state.oidc?.user);
const userStoredInRedux = useRef(false);

useEffect(() => {
if (user) {
userStoredInRedux.current = true;
}
}, [!!user])


useEffect(() => {
if (!navbarRef.current || !version) {
return;
Expand Down Expand Up @@ -111,7 +103,7 @@ function useLoginEffect(navbarRef: { current: NavbarWebComponent | null }, versi
};
}, [navbarRef, version, dispatch]);

return { isAuthenticated: isAuthenticated && userStoredInRedux.current };
return { isAuthenticated };
}

function useLanguageEffect(navbarRef: { current: NavbarWebComponent | null }, version: string | null) {
Expand Down Expand Up @@ -180,22 +172,6 @@ function useThemeEffect(navbarRef: { current: NavbarWebComponent | null }, versi
}, [navbarRef, version, dispatch]);
}

function useLogoutEffect(
navbarRef: { current: NavbarWebComponent | null },
isAuthenticated: boolean,
) {
const user = useTypedSelector((state) => state.oidc?.user);
useLayoutEffect(() => {
if (!navbarRef.current) {
return;
}

if (isAuthenticated && !user) {
navbarRef.current.logOut();
}
}, [navbarRef, !user, isAuthenticated]);
}

function ErrorFallback() {
const { language, api } = useTypedSelector((state) => state.config);
const url_support = api?.url_support;
Expand All @@ -220,8 +196,7 @@ function InternalNavbar() {
const navbarRef = useRef<NavbarWebComponent | null>(null);

const version = useNavbarVersion(navbarRef);
const { isAuthenticated } = useLoginEffect(navbarRef, version);
useLogoutEffect(navbarRef, isAuthenticated);
useLoginEffect(navbarRef, version);
useLanguageEffect(navbarRef, version);
useThemeEffect(navbarRef, version);

Expand Down
31 changes: 7 additions & 24 deletions ui/src/containers/AlertPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@flow
import React, { useMemo, useState } from 'react';
import React, { useMemo } from 'react';
import styled, { useTheme } from 'styled-components';
import { useHistory } from 'react-router';
import { useLocation } from 'react-router-dom';
Expand All @@ -10,7 +10,7 @@ import {
useFilters,
useGlobalFilter,
} from 'react-table';
import { EmptyTable, SearchInput, Toggle } from '@scality/core-ui';
import { EmptyTable, SearchInput } from '@scality/core-ui';
import { padding, fontSize } from '@scality/core-ui/dist/style/theme';
import { useAlerts } from './AlertProvider';
import CircleStatus from '../components/CircleStatus';
Expand Down Expand Up @@ -260,7 +260,7 @@ function GlobalFilter({
);
}

function ActiveAlertTab({ columns, data, displayLogical, setDisplayLogical }) {
function ActiveAlertTab({ columns, data }) {
const query = useQuery();
const querySearch = query.get('search');
const querySort = query.get('sort');
Expand Down Expand Up @@ -344,22 +344,13 @@ function ActiveAlertTab({ columns, data, displayLogical, setDisplayLogical }) {
colSpan={visibleColumns.length}
style={{
textAlign: 'left',
display: 'flex',
justifyItems: 'stretch',
alignItems: 'center',
}}
>
<GlobalFilter
preGlobalFilteredRows={preGlobalFilteredRows}
globalFilter={state.globalFilter}
setGlobalFilter={setGlobalFilter}
/>

<Toggle
label={'View logical alerts'}
toggle={displayLogical}
onChange={(evt) => setDisplayLogical(evt.target.checked)}
/>
</tr>

{headerGroups.map((headerGroup) => {
Expand Down Expand Up @@ -435,21 +426,15 @@ function ActiveAlertTab({ columns, data, displayLogical, setDisplayLogical }) {

export default function AlertPage() {
const alerts = useAlerts({});
const [displayLogical, setDisplayLogical] = useState(false);
const leafAlerts = useMemo(
() => alerts?.alerts.filter((alert) => !alert.labels.children) || [],
[JSON.stringify(alerts?.alerts)],
);

const displayedAlerts = useMemo(
() => (displayLogical ? alerts?.alerts : leafAlerts) || [],
[JSON.stringify(alerts?.alerts), displayLogical],
);

const criticalAlerts = displayedAlerts.filter(
const criticalAlerts = leafAlerts.filter(
(alert) => alert.severity === 'critical',
);
const wariningAlerts = displayedAlerts.filter(
const wariningAlerts = leafAlerts.filter(
(alert) => alert.severity === 'warning',
);

Expand Down Expand Up @@ -483,16 +468,14 @@ export default function AlertPage() {
return (
<AlertPageContainer>
<AlertPageHeader
activeAlerts={displayedAlerts.length}
activeAlerts={leafAlerts.length}
critical={criticalAlerts.length}
warning={wariningAlerts.length}
/>
<AlertContent>
<ActiveAlertTab
data={displayedAlerts}
data={leafAlerts}
columns={columns}
displayLogical={displayLogical}
setDisplayLogical={setDisplayLogical}
/>
</AlertContent>
</AlertPageContainer>
Expand Down
6 changes: 4 additions & 2 deletions ui/src/ducks/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { Effect, call, takeEvery, put, select } from 'redux-saga/effects';
import * as ApiSalt from '../services/salt/api';

import type { Config } from '../services/api';
import { apiConfigSelector, logoutAction } from './config';
import { apiConfigSelector } from './config';
import { connectSaltApiAction } from './app/salt';
import { User } from 'oidc-client';
import { addNotificationErrorAction } from './app/notifications';
import { intl } from '../translations/IntlGlobalProvider';

// Actions
const AUTHENTICATE_SALT_API = 'AUTHENTICATE_SALT_API';
Expand Down Expand Up @@ -68,7 +70,7 @@ export function* authenticateSaltApi(): Generator<Effect, void, any> {
}),
);
} else {
yield put(logoutAction());
yield put(addNotificationErrorAction({title: intl.translate('salt_login_error_title'), message: intl.translate('salt_login_error_message')}))
}
}

Expand Down
19 changes: 18 additions & 1 deletion ui/src/ducks/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ jest.mock('../index.js', () => {
};
});

import uuidv1 from 'uuid/v1';
jest.mock('uuid/v1', () => ({
__esModule: true,
default: () => 'uuidv1',
}));

import { call, put } from 'redux-saga/effects';
import {
SALT_AUTHENTICATION_FAILED,
Expand Down Expand Up @@ -68,6 +74,17 @@ it('Salt authentication failed', () => {
error: 'error',
};

expect(gen.next(result).value).toEqual(put({ type: LOGOUT }));
expect(gen.next(result).value).toEqual(
put({
payload: {
message:
'Some features of the UI may not work as expected (cluster expansion and displaying nodes IPs). Please try to logout and login again or contact your support if this error persist.',
title: 'An error occurred when authenticating on salt API',
uid: 'uuidv1',
variant: 'danger',
},
type: 'ADD_NOTIFICATION_ERROR',
}),
);
expect(gen.next().done).toEqual(true);
});
4 changes: 3 additions & 1 deletion ui/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,7 @@
"show_cluster_avg": "Show Cluster Average",
"cluster_avg": "Cluster avg",
"dashboard": "Dashboard",
"required_fields": "* Required fields"
"required_fields": "* Required fields",
"salt_login_error_title": "An error occurred when authenticating on salt API",
"salt_login_error_message": "Some features of the UI may not work as expected (cluster expansion and displaying nodes IPs). Please try to logout and login again or contact your support if this error persist."
}
4 changes: 3 additions & 1 deletion ui/src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@
"show_cluster_avg": "Montrer la moyenne du Cluster",
"cluster_avg": "Cluster moy",
"dashboard": "Dashboard",
"required_fields": "* Champs requis"
"required_fields": "* Champs requis",
"salt_login_error_title": "L'authentification aupres de Salt a échoué",
"salt_login_error_message": "Certaines fonctionalité de l'interface peuvent ne pas fonctionner (deploiement d'un nouveau node ou affichage des IPs d'un node). Veuillez essayer de vous deconnecter et de vous reconnecter, ou si l'erreur persiste merci de bien vouloir contacter votre support."

}