Skip to content

Commit

Permalink
fix(internet-header, documentation): removes code smells detected by …
Browse files Browse the repository at this point in the history
…sonar cloud (#1872)

Co-authored-by: Philipp Gfeller <[email protected]>
  • Loading branch information
b1aserlu and gfellerph authored Aug 24, 2023
1 parent 4a93837 commit 05870c6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-shrimps-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@swisspost/internet-header': patch
---

Fixed a line of code that was not compliant with quality rules
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ function killAutoHideTimeout(timeoutStore: ReturnType<typeof setTimeout>[], args
function render(args: Args, context: StoryContext) {
const [_, updateArgs] = useArgs();

updateAlignments();
updateAlignments(args, updateArgs);

const timeoutStore = timeoutStores[context.name as keyof ITimeoutStores];

Expand All @@ -353,8 +353,15 @@ function render(args: Args, context: StoryContext) {
const isFixed = args.position === 'fixed';
const alignV = args.alignVRestricted ?? args.alignV;
const alignH = args.alignHRestricted ?? args.alignH;
const role = isFixed ? 'alert' : 'status';
const ariaLive = isFixed ? 'assertive' : 'polite';
let role;
let ariaLive;
if (isFixed) {
role = 'alert';
ariaLive = 'assertive';
} else {
role = 'status';
ariaLive = 'polite';
}

const dismissibleButton =
args.dismissible || isFixed
Expand Down Expand Up @@ -383,44 +390,43 @@ function render(args: Args, context: StoryContext) {
</div>
`;

let wrappedContent;
if (args.stacked) {
return html`
<div
aria-live="polite"
aria-atomic="true"
class="${`toast-container toast-${alignV}-${alignH}`}"
>
${component} ${component}
</div>
wrappedContent = html`
${component} ${component}
`;
} else if (isFixed) {
if (args.show) createAutoHideTimeout(timeoutStore, args, updateArgs);

return html`
<div
aria-live="polite"
aria-atomic="true"
class="${`toast-container toast-${alignV}-${alignH}`}"
>
${args.show ? component : null}
</div>
`;
if (args.show) {
createAutoHideTimeout(timeoutStore, args, updateArgs);
wrappedContent = component;
} else {
wrappedContent = null;
}
} else {
return component;
}
return html`
<div
aria-live="polite"
aria-atomic="true"
class="${`toast-container toast-${alignV}-${alignH}`}"
>
${wrappedContent}
</div>
`;
}

function updateAlignments() {
if (args.alignH && args.alignHRestricted && args.alignH !== args.alignHRestricted) {
args.alignV === 'center'
? updateArgs({ alignH: args.alignHRestricted })
: updateArgs({ alignHRestricted: args.alignH });
}
function updateAlignments(args: Args, updateArgs: Function) {
if (args.alignH && args.alignHRestricted && args.alignH !== args.alignHRestricted) {
args.alignV === 'center'
? updateArgs({ alignH: args.alignHRestricted })
: updateArgs({ alignHRestricted: args.alignH });
}

if (args.alignV && args.alignVRestricted && args.alignV !== args.alignVRestricted) {
args.alignH === 'full-width'
? updateArgs({ alignV: args.alignVRestricted })
: updateArgs({ alignVRestricted: args.alignV });
}
if (args.alignV && args.alignVRestricted && args.alignV !== args.alignVRestricted) {
args.alignH === 'full-width'
? updateArgs({ alignV: args.alignVRestricted })
: updateArgs({ alignVRestricted: args.alignV });
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/internet-header/src/assets/js/klp-login-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ const vertx = window.vertx || {};
const messagesUrl = originUrl + '/selfadmin/messages/?lang=' + currentLang;

if (options !== undefined) {
conf = Object.assign({}, conf, options);
conf = { ...conf, ...options };
}

function isHTML5StorageSupported() {
Expand Down

0 comments on commit 05870c6

Please sign in to comment.