From 92c7ec950ab8b6be3623561b34a085a98971efa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 19 Mar 2024 09:04:59 +0100 Subject: [PATCH 1/4] transferred forgotten improvements --- src/Umbraco.Web.UI.Client/src/apps/app/app.context.ts | 7 +++---- .../src/packages/core/auth/auth.context.ts | 7 +++---- .../section/section-sidebar/section-sidebar.context.ts | 6 +++--- .../section/section-sidebar/section-sidebar.element.ts | 7 +------ .../src/packages/core/themes/theme.context.ts | 8 +++----- .../workspace-split-view/workspace-split-view.context.ts | 8 +++----- .../invariant-workspace-property-dataset-context.ts | 9 +++------ .../document-property-dataset-context.token.ts | 6 +++--- 8 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/apps/app/app.context.ts b/src/Umbraco.Web.UI.Client/src/apps/app/app.context.ts index 17d0c4c997..39a248c8f5 100644 --- a/src/Umbraco.Web.UI.Client/src/apps/app/app.context.ts +++ b/src/Umbraco.Web.UI.Client/src/apps/app/app.context.ts @@ -1,17 +1,16 @@ import type { UmbAppContextConfig } from './app-context-config.interface.js'; -import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; +import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; -export class UmbAppContext extends UmbControllerBase { +export class UmbAppContext extends UmbContextBase { #serverUrl: string; #backofficePath: string; constructor(host: UmbControllerHost, config: UmbAppContextConfig) { - super(host); + super(host, UMB_APP_CONTEXT); this.#serverUrl = config.serverUrl; this.#backofficePath = config.backofficePath; - this.provideContext(UMB_APP_CONTEXT, this); } getBackofficePath() { diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts index 87e1ec1a74..f457655b18 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/auth/auth.context.ts @@ -3,10 +3,10 @@ import { UMB_AUTH_CONTEXT } from './auth.context.token.js'; import type { UmbOpenApiConfiguration } from './models/openApiConfiguration.js'; import { OpenAPI } from '@umbraco-cms/backoffice/external/backend-api'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; -import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; +import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'; import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api'; -export class UmbAuthContext extends UmbControllerBase { +export class UmbAuthContext extends UmbContextBase { #isAuthorized = new UmbBooleanState(false); readonly isAuthorized = this.#isAuthorized.asObservable(); @@ -16,13 +16,12 @@ export class UmbAuthContext extends UmbControllerBase { #authFlow; constructor(host: UmbControllerHost, serverUrl: string, backofficePath: string, isBypassed: boolean) { - super(host); + super(host, UMB_AUTH_CONTEXT); this.#isBypassed = isBypassed; this.#serverUrl = serverUrl; this.#backofficePath = backofficePath; this.#authFlow = new UmbAuthFlow(serverUrl, this.#getRedirectUrl()); - this.provideContext(UMB_AUTH_CONTEXT, this); } /** diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/section/section-sidebar/section-sidebar.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/section/section-sidebar/section-sidebar.context.ts index 8307b54c52..839d76ae90 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/section/section-sidebar/section-sidebar.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/section/section-sidebar/section-sidebar.context.ts @@ -1,9 +1,9 @@ import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; +import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import { UmbStringState, UmbBooleanState } from '@umbraco-cms/backoffice/observable-api'; -export class UmbSectionSidebarContext { - #host: UmbControllerHost; +export class UmbSectionSidebarContext extends UmbContextBase { #contextMenuIsOpen = new UmbBooleanState(false); contextMenuIsOpen = this.#contextMenuIsOpen.asObservable(); @@ -17,7 +17,7 @@ export class UmbSectionSidebarContext { headline = this.#headline.asObservable(); constructor(host: UmbControllerHost) { - this.#host = host; + super(host, UMB_SECTION_SIDEBAR_CONTEXT); } toggleContextMenu(entityType: string, unique: string | null | undefined, headline: string | undefined) { diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/section/section-sidebar/section-sidebar.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/section/section-sidebar/section-sidebar.element.ts index 7db7ba90d7..65da98a094 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/section/section-sidebar/section-sidebar.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/section/section-sidebar/section-sidebar.element.ts @@ -1,4 +1,4 @@ -import { UmbSectionSidebarContext, UMB_SECTION_SIDEBAR_CONTEXT } from './section-sidebar.context.js'; +import { UmbSectionSidebarContext } from './section-sidebar.context.js'; import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import { css, html, customElement } from '@umbraco-cms/backoffice/external/lit'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; @@ -7,11 +7,6 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; export class UmbSectionSidebarElement extends UmbLitElement { #sectionSidebarContext = new UmbSectionSidebarContext(this); - constructor() { - super(); - this.provideContext(UMB_SECTION_SIDEBAR_CONTEXT, this.#sectionSidebarContext); - } - render() { return html` diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/themes/theme.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/themes/theme.context.ts index 5ec021db65..f411529ebb 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/themes/theme.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/themes/theme.context.ts @@ -3,14 +3,14 @@ import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; import type { UmbObserverController } from '@umbraco-cms/backoffice/observable-api'; import { UmbStringState } from '@umbraco-cms/backoffice/observable-api'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; -import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; +import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'; import type { ManifestTheme } from '@umbraco-cms/backoffice/extension-registry'; import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'; import { loadManifestPlainCss } from '@umbraco-cms/backoffice/extension-api'; const LOCAL_STORAGE_KEY = 'umb-theme-alias'; -export class UmbThemeContext extends UmbControllerBase { +export class UmbThemeContext extends UmbContextBase { #theme = new UmbStringState('umb-light-theme'); #themeObserver?: UmbObserverController; @@ -19,9 +19,7 @@ export class UmbThemeContext extends UmbControllerBase { #styleElement: HTMLLinkElement | HTMLStyleElement | null = null; constructor(host: UmbControllerHost) { - super(host); - - this.provideContext(UMB_THEME_CONTEXT, this); + super(host, UMB_THEME_CONTEXT); const storedTheme = localStorage.getItem(LOCAL_STORAGE_KEY); if (storedTheme) { diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-split-view/workspace-split-view.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-split-view/workspace-split-view.context.ts index 07c73692f4..3039616715 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-split-view/workspace-split-view.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-split-view/workspace-split-view.context.ts @@ -2,11 +2,11 @@ import { UMB_VARIANT_WORKSPACE_CONTEXT } from '../../workspace-context/index.js' import { UmbVariantId } from '@umbraco-cms/backoffice/variant'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; -import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; +import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'; import { UmbNumberState } from '@umbraco-cms/backoffice/observable-api'; import type { UmbPropertyDatasetContext } from '@umbraco-cms/backoffice/property'; -export class UmbWorkspaceSplitViewContext extends UmbControllerBase { +export class UmbWorkspaceSplitViewContext extends UmbContextBase { #workspaceContext?: typeof UMB_VARIANT_WORKSPACE_CONTEXT.TYPE; public getWorkspaceContext() { return this.#workspaceContext; @@ -21,7 +21,7 @@ export class UmbWorkspaceSplitViewContext extends UmbControllerBase { //variantId = this.#variantId.asObservable(); constructor(host: UmbControllerHost) { - super(host); + super(host, UMB_WORKSPACE_SPLIT_VIEW_CONTEXT); this.consumeContext(UMB_VARIANT_WORKSPACE_CONTEXT, (context) => { this.#workspaceContext = context; @@ -31,8 +31,6 @@ export class UmbWorkspaceSplitViewContext extends UmbControllerBase { this.observe(this.index, () => { this._observeVariant(); }); - - this.provideContext(UMB_WORKSPACE_SPLIT_VIEW_CONTEXT, this); } private _observeVariant() { diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace-property-dataset/invariant-workspace-property-dataset-context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace-property-dataset/invariant-workspace-property-dataset-context.ts index 9f1997eda5..44ca0b1bc4 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace-property-dataset/invariant-workspace-property-dataset-context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace-property-dataset/invariant-workspace-property-dataset-context.ts @@ -1,7 +1,7 @@ import type { UmbPropertyDatasetContext, UmbNameablePropertyDatasetContext } from '@umbraco-cms/backoffice/property'; import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; -import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; +import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'; import { UmbVariantId } from '@umbraco-cms/backoffice/variant'; import type { UmbInvariantableWorkspaceContextInterface } from '@umbraco-cms/backoffice/workspace'; @@ -11,7 +11,7 @@ import type { UmbInvariantableWorkspaceContextInterface } from '@umbraco-cms/bac export class UmbInvariantWorkspacePropertyDatasetContext< WorkspaceType extends UmbInvariantableWorkspaceContextInterface = UmbInvariantableWorkspaceContextInterface, > - extends UmbControllerBase + extends UmbContextBase implements UmbPropertyDatasetContext, UmbNameablePropertyDatasetContext { #workspace: WorkspaceType; @@ -37,13 +37,10 @@ export class UmbInvariantWorkspacePropertyDatasetContext< } constructor(host: UmbControllerHost, workspace: WorkspaceType) { - // The controller alias, is a very generic name cause we want only one of these for this controller host. - super(host, 'variantContext'); + super(host, UMB_PROPERTY_DATASET_CONTEXT); this.#workspace = workspace; this.name = this.#workspace.name; - - this.provideContext(UMB_PROPERTY_DATASET_CONTEXT, this); } /** diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/property-dataset-context/document-property-dataset-context.token.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/property-dataset-context/document-property-dataset-context.token.ts index 1c4fa693e5..62cd946c83 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/property-dataset-context/document-property-dataset-context.token.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/property-dataset-context/document-property-dataset-context.token.ts @@ -3,11 +3,11 @@ import type { UmbDocumentPropertyDataContext } from './document-property-dataset import type { UmbPropertyDatasetContext } from '@umbraco-cms/backoffice/property'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; -export const IsDocumentVariantContext = ( +export const IsDocumentPropertyDatasetContext = ( context: UmbPropertyDatasetContext, ): context is UmbDocumentPropertyDataContext => context.getEntityType() === UMB_DOCUMENT_ENTITY_TYPE; -export const UMB_DOCUMENT_VARIANT_CONTEXT = new UmbContextToken< +export const UMB_DOCUMENT_PROPERTY_DATASET_CONTEXT = new UmbContextToken< UmbPropertyDatasetContext, UmbDocumentPropertyDataContext ->('UmbVariantContext', undefined, IsDocumentVariantContext); +>('UmbVariantContext', undefined, IsDocumentPropertyDatasetContext); From ef63b28cd7f9864c439ce37394f29a4fd598c8ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 19 Mar 2024 09:06:26 +0100 Subject: [PATCH 2/4] UmbRouteContext --- .../src/packages/core/router/route.context.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/router/route.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/router/route.context.ts index d7f41278b7..274adb3729 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/router/route.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/router/route.context.ts @@ -3,14 +3,14 @@ import { createRoutePathBuilder } from './generate-route-path-builder.function.j import type { IRoutingInfo, IRouterSlot } from '@umbraco-cms/backoffice/external/router-slot'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; -import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; +import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'; import { UMB_MODAL_MANAGER_CONTEXT, type UmbModalRouteRegistration } from '@umbraco-cms/backoffice/modal'; const EmptyDiv = document.createElement('div'); type UmbRoutePlusModalKey = UmbRoute & { __modalKey: string }; -export class UmbRouteContext extends UmbControllerBase { +export class UmbRouteContext extends UmbContextBase { #mainRouter: IRouterSlot; #modalRouter: IRouterSlot; #modalRegistrations: UmbModalRouteRegistration[] = []; @@ -21,10 +21,9 @@ export class UmbRouteContext extends UmbControllerBase { #activeModalPath?: string; constructor(host: UmbControllerHost, mainRouter: IRouterSlot, modalRouter: IRouterSlot) { - super(host); + super(host, UMB_ROUTE_CONTEXT); this.#mainRouter = mainRouter; this.#modalRouter = modalRouter; - this.provideContext(UMB_ROUTE_CONTEXT, this); this.consumeContext(UMB_MODAL_MANAGER_CONTEXT, (context) => { this.#modalContext = context; this.#generateModalRoutes(); From 7b900936c6ab808bbbe6f9eb3eb2ac50e986fc0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 19 Mar 2024 09:11:01 +0100 Subject: [PATCH 3/4] UmbAppLanguageContext --- .../language/global-contexts/app-language.context.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/language/global-contexts/app-language.context.ts b/src/Umbraco.Web.UI.Client/src/packages/language/global-contexts/app-language.context.ts index 02773e67b5..ca0cc109a1 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/language/global-contexts/app-language.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/language/global-contexts/app-language.context.ts @@ -2,11 +2,11 @@ import { UmbLanguageCollectionRepository } from '../collection/index.js'; import type { UmbLanguageDetailModel } from '../types.js'; import { UmbArrayState, UmbObjectState, createObservablePart } from '@umbraco-cms/backoffice/observable-api'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; -import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api'; +import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; import type { UmbApi } from '@umbraco-cms/backoffice/extension-api'; -export class UmbAppLanguageContext extends UmbControllerBase implements UmbApi { +export class UmbAppLanguageContext extends UmbContextBase implements UmbApi { #languageCollectionRepository: UmbLanguageCollectionRepository; #languages = new UmbArrayState([], (x) => x.unique); @@ -24,8 +24,7 @@ export class UmbAppLanguageContext extends UmbControllerBase implements UmbApi { } constructor(host: UmbControllerHost) { - super(host); - this.provideContext(UMB_APP_LANGUAGE_CONTEXT, this); + super(host, UMB_APP_LANGUAGE_CONTEXT); this.#languageCollectionRepository = new UmbLanguageCollectionRepository(this); this.#observeLanguages(); } From f06639351b34417586de1df1b258692097b7535b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 19 Mar 2024 09:37:37 +0100 Subject: [PATCH 4/4] notes for server variables and app language --- .../global-contexts/document-configuration.context.ts | 5 +++++ .../language/global-contexts/app-language.context.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/global-contexts/document-configuration.context.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/global-contexts/document-configuration.context.ts index 3cb6897a37..c7d28e8905 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/global-contexts/document-configuration.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/global-contexts/document-configuration.context.ts @@ -8,8 +8,10 @@ import { } from '@umbraco-cms/backoffice/external/backend-api'; import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources'; +// TODO: Turn this into a Repository with a Store that holds the cache [NL] /** * A context for fetching and caching the document configuration. + * @deprecated Do not use this one, it will have ot change in near future. */ export class UmbDocumentConfigurationContext extends UmbControllerBase implements UmbApi { /** @@ -44,6 +46,9 @@ export class UmbDocumentConfigurationContext extends UmbControllerBase implement // Export as default to work as a global context: export default UmbDocumentConfigurationContext; +/** + * @deprecated Do not use this one, it will have ot change in near future. + */ export const UMB_DOCUMENT_CONFIGURATION_CONTEXT = new UmbContextToken( 'UmbDocumentConfigurationContext', ); diff --git a/src/Umbraco.Web.UI.Client/src/packages/language/global-contexts/app-language.context.ts b/src/Umbraco.Web.UI.Client/src/packages/language/global-contexts/app-language.context.ts index ca0cc109a1..8d4b2af962 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/language/global-contexts/app-language.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/language/global-contexts/app-language.context.ts @@ -6,6 +6,8 @@ import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; import type { UmbApi } from '@umbraco-cms/backoffice/extension-api'; +// TODO: Make a store for the App Languages. +// TODO: Implement default language end-point, in progress at backend team, so we can avoid getting all languages. export class UmbAppLanguageContext extends UmbContextBase implements UmbApi { #languageCollectionRepository: UmbLanguageCollectionRepository; #languages = new UmbArrayState([], (x) => x.unique);