From b7d58ce75d0b289c5222256488b5fc3f18564d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 26 Jul 2023 15:30:47 +0200 Subject: [PATCH] implement for dashboards --- .../.github/CONTRIBUTING.md | 9 ++- .../controller/base-extensions-controller.ts | 15 ++--- .../extensions-manifest-controller.ts | 9 ++- .../extension-slot/extension-slot.test.ts | 9 ++- .../models/dashboard.model.ts | 18 ++---- .../core/section/section-default.element.ts | 3 +- .../section-views/section-views.element.ts | 12 +++- .../packages/dictionary/section.manifest.ts | 9 ++- .../documents/dashboards/manifests.ts | 9 ++- .../src/packages/members/section.manifests.ts | 9 ++- .../src/packages/search/manifests.ts | 9 ++- .../packages/settings/dashboards/manifests.ts | 56 +++++++++++++------ .../src/packages/umbraco-news/manifests.ts | 9 ++- 13 files changed, 109 insertions(+), 67 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/.github/CONTRIBUTING.md b/src/Umbraco.Web.UI.Client/.github/CONTRIBUTING.md index b870ebf151..ebc40f9fef 100644 --- a/src/Umbraco.Web.UI.Client/.github/CONTRIBUTING.md +++ b/src/Umbraco.Web.UI.Client/.github/CONTRIBUTING.md @@ -122,9 +122,12 @@ To declare the Published Cache Status Dashboard as a new manifest, we need to ad label: 'Published Status', pathname: 'published-status', }, - conditions: { - sections: ['Umb.Section.Settings'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: 'Umb.Section.Settings', + }, + ], }, ``` diff --git a/src/Umbraco.Web.UI.Client/src/libs/extension-api/controller/base-extensions-controller.ts b/src/Umbraco.Web.UI.Client/src/libs/extension-api/controller/base-extensions-controller.ts index 7fea027cfe..45f36ef3cf 100644 --- a/src/Umbraco.Web.UI.Client/src/libs/extension-api/controller/base-extensions-controller.ts +++ b/src/Umbraco.Web.UI.Client/src/libs/extension-api/controller/base-extensions-controller.ts @@ -13,11 +13,12 @@ import { UmbBaseController, UmbControllerHost } from '@umbraco-cms/backoffice/co export abstract class UmbBaseExtensionsController< ManifestTypeName extends keyof ManifestTypeMap | string, ManifestType extends ManifestBase = SpecificManifestTypeOrManifestBase, - ControllerType extends UmbBaseExtensionController = UmbBaseExtensionController + ControllerType extends UmbBaseExtensionController = UmbBaseExtensionController, + PermittedControllerType extends ControllerType = ControllerType > extends UmbBaseController { - #onChange: (permittedManifests: Array, controller: ControllerType) => void; + #onChange: (permittedManifests: Array, controller: PermittedControllerType) => void; private _extensions: Array = []; - private _permittedExts: Array = []; + private _permittedExts: Array = []; get permittedExtensions(): Array { return this._permittedExts; @@ -27,7 +28,7 @@ export abstract class UmbBaseExtensionsController< host: UmbControllerHost, type: ManifestTypeName, filter: null | ((manifest: ManifestType) => boolean), - onChange: (permittedManifests: Array, controller: ControllerType) => void + onChange: (permittedManifests: Array, controller: PermittedControllerType) => void ) { super(host); this.#onChange = onChange; @@ -80,10 +81,10 @@ export abstract class UmbBaseExtensionsController< protected _extensionChanged = (isPermitted: boolean, controller: ControllerType) => { let hasChanged = false; - const existingIndex = this._permittedExts.indexOf(controller); + const existingIndex = this._permittedExts.indexOf(controller as PermittedControllerType); if (isPermitted) { if (existingIndex === -1) { - this._permittedExts.push(controller); + this._permittedExts.push(controller as PermittedControllerType); hasChanged = true; } } else { @@ -95,7 +96,7 @@ export abstract class UmbBaseExtensionsController< if (hasChanged) { //this._permittedExts = this._permittedExts.filter((a) => a.permitted); this._permittedExts.sort((a, b) => b.weight - a.weight); - this.#onChange(this._permittedExts, this as unknown as ControllerType); + this.#onChange(this._permittedExts, this as unknown as PermittedControllerType); // Idea: could be abstracted into a requestChange method, so we can override it in a subclass. } }; diff --git a/src/Umbraco.Web.UI.Client/src/libs/extension-api/controller/extensions-manifest-controller.ts b/src/Umbraco.Web.UI.Client/src/libs/extension-api/controller/extensions-manifest-controller.ts index 505386768e..0353391c27 100644 --- a/src/Umbraco.Web.UI.Client/src/libs/extension-api/controller/extensions-manifest-controller.ts +++ b/src/Umbraco.Web.UI.Client/src/libs/extension-api/controller/extensions-manifest-controller.ts @@ -13,13 +13,16 @@ import { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; export class UmbExtensionsManifestController< ManifestTypeName extends keyof ManifestTypeMap | string, ManifestType extends ManifestBase = SpecificManifestTypeOrManifestBase, - ControllerType extends UmbExtensionManifestController = UmbExtensionManifestController -> extends UmbBaseExtensionsController { + ControllerType extends UmbExtensionManifestController = UmbExtensionManifestController, + PermittedControllerType extends ControllerType = ControllerType & { + manifest: Required>; + } +> extends UmbBaseExtensionsController { constructor( host: UmbControllerHost, type: ManifestTypeName, filter: null | ((manifest: ManifestType) => boolean), - onChange: (permittedManifests: Array, controller: ControllerType) => void + onChange: (permittedManifests: Array, controller: PermittedControllerType) => void ) { super(host, type, filter, onChange); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/components/extension-slot/extension-slot.test.ts b/src/Umbraco.Web.UI.Client/src/packages/core/components/extension-slot/extension-slot.test.ts index 45d97f6ce9..a881a81a62 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/components/extension-slot/extension-slot.test.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/components/extension-slot/extension-slot.test.ts @@ -54,9 +54,12 @@ describe('UmbExtensionSlotElement', () => { meta: { pathname: 'test/test', }, - conditions: { - sections: ['test'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: 'test', + }, + ], }); }); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/extension-registry/models/dashboard.model.ts b/src/Umbraco.Web.UI.Client/src/packages/core/extension-registry/models/dashboard.model.ts index f28ae9d63d..d67e3aa562 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/extension-registry/models/dashboard.model.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/extension-registry/models/dashboard.model.ts @@ -1,9 +1,10 @@ +import { ConditionTypes } from '../conditions/types.js'; import type { UmbDashboardExtensionElement } from '../interfaces/index.js'; -import type { ManifestElement, ManifestWithConditions } from '@umbraco-cms/backoffice/extension-api'; +import type { ManifestElement, ManifestWithDynamicConditions } from '@umbraco-cms/backoffice/extension-api'; export interface ManifestDashboard extends ManifestElement, - ManifestWithConditions { + ManifestWithDynamicConditions { type: 'dashboard'; meta: MetaDashboard; } @@ -26,17 +27,8 @@ export interface MetaDashboard { pathname?: string; } +/* export interface ConditionsDashboard { - /** - * An array of section aliases that the dashboard should be available in - * - * @uniqueItems true - * @minItems 1 - * @items.examples [ - * "Umb.Section.Content", - * "Umb.Section.Settings" - * ] - * - */ sections: string[]; } +*/ diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/section/section-default.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/section/section-default.element.ts index 8b68acb58f..36123bfeea 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/section/section-default.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/section/section-default.element.ts @@ -20,7 +20,6 @@ import { UmbExtensionElementController, UmbExtensionsElementController } from '@ @customElement('umb-section-default') export class UmbSectionDefaultElement extends UmbLitElement implements UmbSectionExtensionElement { private _manifest?: ManifestSection | undefined; - private _extensionController?: UmbExtensionsElementController<'sectionSidebarApp'>; @property({ type: Object, attribute: false }) public get manifest(): ManifestSection | undefined { @@ -45,7 +44,7 @@ export class UmbSectionDefaultElement extends UmbLitElement implements UmbSectio constructor() { super(); - this._extensionController = new UmbExtensionsElementController(this, 'sectionSidebarApp', null, (sidebarApps) => { + new UmbExtensionsElementController(this, 'sectionSidebarApp', null, (sidebarApps) => { this._sidebarApps = sidebarApps; this.requestUpdate('_sidebarApps'); }); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/section/section-views/section-views.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/section/section-views/section-views.element.ts index 4760c5047b..285e8d5b4d 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/section/section-views/section-views.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/section/section-views/section-views.element.ts @@ -10,7 +10,7 @@ import { UmbSectionViewExtensionElement, umbExtensionsRegistry, } from '@umbraco-cms/backoffice/extension-registry'; -import { createExtensionElement } from '@umbraco-cms/backoffice/extension-api'; +import { UmbExtensionsManifestController, createExtensionElement } from '@umbraco-cms/backoffice/extension-api'; import { UmbLitElement } from '@umbraco-cms/internal/lit-element'; import { UmbObserverController } from '@umbraco-cms/backoffice/observable-api'; import { pathFolderName } from '@umbraco-cms/backoffice/utils'; @@ -37,9 +37,9 @@ export class UmbSectionViewsElement extends UmbLitElement { private _routes: Array = []; private _sectionContext?: UmbSectionContext; - private _extensionsObserver?: UmbObserverController; + private _viewsObserver?: UmbObserverController; - private _dashboardObserver?: UmbObserverController; + private _dashboardObserver?: UmbExtensionsManifestController; constructor() { super(); @@ -117,6 +117,11 @@ export class UmbSectionViewsElement extends UmbLitElement { this._dashboardObserver?.destroy(); if (sectionAlias) { + this._dashboardObserver = new UmbExtensionsManifestController(this, 'dashboard', null, (views) => { + this._dashboards = views.map((view) => view.manifest); + this.#createRoutes(); + }); + /* this._dashboardObserver = this.observe( umbExtensionsRegistry ?.extensionsOfType('dashboard') @@ -126,6 +131,7 @@ export class UmbSectionViewsElement extends UmbLitElement { this.#createRoutes(); } ); + */ } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/section.manifest.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/section.manifest.ts index e6032870d7..81b4ea2a8c 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/section.manifest.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/section.manifest.ts @@ -42,9 +42,12 @@ const dashboards: Array = [ label: 'Dictionary overview', pathname: '', }, - conditions: { - sections: [sectionAlias], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: sectionAlias, + }, + ], }, ]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/dashboards/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/dashboards/manifests.ts index 64883e956f..1a4b46c347 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/dashboards/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/dashboards/manifests.ts @@ -11,9 +11,12 @@ const dashboards: Array = [ label: 'Redirect Management', pathname: 'redirect-management', }, - conditions: { - sections: ['Umb.Section.Content'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: 'Umb.Section.Content', + }, + ], }, ]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/members/section.manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/members/section.manifests.ts index eec90807c1..1ad8476658 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/members/section.manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/members/section.manifests.ts @@ -24,9 +24,12 @@ const dashboards: Array = [ label: 'Members', pathname: 'members', }, - conditions: { - sections: [sectionAlias], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: sectionAlias, + }, + ], }, ]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/search/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/search/manifests.ts index eb5d196e7d..0a9f1dfa4c 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/search/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/search/manifests.ts @@ -30,9 +30,12 @@ export const manifests: Array = [ label: 'Examine Management', pathname: 'examine-management', }, - conditions: { - sections: ['Umb.Section.Settings'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: 'Umb.Section.Settings', + }, + ], }, { type: 'headerApp', diff --git a/src/Umbraco.Web.UI.Client/src/packages/settings/dashboards/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/settings/dashboards/manifests.ts index bf2e1ebf30..a97e05e79d 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/settings/dashboards/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/settings/dashboards/manifests.ts @@ -1,5 +1,7 @@ import type { ManifestDashboard } from '@umbraco-cms/backoffice/extension-registry'; +const sectionAlias = 'Umb.Section.Settings'; + const dashboards: Array = [ { type: 'dashboard', @@ -12,9 +14,12 @@ const dashboards: Array = [ label: 'Welcome', pathname: 'welcome', }, - conditions: { - sections: ['Umb.Section.Settings'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: sectionAlias, + }, + ], }, { type: 'dashboard', @@ -27,9 +32,12 @@ const dashboards: Array = [ label: 'Models Builder', pathname: 'models-builder', }, - conditions: { - sections: ['Umb.Section.Settings'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: sectionAlias, + }, + ], }, { type: 'dashboard', @@ -42,9 +50,12 @@ const dashboards: Array = [ label: 'Published Status', pathname: 'published-status', }, - conditions: { - sections: ['Umb.Section.Settings'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: sectionAlias, + }, + ], }, { type: 'dashboard', @@ -57,9 +68,12 @@ const dashboards: Array = [ label: 'Health Check', pathname: 'health-check', }, - conditions: { - sections: ['Umb.Section.Settings'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: sectionAlias, + }, + ], }, { type: 'dashboard', @@ -72,9 +86,12 @@ const dashboards: Array = [ label: 'Profiling', pathname: 'profiling', }, - conditions: { - sections: ['Umb.Section.Settings'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: sectionAlias, + }, + ], }, { type: 'dashboard', @@ -87,9 +104,12 @@ const dashboards: Array = [ label: 'Telemetry Data', pathname: 'telemetry', }, - conditions: { - sections: ['Umb.Section.Settings'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: sectionAlias, + }, + ], }, ]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/umbraco-news/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/umbraco-news/manifests.ts index 457f444356..079cf078d5 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/umbraco-news/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/umbraco-news/manifests.ts @@ -9,7 +9,10 @@ export const dashboard: ManifestDashboard = { meta: { label: 'Welcome', }, - conditions: { - sections: ['Umb.Section.Content'], - }, + conditions: [ + { + alias: 'Umb.Condition.SectionAlias', + match: 'Umb.Section.Content', + }, + ], };