Skip to content

Commit

Permalink
Profile setting dialog (#1710)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDoberer authored Nov 25, 2020
1 parent 5d5d892 commit adff27d
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 7 deletions.
4 changes: 2 additions & 2 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
{
"path": "./public-ie11/luigi-ie11.js",
"maxSize": "580 kB",
"maxSize": "590 kB",
"compression": "none"
},
{
Expand Down Expand Up @@ -134,4 +134,4 @@
"type": "git",
"url": "ssh://github.com/SAP/luigi.git"
}
}
}
56 changes: 51 additions & 5 deletions core/src/Authorization.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{#if !isHidden}
<nav class="fd-menu">
<ul class="fd-menu__list fd-menu__list--no-shadow">
Expand Down Expand Up @@ -43,6 +42,28 @@
</a>
</li>
{/each}
{#if hasUserSettings}
<li class="fd-menu__item" on:click="{onUserSettingsClick}" data-testid="{getTestId(profileNav.settings)}">
<a aria-label="User Settings" class="fd-menu__link" data-testid="settings-link">
{#if profileNav.settings.icon}
{#if hasOpenUIicon(profileNav.settings)}
<span
class="fd-top-nav__icon sap-icon--{profileNav.settings.icon}"
></span>
{:else}
<img
class="fd-top-nav__icon nav-icon"
src="{profileNav.settings.icon}"
alt="{profileNav.settings.altText ? profileNav.settings.altText : ''}"
>
{/if}
{/if}
<span
class="fd-menu__title"
>{$getTranslation(profileNav.settings.label)}</span>
</a>
</li>
{/if}
{#if isAuthorizationEnabled || isProfileLogoutItem}
{#if isLoggedIn || !isAuthorizationEnabled && isProfileLogoutItem}
<li
Expand Down Expand Up @@ -84,7 +105,7 @@
<script>
import { AuthLayerSvc } from './services';
import { createEventDispatcher, onMount, getContext } from 'svelte';
import { LuigiAuth, LuigiConfig } from './core-api';
import { LuigiAuth, LuigiConfig, LuigiNavigation } from './core-api';
import {
AuthHelpers,
GenericHelpers,
Expand All @@ -102,9 +123,10 @@
let idpProviderInstance;
let userInfo;
let isLoggedIn;
let profileNav = { logout: {}, items: [] };
let profileNav = { logout: {}, items: [], settings: {} };
let isAuthorizationEnabled;
let isProfileLogoutItem;
let hasUserSettings;
let navProfileListenerInstalled;
let profileLogoutFnDefined;
let store = getContext('store');
Expand Down Expand Up @@ -159,17 +181,32 @@
const logoutItem = await LuigiConfig.getConfigValueAsync(
'navigation.profile.logout'
);
//check if the User Settings schema exist
const userSettings = await LuigiConfig.getConfigValueAsync(
'settings.userSettings'
);
hasUserSettings = Boolean(userSettings);
//check if Settings dropdown is enabled for navigation in Shellbar
const userSettingsProfileMenuEntry = await LuigiConfig.getConfigValueAsync(
'settings.userSettings.userSettingsProfileMenuEntry'
);

const profileNavData = {
items:
(await LuigiConfig.getConfigValueAsync(
'navigation.profile.items'
)) || []
};
if (hasUserSettings) {
profileNavData['settings'] = {
...TOP_NAV_DEFAULTS.userSettingsProfileMenuEntry,
...userSettingsProfileMenuEntry
};
}
profileNavData['logout'] = {
...TOP_NAV_DEFAULTS.logout,
...logoutItem
};

isProfileLogoutItem = Boolean(logoutItem);
profileLogoutFnDefined = false;
AuthLayerSvc.setProfileLogoutFn(null);
Expand Down Expand Up @@ -230,6 +267,15 @@
});
}

export function onUserSettingsClick() {
getUnsavedChangesModalPromise().then(() => {
LuigiNavigation.openAsModal('projects/pr1/users', {
title: 'Users',
size: 'm'
});
});
}

export function logout() {
AuthLayerSvc.logout();
}
Expand All @@ -251,4 +297,4 @@
display: block;
padding: 0.75rem 1rem 0.75rem 0.75rem;
}
</style>
</style>
4 changes: 4 additions & 0 deletions core/src/utilities/luigi-config-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ export const TOP_NAV_DEFAULTS = {
logout: {
label: 'Sign Out',
icon: 'log'
},
userSettingsProfileMenuEntry: {
label: 'Settings',
icon: 'settings'
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,43 @@ describe('Fiddle', () => {

cy.contains('Login again');
});
it('User settings in profile menu with custom label', () => {
newConfig.settings = {
userSettings: {
userSettingsProfileMenuEntry: {
label: 'My UserSettings',
icon: 'settings'
}
}
}
visitLoggedInWithAuthConfig('/', newConfig);
cy.get('[data-testid="luigi-topnav-profile"] button').click();
cy.get('[data-testid="settings-link"]').should('exist');
cy.get('[data-testid="settings-link"]').contains('My UserSettings')
});
it('User settings in profile menu with default label', () => {
newConfig.settings = {
userSettings: {}
}
visitLoggedInWithAuthConfig('/', newConfig);
cy.get('[data-testid="luigi-topnav-profile"] button').click();
cy.get('[data-testid="settings-link"]').should('exist');
cy.get('[data-testid="settings-link"]').contains('Settings')
});
it('User settings not in the profile menu, if not configured', () => {
newConfig.navigation.profile = {
logout: {
label: 'Bye bye',
icon: 'sys-cancel'
}
};
newConfig.auth.disableAutoLogin = false;
visitLoggedInWithAuthConfig('/', newConfig);

cy.get('[data-testid="luigi-topnav-profile"] button').click();
logoutLink().should('exist');
cy.get('[data-testid="settings-link"]').should('not.exist');
});
});
});

Expand Down
46 changes: 46 additions & 0 deletions test/e2e-test-application/src/luigi-config/extended/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,52 @@ class Settings {
}
};
}; */
userSettings = {
userSettingsProfileMenuEntry: {
label: 'My Settings',
icon: 'settings'
},
userSettingGroups: {
userAccount: {
label: 'User Account',
sublabel: 'username',
icon: 'icon.jpg',
title: 'title',
settings: {
name: { type: 'string', label: 'Name', isEditable: true },
email: { type: 'string', label: 'E-Mail', isEditable: false },
server: { type: 'string', label: 'Server', isEditable: false }
}
},
language: {
label: 'Language & Region',
sublabel: 'EN | Time Format: 12h',
icon: false,
title: 'Language & Region',
settings: {
language: {
type: 'enum',
label: 'Language and Region',
options: ['German', 'English', 'Spanish', 'French'],
description:
'After you save your settings, the browser will refresh for the new language to take effect.'
},
date: { type: 'string', label: 'Date Format' },
time: { type: 'enum', label: 'Time Format', options: ['12 h', '24 h'] }
}
},
privacy: {
label: 'Privacy',
title: 'Privacy',
settings: {
policy: {
type: 'string',
label: 'Privacy policy has not been defined.'
}
}
}
}
}
}

export const settings = new Settings();

0 comments on commit adff27d

Please sign in to comment.