Skip to content

fix(internet-header): add self admin url prop to override menu links #4936

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

Open
wants to merge 3 commits into
base: release/v8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/shy-seas-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/internet-header': patch
---

Added a `selfAdminOrigin` prop to the `swisspost-internet-header` component in order to let users override the calculated URL that is currently based on the `logoutURL`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the config is not hosted or served by the Design System, we can't alter it. Also, the system serving it is due to be deprecated, so it probably won't make sense to update it there either.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"endPoint": "https://n.post.ch",
"notificationsEndPoint": "https://post.ch/selfadmin/messages/unreadmessages",
"logoutURL": "https://post.ch/logout/",
"selfAdminOrigin": "https://post.ch",
"keepAliveURL": "https://post.ch/keepalive",
"autoLoginURL": "https://post.ch/idp/?app=loginwidget"
}
Expand Down Expand Up @@ -1385,6 +1386,7 @@
"endPoint": "https://n.post.ch",
"notificationsEndPoint": "https://post.ch/selfadmin/messages/unreadmessages",
"logoutURL": "https://post.ch/logout/",
"selfAdminOrigin": "https://post.ch",
"keepAliveURL": "https://post.ch/keepalive",
"autoLoginURL": "https://post.ch/idp/?app=loginwidget"
}
Expand Down Expand Up @@ -2297,6 +2299,7 @@
"endPoint": "https://n.post.ch",
"notificationsEndPoint": "https://post.ch/selfadmin/messages/unreadmessages",
"logoutURL": "https://post.ch/logout/",
"selfAdminOrigin": "https://post.ch",
"keepAliveURL": "https://post.ch/keepalive",
"autoLoginURL": "https://post.ch/idp/?app=loginwidget"
}
Expand Down Expand Up @@ -3209,6 +3212,7 @@
"endPoint": "https://n.post.ch",
"notificationsEndPoint": "https://post.ch/selfadmin/messages/unreadmessages",
"logoutURL": "https://post.ch/logout/",
"selfAdminOrigin": "https://post.ch",
"keepAliveURL": "https://post.ch/keepalive",
"autoLoginURL": "https://post.ch/idp/?app=loginwidget"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/internet-header/src/assets/js/klp-login-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ const vertx = window.vertx || {};
const getLocation = function (url) {
return new URL(url);
};
const url = getLocation(logoutURL());
originUrl = url.origin;

originUrl = platform.selfAdminOrigin ? platform.selfAdminOrigin : getLocation(logoutURL()).origin;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick, but since it's available, could as well use the nullish coalescing operator here.

Suggested change
originUrl = platform.selfAdminOrigin ? platform.selfAdminOrigin : getLocation(logoutURL()).origin;
originUrl = platform.selfAdminOrigin ?? getLocation(logoutURL()).origin;

