From ad41e5c8e096a0dde66b0109a2a6268b5a43a2a4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:19:17 +0100 Subject: [PATCH] :sparkles: feat(core): enable / disable animation with local storage for e2e testing (#1551) * Create PR for #1550 * feat(core): disable animation by set local storage key baloise-animated to false --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Gery Hirschfeld --- .changeset/tough-cows-flash.md | 5 +++++ .../core/src/components/bal-app/bal-app.tsx | 4 +++- packages/core/src/utils/config/config.const.ts | 1 + packages/core/src/utils/config/config.ts | 18 +++++++++++++++++- packages/core/src/utils/config/initialize.ts | 3 ++- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .changeset/tough-cows-flash.md diff --git a/.changeset/tough-cows-flash.md b/.changeset/tough-cows-flash.md new file mode 100644 index 0000000000..80139582a2 --- /dev/null +++ b/.changeset/tough-cows-flash.md @@ -0,0 +1,5 @@ +--- +'@baloise/ds-core': minor +--- + +**core**: disable animation by set local storage key baloise-animated to false diff --git a/packages/core/src/components/bal-app/bal-app.tsx b/packages/core/src/components/bal-app/bal-app.tsx index 88ae367f46..559a9924bd 100644 --- a/packages/core/src/components/bal-app/bal-app.tsx +++ b/packages/core/src/components/bal-app/bal-app.tsx @@ -34,7 +34,9 @@ export class App implements Loggable { @Prop({ reflect: true, mutable: true }) ready = false connectedCallback() { - updateBalAnimated(this.animated) + if (this.animated === false) { + updateBalAnimated(this.animated) + } if (balBrowser.hasWindow) { window.addEventListener('resize', this.debouncedNotify) diff --git a/packages/core/src/utils/config/config.const.ts b/packages/core/src/utils/config/config.const.ts index ee897399f0..93223cb2f7 100644 --- a/packages/core/src/utils/config/config.const.ts +++ b/packages/core/src/utils/config/config.const.ts @@ -1 +1,2 @@ export const BALOISE_SESSION_KEY = 'baloise-persist-config' +export const BALOISE_ANIMATION_KEY = 'baloise-animated' diff --git a/packages/core/src/utils/config/config.ts b/packages/core/src/utils/config/config.ts index 8e35d6073a..d133b07931 100644 --- a/packages/core/src/utils/config/config.ts +++ b/packages/core/src/utils/config/config.ts @@ -1,6 +1,6 @@ import { balBrowser } from '../browser' import { BalLogger } from '../log' -import { BALOISE_SESSION_KEY } from './config.const' +import { BALOISE_ANIMATION_KEY, BALOISE_SESSION_KEY } from './config.const' import { BalConfig, BalConfigState, BalIcons, BalLanguage, BalRegion } from './config.types' import { BalConfigObserver } from './observable/observer' import { defaultConfig } from './config.default' @@ -179,6 +179,22 @@ export const configFromSession = (win: Window): any => { } } +export const configFromLocalStorage = (win: Window): any => { + try { + const animated = JSON.parse(win.localStorage.getItem(BALOISE_ANIMATION_KEY)) + + if (animated !== null) { + return { + animated, + } + } + + return {} + } catch (e) { + return {} + } +} + export const saveConfig = (win: Window, c: any) => { try { win.sessionStorage.setItem(BALOISE_SESSION_KEY, JSON.stringify(c)) diff --git a/packages/core/src/utils/config/initialize.ts b/packages/core/src/utils/config/initialize.ts index 9f9e78435c..e7f9773b7d 100644 --- a/packages/core/src/utils/config/initialize.ts +++ b/packages/core/src/utils/config/initialize.ts @@ -1,5 +1,5 @@ import { balBrowser } from '../browser' -import { config, configFromSession } from './config' +import { config, configFromLocalStorage, configFromSession } from './config' import { BalConfig } from './config.types' @@ -12,6 +12,7 @@ export const setupConfig = (userConfig: BalConfig = {}, win = {} as any) => { config.reset({ ...configFromSession(win), + ...configFromLocalStorage(win), ...userConfig, icons: { ...configFromSession(win).icons,