Skip to content

Commit e02c9c5

Browse files
committed
frontend: Improve top bar menu on mobile
This change addresses issues with the top bar on mobile devices, both in the home view and in-cluster. Fixes: #2066 Signed-off-by: Evangelos Skopelitis <eskopelitis@microsoft.com>
1 parent 82eb285 commit e02c9c5

File tree

7 files changed

+73
-35
lines changed

7 files changed

+73
-35
lines changed

frontend/src/components/App/TopBar.tsx

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,21 @@ function AppBarActionsMenu({
139139
appBarActions.map(action => {
140140
const Action = has(action, 'action') ? action.action : action;
141141
if (React.isValidElement(Action)) {
142+
const label = (action as AppBarAction)?.label;
142143
return (
143144
<ErrorBoundary>
144-
<MenuItem>{Action}</MenuItem>
145+
<MenuItem
146+
onClick={(action as AppBarAction)?.onClick || undefined}
147+
sx={{
148+
justifyContent: 'center',
149+
gap: '12px',
150+
}}
151+
>
152+
<ListItemIcon sx={{ minWidth: '40px', justifyContent: 'center' }}>
153+
{Action}
154+
</ListItemIcon>
155+
{label && <ListItemText primary={label} />}
156+
</MenuItem>
145157
</ErrorBoundary>
146158
);
147159
} else if (Action === null) {
@@ -150,7 +162,10 @@ function AppBarActionsMenu({
150162
const ActionComponent = Action as React.FC;
151163
return (
152164
<ErrorBoundary>
153-
<MenuItem>
165+
<MenuItem
166+
onClick={(action as AppBarAction)?.onClick || undefined}
167+
sx={{ justifyContent: 'center' }}
168+
>
154169
<ActionComponent />
155170
</MenuItem>
156171
</ErrorBoundary>
@@ -308,33 +323,41 @@ export function PureTopBar({
308323
id: DefaultAppBarAction.NOTIFICATION,
309324
action: null,
310325
},
311-
{
312-
id: DefaultAppBarAction.SETTINGS,
313-
action: (
314-
<MenuItem>
315-
<SettingsButton onClickExtra={handleMenuClose} />
316-
</MenuItem>
317-
),
318-
},
326+
...(isClusterContext
327+
? [
328+
{
329+
id: DefaultAppBarAction.SETTINGS,
330+
action: <SettingsButton onClickExtra={handleMenuClose} />,
331+
label: t('translation|Settings'),
332+
onClick: () => {
333+
handleMenuClose();
334+
history.push(createRouteURL('settingsCluster', { cluster }));
335+
},
336+
},
337+
]
338+
: []),
319339
{
320340
id: DefaultAppBarAction.USER,
321341
action: !!isClusterContext && (
322-
<MenuItem>
323-
<IconButton
324-
aria-label={t('Account of current user')}
325-
aria-controls={userMenuId}
326-
aria-haspopup="true"
327-
color="inherit"
328-
onClick={event => {
329-
handleMenuClose();
330-
handleProfileMenuOpen(event);
331-
}}
332-
size="medium"
333-
>
334-
<Icon icon="mdi:account" />
335-
</IconButton>
336-
</MenuItem>
342+
<IconButton
343+
aria-label={t('Account of current user')}
344+
aria-controls={userMenuId}
345+
aria-haspopup="true"
346+
color="inherit"
347+
onClick={event => {
348+
handleMenuClose();
349+
handleProfileMenuOpen(event);
350+
}}
351+
size="medium"
352+
>
353+
<Icon icon="mdi:account" />
354+
</IconButton>
337355
),
356+
label: t('translation|Account'),
357+
onClick: (event: React.MouseEvent<HTMLElement>) => {
358+
handleMenuClose();
359+
handleProfileMenuOpen(event);
360+
},
338361
},
339362
];
340363
const renderMobileMenu = (
@@ -395,6 +418,12 @@ export function PureTopBar({
395418
),
396419
},
397420
];
421+
422+
const visibleMobileActions = processAppBarActions(
423+
allAppBarActionsMobile,
424+
appBarActionsProcessors
425+
).filter(action => React.isValidElement(action.action) || typeof action === 'function');
426+
398427
return (
399428
<>
400429
<AppBar
@@ -425,16 +454,18 @@ export function PureTopBar({
425454
<HeadlampButton open={openSideBar} onToggleOpen={onToggleOpen} />
426455
<Box sx={{ flexGrow: 1 }} />
427456
<GlobalSearch isIconButton />
428-
<IconButton
429-
aria-label={t('show more')}
430-
aria-controls={mobileMenuId}
431-
aria-haspopup="true"
432-
onClick={handleMobileMenuOpen}
433-
color="inherit"
434-
size="medium"
435-
>
436-
<Icon icon="mdi:more-vert" />
437-
</IconButton>
457+
{visibleMobileActions.length > 0 && (
458+
<IconButton
459+
aria-label={t('show more')}
460+
aria-controls={mobileMenuId}
461+
aria-haspopup="true"
462+
onClick={handleMobileMenuOpen}
463+
color="inherit"
464+
size="medium"
465+
>
466+
<Icon icon="mdi:more-vert" />
467+
</IconButton>
468+
)}
438469
</>
439470
) : (
440471
<>

frontend/src/i18n/locales/de/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"Log out": "Abmelden",
8989
"(No token set up)": "(Kein Token eingerichtet)",
9090
"Account of current user": "Konto des aktuellen Benutzers",
91+
"Account": "",
9192
"Appbar Tools": "Appbar-Tools",
9293
"show more": "mehr anzeigen",
9394
"Getting auth info: {{ clusterName }}": "Rufe Authentifizierungsinformationen für {{ clusterName }} ab",

frontend/src/i18n/locales/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"Log out": "Log out",
8989
"(No token set up)": "(No token set up)",
9090
"Account of current user": "Account of current user",
91+
"Account": "Account",
9192
"Appbar Tools": "Appbar Tools",
9293
"show more": "show more",
9394
"Getting auth info: {{ clusterName }}": "Getting auth info: {{ clusterName }}",

frontend/src/i18n/locales/es/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"Log out": "Desconectar",
8989
"(No token set up)": "(Ningún token asignado)",
9090
"Account of current user": "Cuenta del usuario actual",
91+
"Account": "",
9192
"Appbar Tools": "Herramientas de la barra de aplicación",
9293
"show more": "mostrar más",
9394
"Getting auth info: {{ clusterName }}": "Obteniendo información de autenticación: {{ clusterName }}",

frontend/src/i18n/locales/fr/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"Log out": "Déconnexion",
8989
"(No token set up)": "(Pas de jeton mis en place)",
9090
"Account of current user": "Compte de l'utilisateur actuel",
91+
"Account": "",
9192
"Appbar Tools": "Outils de la barre d'application",
9293
"show more": "afficher plus",
9394
"Getting auth info: {{ clusterName }}": "Obtenir des informations d'authentification : {{ clusterName }}",

frontend/src/i18n/locales/pt/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"Log out": "Terminar sessão",
8989
"(No token set up)": "(Nenhum token establecido)",
9090
"Account of current user": "Conta do utilizador actual",
91+
"Account": "",
9192
"Appbar Tools": "Ferramentas da barra de aplicação",
9293
"show more": "mostrar mais",
9394
"Getting auth info: {{ clusterName }}": "A obter informação de autentição: {{ clusterName }}",

frontend/src/redux/actionButtonsSlice.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export type RowAction = {
2222
export type AppBarAction = {
2323
id: string;
2424
action?: AppBarActionType;
25+
label?: string;
26+
onClick?: (args?: any) => void;
2527
};
2628

2729
export enum DefaultHeaderAction {

0 commit comments

Comments
 (0)