Skip to content

Commit

Permalink
Merge pull request #2336 from headlamp-k8s/something-went-wrong
Browse files Browse the repository at this point in the history
frontend: AlertNotification: Improve alert component
  • Loading branch information
illume committed Sep 30, 2024
2 parents 1e29eea + cdc023e commit 00976c8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
44 changes: 27 additions & 17 deletions frontend/src/components/common/AlertNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Box, Button } from '@mui/material';
import { Alert, Button, Typography } from '@mui/material';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { matchPath, useLocation } from 'react-router-dom';
import { testClusterHealth } from '../../lib/k8s/apiProxy';
import { getRoute, getRoutePath } from '../../lib/router';
import { getCluster } from '../../lib/util';
import { useSidebarInfo } from '../Sidebar';

// in ms
const NETWORK_STATUS_CHECK_TIME = 5000;
Expand All @@ -20,7 +19,6 @@ export interface PureAlertNotificationProps {
const ROUTES_WITHOUT_ALERT = ['login', 'token', 'settingsCluster'];

export function PureAlertNotification({ checkerFunction }: PureAlertNotificationProps) {
const { width: sidebarWidth } = useSidebarInfo();
const [networkStatusCheckTimeFactor, setNetworkStatusCheckTimeFactor] = React.useState(0);
const [error, setError] = React.useState<null | string | boolean>(null);
const [intervalID, setIntervalID] = React.useState<NodeJS.Timeout | null>(null);
Expand Down Expand Up @@ -99,32 +97,33 @@ export function PureAlertNotification({ checkerFunction }: PureAlertNotification
}

return (
<Box
<Alert
variant="filled"
severity="error"
sx={theme => ({
color: theme.palette.common.white,
background: theme.palette.error.main,
textAlign: 'center',
display: 'flex',
paddingTop: theme.spacing(1),
paddingBottom: theme.spacing(0.5),
paddingTop: theme.spacing(0.5),
paddingBottom: theme.spacing(1),
paddingRight: theme.spacing(3),
justifyContent: 'center',
position: 'fixed',
zIndex: theme.zIndex.snackbar + 1,
width: '100%',
top: '0',
height: '3.8vh',
alignItems: 'center',
left: '50%',
width: 'auto',
transform: 'translateX(-50%)',
})}
bgcolor="error.main"
paddingRight={sidebarWidth}
>
<Box>
{t('Something went wrong.')}
action={
<Button
sx={theme => ({
color: theme.palette.error.main,
borderColor: theme.palette.error.main,
background: theme.palette.common.white,
lineHeight: '1',
marginLeft: theme.spacing(1),
lineHeight: theme.typography.body2.lineHeight,
'&:hover': {
color: theme.palette.common.white,
borderColor: theme.palette.common.white,
Expand All @@ -136,8 +135,19 @@ export function PureAlertNotification({ checkerFunction }: PureAlertNotification
>
{t('translation|Try Again')}
</Button>
</Box>
</Box>
}
>
<Typography
variant="body2"
sx={theme => ({
paddingTop: theme.spacing(0.5),
fontWeight: 'bold',
fontSize: '16px',
})}
>
{t('translation|Lost connection to the cluster.')}
</Typography>
</Alert>
);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/i18n/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"Reason": "Ereignis",
"Last Seen": "Zuletzt gesehen",
"Offline": "Offline",
"Something went wrong.": "Etwas ist schief gelaufen.",
"Lost connection to the cluster.": "",
"No": "Nein",
"Yes": "Ja",
"Toggle fullscreen": "Vollbild ein/aus",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"Reason": "Reason",
"Last Seen": "Last Seen",
"Offline": "Offline",
"Something went wrong.": "Something went wrong.",
"Lost connection to the cluster.": "Lost connection to the cluster.",
"No": "No",
"Yes": "Yes",
"Toggle fullscreen": "Toggle fullscreen",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/i18n/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"Reason": "Razón",
"Last Seen": "Últi. ocurrencia",
"Offline": "Desconectado",
"Something went wrong.": "Algo ha fallado.",
"Lost connection to the cluster.": "",
"No": "No",
"Yes": "",
"Toggle fullscreen": "Alternar pantalla completa",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/i18n/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"Reason": "Motif",
"Last Seen": "Dernière vue",
"Offline": "Hors ligne",
"Something went wrong.": "Quelque chose s'est mal passé.",
"Lost connection to the cluster.": "",
"No": "Non",
"Yes": "Oui",
"Toggle fullscreen": "Basculer en mode plein écran",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/i18n/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"Reason": "Razão",
"Last Seen": "Visto últ. vez",
"Offline": "Desconectado",
"Something went wrong.": "Algo correu mal.",
"Lost connection to the cluster.": "",
"No": "Não",
"Yes": "Sim",
"Toggle fullscreen": "Alternar ecrã inteiro",
Expand Down

0 comments on commit 00976c8

Please sign in to comment.