const menuLinks = [
{
description: texts[currentLang].userProfile,
Expand Down
24 changes: 20 additions & 4 deletions packages/internet-header/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ export namespace Components {
}
interface PostKlpLoginWidget {
/**
* Override the logout-url provided by the portal config.
* Overrides the logout-url provided by the portal config.
*/
"logoutUrl"?: string;
/**
* Overrides the self-admin origin for menu links.
*/
"selfAdminOrigin"?: string;
/**
* Sets the focus on the login button
*/
Expand Down Expand Up @@ -154,7 +158,7 @@ export namespace Components {
*/
"login": boolean;
/**
* Override the logout-url provided by the portal config.
* Overrides the logout-url provided by the portal config.
*/
"logoutUrl"?: string;
/**
Expand All @@ -173,6 +177,10 @@ export namespace Components {
* Toggle the search button.
*/
"search": boolean;
/**
* Overrides the logout-url provided by the portal config.
*/
"selfAdminOrigin"?: string;
/**
* Toggle skiplinks. They help keyboard users to quickly jump to important sections of the page.
*/
Expand Down Expand Up @@ -342,9 +350,13 @@ declare namespace LocalJSX {
}
interface PostKlpLoginWidget {
/**
* Override the logout-url provided by the portal config.
* Overrides the logout-url provided by the portal config.
*/
"logoutUrl"?: string;
/**
* Overrides the self-admin origin for menu links.
*/
"selfAdminOrigin"?: string;
}
interface PostLanguageSwitch {
/**
Expand Down Expand Up @@ -442,7 +454,7 @@ declare namespace LocalJSX {
*/
"login"?: boolean;
/**
* Override the logout-url provided by the portal config.
* Overrides the logout-url provided by the portal config.
*/
"logoutUrl"?: string;
/**
Expand All @@ -465,6 +477,10 @@ declare namespace LocalJSX {
* Toggle the search button.
*/
"search"?: boolean;
/**
* Overrides the logout-url provided by the portal config.
*/
"selfAdminOrigin"?: string;
/**
* Toggle skiplinks. They help keyboard users to quickly jump to important sections of the page.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,15 @@ export class PostInternetHeader {
@Prop() languageLocalStorageKey?: string = 'swisspost-internet-header-language';

/**
* Override the logout-url provided by the portal config.
* Overrides the logout-url provided by the portal config.
*/
@Prop() logoutUrl?: string;

/**
* Overrides the logout-url provided by the portal config.
*/
@Prop() selfAdminOrigin?: string;
Comment on lines +107 to +114
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be a bit more specific here? These properties don't have the same effect and this comment will show up as type hint in project devs IDEs.


/**
* Set the currently activated route. If there is a link matching this URL in the header, it will be highlighted.
* Will also highlight partly matching URLs. When set to auto, will use current location.href for comparison.
Expand Down Expand Up @@ -182,6 +187,7 @@ export class PostInternetHeader {
try {
state.projectId = this.project;
state.stickyness = this.stickyness;
state.selfAdminOrigin = this.selfAdminOrigin;
state.environment = this.environment.toLocaleLowerCase() as Environment;
if (this.language !== undefined) state.currentLanguage = this.language;
state.languageSwitchOverrides =
Expand Down Expand Up @@ -528,7 +534,10 @@ export class PostInternetHeader {
<post-search onDropdownToggled={e => this.handleDropdownToggled(e)}></post-search>
</If>
<If condition={!!renderLogin}>
<post-klp-login-widget logout-url={this.logoutUrl}>
<post-klp-login-widget
logout-url={this.logoutUrl}
self-admin-origin={this.selfAdminOrigin}
>
<slot name="login-widget"></slot>
</post-klp-login-widget>
</If>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
| `languageLocalStorageKey` | `language-local-storage-key` | The header uses this local storage key to set the language. Disables automatic language selection. | `string \| undefined` | `'swisspost-internet-header-language'` |
| `languageSwitchOverrides` | `language-switch-overrides` | Override the language switch links with custom URLs. Helpful when your application contains sub-pages, and you would like to stay on subpages when the user changes language. | `IAvailableLanguage[] \| string \| undefined` | `undefined` |
| `login` | `login` | Toggle the login link (when logged out) or the user widget (when logged in). | `boolean` | `true` |
| `logoutUrl` | `logout-url` | Override the logout-url provided by the portal config. | `string \| undefined` | `undefined` |
| `logoutUrl` | `logout-url` | Overrides the logout-url provided by the portal config. | `string \| undefined` | `undefined` |
| `meta` | `meta` | Toggle the meta navigation. | `boolean` | `true` |
| `osFlyoutOverrides` | `os-flyout-overrides` | Online Services only: Add custom links to the special online service navigation entry | `NavMainEntity \| string \| undefined` | `undefined` |
| `project` | `project` | Your project id, previously passed as query string parameter serviceId. | `string` | `undefined` |
| `search` | `search` | Toggle the search button. | `boolean` | `true` |
| `selfAdminOrigin` | `self-admin-origin` | Overrides the logout-url provided by the portal config. | `string \| undefined` | `undefined` |
| `skiplinks` | `skiplinks` | Toggle skiplinks. They help keyboard users to quickly jump to important sections of the page. | `boolean` | `true` |
| `stickyness` | `stickyness` | Sticky behaviour of the header. | `"full" \| "main" \| "minimal" \| "none"` | `'minimal'` |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,34 @@ export class PostKlpLoginWidget implements IsFocusable {
@Element() host: HTMLPostKlpLoginWidgetElement;

/**
* Override the logout-url provided by the portal config.
* Overrides the logout-url provided by the portal config.
*/
@Prop() logoutUrl?: string;

/**
* Overrides the self-admin origin for menu links.
*/
@Prop() selfAdminOrigin?: string;

async componentDidLoad() {
if (
state.localizedConfig?.header?.showJobsLoginWidget ||
!state.localizedConfig?.header?.loginWidgetOptions
)
return;
const { initializeKLPLoginWidget } = await import('./klp-widget.controller.js');
const { platform, ...widgetOptions } = state.localizedConfig.header.loginWidgetOptions;
let { platform, ...widgetOptions } = state.localizedConfig.header.loginWidgetOptions;
if (this.logoutUrl !== undefined) {
platform = { ...platform, logoutURL: this.logoutUrl };
}
if (this.selfAdminOrigin !== undefined) {
platform = { ...platform, selfAdminOrigin: this.selfAdminOrigin };
}

initializeKLPLoginWidget('post-klp-login-widget', {
...widgetOptions,
environment: state.environment,
...(this.logoutUrl !== undefined
? { platform: { ...platform, logoutURL: this.logoutUrl } }
: { platform }),
platform,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ----------- | ------------ | ------------------------------------------------------ | --------------------- | ----------- |
| `logoutUrl` | `logout-url` | Override the logout-url provided by the portal config. | `string \| undefined` | `undefined` |
| Property | Attribute | Description | Type | Default |
| ----------------- | ------------------- | ------------------------------------------------------- | --------------------- | ----------- |
| `logoutUrl` | `logout-url` | Overrides the logout-url provided by the portal config. | `string \| undefined` | `undefined` |
| `selfAdminOrigin` | `self-admin-origin` | Overrides the self-admin origin for menu links. | `string \| undefined` | `undefined` |


## Methods
Expand Down
4 changes: 4 additions & 0 deletions packages/internet-header/src/data/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface HeaderState {
localizedCustomConfig?: ILocalizedCustomConfig;
osFlyoutOverrides?: NavMainEntity;
stickyness: StickynessOptions;
logoutUrl: string | undefined;
selfAdminOrigin: string | undefined;
}

export const { state, reset, dispose } = createStore<HeaderState>({
Expand All @@ -27,4 +29,6 @@ export const { state, reset, dispose } = createStore<HeaderState>({
login: true,
meta: true,
stickyness: 'minimal',
logoutUrl: undefined,
selfAdminOrigin: undefined,
});
1 change: 1 addition & 0 deletions packages/internet-header/src/models/header.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface ILoginWidgetOptions {
logoutURL: string;
keepAliveURL: string;
autoLoginURL: string;
selfAdminOrigin: string;
};
}

Expand Down
Loading