migrate umbCurrentUserStore to UmbContextAlias

This commit is contained in:
Jacob Overgaard
2023-01-17 15:03:13 +01:00
parent 360b8e0627
commit 6fde96e499
5 changed files with 14 additions and 8 deletions

View File

@@ -6,7 +6,7 @@ import { UmbModalService, UMB_MODAL_SERVICE_CONTEXT_ALIAS } from '../core/modal'
import { UmbNotificationService, UMB_NOTIFICATION_SERVICE_CONTEXT_ALIAS } from '../core/notification';
import { UmbUserStore } from './users/users/user.store';
import { UmbUserGroupStore } from './users/user-groups/user-group.store';
import { UmbCurrentUserStore } from './users/current-user/current-user.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 { UmbDocumentTypeStore } from './documents/document-types/document-type.store';
@@ -57,7 +57,7 @@ export class UmbBackofficeElement extends UmbLitElement {
this.provideContext(UMB_NOTIFICATION_SERVICE_CONTEXT_ALIAS, new UmbNotificationService());
// TODO: find a way this is possible outside this element. It needs to be possible to register stores in extensions
this.provideContext('umbCurrentUserStore', new UmbCurrentUserStore());
this.provideContext(UMB_CURRENT_USER_STORE_CONTEXT_ALIAS, new UmbCurrentUserStore());
this.provideContext('umbDocumentStore', new UmbDocumentStore(this));
this.provideContext('umbMediaStore', new UmbMediaStore(this));
this.provideContext('umbDataTypeStore', new UmbDataTypeStore(this));

View File

@@ -1,7 +1,7 @@
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
import { css, CSSResultGroup, html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { UmbCurrentUserStore } from './current-user.store';
import { UmbCurrentUserStore, UMB_CURRENT_USER_STORE_CONTEXT_ALIAS } from './current-user.store';
import type { UserDetails } from '@umbraco-cms/models';
import { UmbModalService, UMB_MODAL_SERVICE_CONTEXT_ALIAS } from 'src/core/modal';
import { UmbLitElement } from '@umbraco-cms/element';
@@ -30,7 +30,7 @@ export class UmbCurrentUserHeaderApp extends UmbLitElement {
this._modalService = _instance;
});
this.consumeContext<UmbCurrentUserStore>('umbCurrentUserStore', (_instance) => {
this.consumeContext(UMB_CURRENT_USER_STORE_CONTEXT_ALIAS, (_instance) => {
this._currentUserStore = _instance;
this._observeCurrentUser();
});

View File

@@ -2,6 +2,7 @@ import { BehaviorSubject, Observable } from 'rxjs';
import { umbUsersData } from '../../../core/mocks/data/users.data';
import type { UserDetails } from '@umbraco-cms/models';
import { umbracoPath } from '@umbraco-cms/utils';
import { UmbContextAlias } from '@umbraco-cms/context-api';
export class UmbCurrentUserStore {
private _currentUser = new BehaviorSubject<UserDetails>(umbUsersData.getAll()[0]); //TODO: Temp solution to set the first user as the current logged in user
@@ -26,3 +27,5 @@ export class UmbCurrentUserStore {
return this._currentUser.getValue()?.userGroups.includes(adminUserGroupKey);
}
}
export const UMB_CURRENT_USER_STORE_CONTEXT_ALIAS = new UmbContextAlias<UmbCurrentUserStore>(UmbCurrentUserStore.name);

View File

@@ -8,7 +8,7 @@ import { repeat } from 'lit/directives/repeat.js';
import { distinctUntilChanged } from 'rxjs';
import { getTagLookAndColor } from '../../../../auth/utils';
import { UmbCurrentUserStore } from '../../current-user/current-user.store';
import { UmbCurrentUserStore, UMB_CURRENT_USER_STORE_CONTEXT_ALIAS } from '../../current-user/current-user.store';
import { UmbWorkspaceUserContext } from './user-workspace.context';
import type { UserDetails } from '@umbraco-cms/models';
@@ -117,7 +117,7 @@ export class UmbUserWorkspaceElement extends UmbLitElement implements UmbWorkspa
constructor() {
super();
this.consumeContext('umbCurrentUserStore', (store) => {
this.consumeContext(UMB_CURRENT_USER_STORE_CONTEXT_ALIAS, (store) => {
this._currentUserStore = store;
this._observeCurrentUser();
});

View File

@@ -7,7 +7,10 @@ import {
UmbCurrentUserHistoryStore,
UmbCurrentUserHistoryItem,
} from 'src/backoffice/users/current-user/current-user-history.store';
import { UmbCurrentUserStore } from 'src/backoffice/users/current-user/current-user.store';
import {
UmbCurrentUserStore,
UMB_CURRENT_USER_STORE_CONTEXT_ALIAS,
} from 'src/backoffice/users/current-user/current-user.store';
import { UmbLitElement } from '@umbraco-cms/element';
@customElement('umb-modal-layout-current-user')
@@ -94,7 +97,7 @@ export class UmbModalLayoutCurrentUserElement extends UmbLitElement {
this._modalService = _instance;
});
this.consumeContext<UmbCurrentUserStore>('umbCurrentUserStore', (_instance) => {
this.consumeContext(UMB_CURRENT_USER_STORE_CONTEXT_ALIAS, (_instance) => {
this._currentUserStore = _instance;
this._observeCurrentUser();
});