From de3ea8b791245a4e5cbdea91c9103be0aab5e545 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Tue, 17 Jan 2023 16:27:17 +0100 Subject: [PATCH] migrate UmbCurrentUserHistoryStore to UmbContextAlias --- .../src/backoffice/backoffice.element.ts | 7 +++++-- .../current-user/current-user-history.store.ts | 13 +++++++------ .../layouts/modal-layout-current-user.element.ts | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/backoffice.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/backoffice.element.ts index 14fdd57669..d7b1b6b3d8 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/backoffice.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/backoffice.element.ts @@ -7,7 +7,10 @@ import { UmbNotificationService, UMB_NOTIFICATION_SERVICE_CONTEXT_ALIAS } from ' import { UmbUserStore, UMB_USER_STORE_CONTEXT_ALIAS } from './users/users/user.store'; import { UmbUserGroupStore, UMB_USER_GROUP_STORE_CONTEXT_ALIAS } from './users/user-groups/user-group.store'; import { UmbCurrentUserStore, UMB_CURRENT_USER_STORE_CONTEXT_ALIAS } from './users/current-user/current-user.store'; -import { UmbCurrentUserHistoryStore } from './users/current-user/current-user-history.store'; +import { + UmbCurrentUserHistoryStore, + UMB_CURRENT_USER_HISTORY_STORE_CONTEXT_ALIAS, +} from './users/current-user/current-user-history.store'; import { UmbDocumentTypeStore, @@ -71,7 +74,7 @@ export class UmbBackofficeElement extends UmbLitElement { this.provideContext(UMB_USER_GROUP_STORE_CONTEXT_ALIAS, new UmbUserGroupStore(this)); this.provideContext(UMB_MEMBER_GROUP_STORE_CONTEXT_ALIAS, new UmbMemberGroupStore(this)); this.provideContext(UMB_SECTION_STORE_CONTEXT_ALIAS, new UmbSectionStore()); - this.provideContext('umbCurrentUserHistoryStore', new UmbCurrentUserHistoryStore()); + this.provideContext(UMB_CURRENT_USER_HISTORY_STORE_CONTEXT_ALIAS, new UmbCurrentUserHistoryStore()); this.provideContext('umbDictionaryStore', new UmbDictionaryStore(this)); this.provideContext('umbDocumentBlueprintStore', new UmbDocumentBlueprintStore(this)); } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-history.store.ts b/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-history.store.ts index 76f6651277..e2558a5eba 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-history.store.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-history.store.ts @@ -1,3 +1,4 @@ +import { UmbContextAlias } from '@umbraco-cms/context-api'; import { createObservablePart, UniqueBehaviorSubject } from '@umbraco-cms/observable-api'; export type UmbModelType = 'dialog' | 'sidebar'; @@ -9,14 +10,10 @@ export type UmbCurrentUserHistoryItem = { }; export class UmbCurrentUserHistoryStore { - - #history = new UniqueBehaviorSubject( - >[] - ); + #history = new UniqueBehaviorSubject(>[]); public readonly history = this.#history.asObservable(); - public readonly latestHistory = createObservablePart(this.#history, historyItems => historyItems.slice(-10)); - + public readonly latestHistory = createObservablePart(this.#history, (historyItems) => historyItems.slice(-10)); constructor() { if (!('navigation' in window)) return; @@ -52,3 +49,7 @@ export class UmbCurrentUserHistoryStore { this.#history.next([]); } } + +export const UMB_CURRENT_USER_HISTORY_STORE_CONTEXT_ALIAS = new UmbContextAlias( + UmbCurrentUserHistoryStore.name +); diff --git a/src/Umbraco.Web.UI.Client/src/core/modal/layouts/modal-layout-current-user.element.ts b/src/Umbraco.Web.UI.Client/src/core/modal/layouts/modal-layout-current-user.element.ts index e647d8a2ed..e3fad1ac29 100644 --- a/src/Umbraco.Web.UI.Client/src/core/modal/layouts/modal-layout-current-user.element.ts +++ b/src/Umbraco.Web.UI.Client/src/core/modal/layouts/modal-layout-current-user.element.ts @@ -6,6 +6,7 @@ import type { UserDetails } from '@umbraco-cms/models'; import { UmbCurrentUserHistoryStore, UmbCurrentUserHistoryItem, + UMB_CURRENT_USER_HISTORY_STORE_CONTEXT_ALIAS, } from 'src/backoffice/users/current-user/current-user-history.store'; import { UmbCurrentUserStore, @@ -102,7 +103,7 @@ export class UmbModalLayoutCurrentUserElement extends UmbLitElement { this._observeCurrentUser(); }); - this.consumeContext('umbCurrentUserHistoryStore', (_instance) => { + this.consumeContext(UMB_CURRENT_USER_HISTORY_STORE_CONTEXT_ALIAS, (_instance) => { this._currentUserHistoryStore = _instance; this._observeHistory(); });