From 3c2187b3f63f4039a40b4d064bab8feb31c5c43c Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 11 Oct 2022 10:14:03 +0200 Subject: [PATCH 1/7] move weight property in schema --- src/Umbraco.Web.UI.Client/schemas/api/api.yml | 53 ++++++++++++------- .../schemas/generated-schema.ts | 32 +++++++---- .../temp-schema-generator/manifests.ts | 6 +-- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/schemas/api/api.yml b/src/Umbraco.Web.UI.Client/schemas/api/api.yml index 6aa6d277f7..d85ac0e35a 100644 --- a/src/Umbraco.Web.UI.Client/schemas/api/api.yml +++ b/src/Umbraco.Web.UI.Client/schemas/api/api.yml @@ -566,13 +566,9 @@ components: type: string pathname: type: string - weight: - type: number - format: float required: - label - pathname - - weight IManifestSection: type: object properties: @@ -590,6 +586,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - meta @@ -598,15 +597,11 @@ components: MetaTree: type: object properties: - weight: - type: number - format: float sections: type: array items: type: string required: - - weight - sections IManifestTree: type: object @@ -625,6 +620,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - meta @@ -654,6 +652,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - meta @@ -670,14 +671,10 @@ components: type: string icon: type: string - weight: - type: number - format: float required: - trees - label - icon - - weight IManifestTreeItemAction: type: object properties: @@ -695,6 +692,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - meta @@ -792,6 +792,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - meta @@ -806,15 +809,11 @@ components: type: string pathname: type: string - weight: - type: number - format: float label: type: string required: - sections - pathname - - weight IManifestDashboard: type: object properties: @@ -832,6 +831,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - meta @@ -846,9 +848,6 @@ components: type: string pathname: type: string - weight: - type: number - format: float label: type: string icon: @@ -856,7 +855,6 @@ components: required: - editors - pathname - - weight - label - icon IManifestEditorView: @@ -876,6 +874,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - meta @@ -907,6 +908,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - meta @@ -936,6 +940,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - meta @@ -954,6 +961,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - js @@ -972,6 +982,9 @@ components: type: string name: type: string + weight: + type: number + format: float required: - type - alias diff --git a/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts b/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts index 3216149c08..15e62a1eb1 100644 --- a/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts +++ b/src/Umbraco.Web.UI.Client/schemas/generated-schema.ts @@ -142,8 +142,6 @@ export interface components { MetaSection: { label: string; pathname: string; - /** Format: float */ - weight: number; }; IManifestSection: { /** @enum {string} */ @@ -153,10 +151,10 @@ export interface components { elementName?: string; alias: string; name: string; + /** Format: float */ + weight?: number; }; MetaTree: { - /** Format: float */ - weight: number; sections: string[]; }; IManifestTree: { @@ -167,6 +165,8 @@ export interface components { elementName?: string; alias: string; name: string; + /** Format: float */ + weight?: number; }; MetaEditor: { entityType: string; @@ -179,13 +179,13 @@ export interface components { elementName?: string; alias: string; name: string; + /** Format: float */ + weight?: number; }; MetaTreeItemAction: { trees: string[]; label: string; icon: string; - /** Format: float */ - weight: number; }; IManifestTreeItemAction: { /** @enum {string} */ @@ -195,6 +195,8 @@ export interface components { elementName?: string; alias: string; name: string; + /** Format: float */ + weight?: number; }; PropertyEditorConfigProperty: { label: string; @@ -236,12 +238,12 @@ export interface components { elementName?: string; alias: string; name: string; + /** Format: float */ + weight?: number; }; MetaDashboard: { sections: string[]; pathname: string; - /** Format: float */ - weight: number; label?: string; }; IManifestDashboard: { @@ -252,12 +254,12 @@ export interface components { elementName?: string; alias: string; name: string; + /** Format: float */ + weight?: number; }; MetaEditorView: { editors: string[]; pathname: string; - /** Format: float */ - weight: number; label: string; icon: string; }; @@ -269,6 +271,8 @@ export interface components { elementName?: string; alias: string; name: string; + /** Format: float */ + weight?: number; }; MetaPropertyAction: { propertyEditors: string[]; @@ -281,6 +285,8 @@ export interface components { elementName?: string; alias: string; name: string; + /** Format: float */ + weight?: number; }; MetaPackageView: { packageAlias: string; @@ -293,6 +299,8 @@ export interface components { elementName?: string; alias: string; name: string; + /** Format: float */ + weight?: number; }; IManifestEntrypoint: { /** @enum {string} */ @@ -300,6 +308,8 @@ export interface components { js: string; alias: string; name: string; + /** Format: float */ + weight?: number; }; IManifestCustom: { /** @enum {string} */ @@ -307,6 +317,8 @@ export interface components { meta?: { [key: string]: unknown }; alias: string; name: string; + /** Format: float */ + weight?: number; }; Manifest: | components["schemas"]["IManifestSection"] diff --git a/src/Umbraco.Web.UI.Client/temp-schema-generator/manifests.ts b/src/Umbraco.Web.UI.Client/temp-schema-generator/manifests.ts index 8ec67f328e..4f2ad8ff95 100644 --- a/src/Umbraco.Web.UI.Client/temp-schema-generator/manifests.ts +++ b/src/Umbraco.Web.UI.Client/temp-schema-generator/manifests.ts @@ -77,16 +77,15 @@ export interface IManifest { type: string; alias: string; name: string; + weight?: number; } export interface MetaSection { label: string; pathname: string; - weight: number; } export interface MetaTree { - weight: number; sections: Array; } @@ -98,7 +97,6 @@ export interface MetaTreeItemAction { trees: Array; label: string; icon: string; - weight: number; } export interface MetaPropertyEditorUI { label: string; @@ -111,14 +109,12 @@ export interface MetaPropertyEditorUI { export interface MetaDashboard { sections: string[]; pathname: string; - weight: number; label?: string; } export interface MetaEditorView { editors: string[]; pathname: string; - weight: number; label: string; icon: string; } From 337e4dee970fc6dc48c2df32615ae2ed56e28fb0 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 11 Oct 2022 10:14:49 +0200 Subject: [PATCH 2/7] move weight property in manifests --- .../backoffice/sections/section.context.ts | 2 +- .../src/mocks/domains/manifests.handlers.ts | 2 +- .../src/temp-internal-manifests/index.ts | 67 +++++++++---------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/sections/section.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/sections/section.context.ts index 63eb9a4725..f32c45180d 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/sections/section.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/sections/section.context.ts @@ -11,10 +11,10 @@ export class UmbSectionContext { name: '', js: '', elementName: '', + weight: 0, meta: { label: '', pathname: '', - weight: 0, }, }); public readonly data = this._data.asObservable(); diff --git a/src/Umbraco.Web.UI.Client/src/mocks/domains/manifests.handlers.ts b/src/Umbraco.Web.UI.Client/src/mocks/domains/manifests.handlers.ts index 13bb1d17d1..53025cb2a3 100644 --- a/src/Umbraco.Web.UI.Client/src/mocks/domains/manifests.handlers.ts +++ b/src/Umbraco.Web.UI.Client/src/mocks/domains/manifests.handlers.ts @@ -16,10 +16,10 @@ export const manifestDevelopmentHandler = rest.get(umbracoPath('/manifests'), (_ name: 'Custom Section', js: '/src/mocks/App_Plugins/section.js', elementName: 'my-section-custom', + weight: 1, meta: { label: 'Custom', pathname: 'my-custom', - weight: 1, }, }, { diff --git a/src/Umbraco.Web.UI.Client/src/temp-internal-manifests/index.ts b/src/Umbraco.Web.UI.Client/src/temp-internal-manifests/index.ts index 2173c71da5..12a44e0e28 100644 --- a/src/Umbraco.Web.UI.Client/src/temp-internal-manifests/index.ts +++ b/src/Umbraco.Web.UI.Client/src/temp-internal-manifests/index.ts @@ -1,7 +1,6 @@ import type { ManifestTypes } from '../core/models'; import { manifests as propertyEditorUIManifests } from './property-editor-ui'; -// TODO: consider moving weight from meta to the main part of the manifest. We need it for every extension. export const internalManifests: Array Promise }> = [ ...propertyEditorUIManifests, { @@ -10,10 +9,10 @@ export const internalManifests: Array Promise import('../backoffice/sections/content/content-section.element'), + weight: 50, meta: { label: 'Content', pathname: 'content', // TODO: how to we want to support pretty urls? - weight: 50, }, }, { @@ -22,10 +21,10 @@ export const internalManifests: Array Promise import('../backoffice/sections/media/media-section.element'), + weight: 50, meta: { label: 'Media', pathname: 'media', // TODO: how to we want to support pretty urls? - weight: 50, }, }, { @@ -34,10 +33,10 @@ export const internalManifests: Array Promise import('../backoffice/sections/members/section-members.element'), + weight: 30, meta: { label: 'Members', pathname: 'members', - weight: 30, }, }, { @@ -45,10 +44,10 @@ export const internalManifests: Array Promise import('../backoffice/sections/settings/settings-section.element'), + weight: 20, meta: { label: 'Settings', pathname: 'settings', // TODO: how to we want to support pretty urls? - weight: 20, }, }, { @@ -57,10 +56,10 @@ export const internalManifests: Array Promise import('../backoffice/sections/packages/packages-section.element'), + weight: 20, meta: { label: 'Packages', pathname: 'packages', - weight: 20, }, }, { @@ -69,11 +68,11 @@ export const internalManifests: Array Promise import('../backoffice/dashboards/welcome/dashboard-welcome.element'), + weight: 20, meta: { label: 'Welcome', sections: ['Umb.Section.Content'], pathname: 'welcome', // TODO: how to we want to support pretty urls? - weight: 20, }, }, { @@ -82,11 +81,11 @@ export const internalManifests: Array Promise import('../backoffice/dashboards/redirect-management/dashboard-redirect-management.element'), + weight: 10, meta: { label: 'Redirect Management', sections: ['Umb.Section.Content'], pathname: 'redirect-management', // TODO: how to we want to support pretty urls? - weight: 10, }, }, { @@ -95,11 +94,11 @@ export const internalManifests: Array Promise import('../backoffice/dashboards/settings-about/dashboard-settings-about.element'), + weight: 10, meta: { label: 'About', sections: ['Umb.Section.Settings'], pathname: 'about', // TODO: how to we want to support pretty urls? - weight: 10, }, }, { @@ -108,11 +107,11 @@ export const internalManifests: Array Promise import('../backoffice/dashboards/telemetry/dashboard-telemetry.element'), + weight: 0, meta: { label: 'Telemetry Data', sections: ['Umb.Section.Settings'], pathname: 'telemetry', // TODO: how do we want to support pretty urls? - weight: 0, }, }, { @@ -121,11 +120,11 @@ export const internalManifests: Array Promise import('../backoffice/dashboards/examine-management/dashboard-examine-management.element'), + weight: 10, meta: { label: 'Examine Management', sections: ['Umb.Section.Settings'], pathname: 'examine-management', // TODO: how to we want to support pretty urls? - weight: 10, }, }, { @@ -134,11 +133,11 @@ export const internalManifests: Array Promise import('../backoffice/dashboards/models-builder/dashboard-models-builder.element'), + weight: 10, meta: { label: 'Models Builder', sections: ['Umb.Section.Settings'], pathname: 'models-builder', // TODO: how to we want to support pretty urls? - weight: 10, }, }, { @@ -147,11 +146,11 @@ export const internalManifests: Array Promise import('../backoffice/dashboards/published-status/dashboard-published-status.element'), + weight: 9, meta: { label: 'Published Status', sections: ['Umb.Section.Settings'], pathname: 'published-status', // TODO: how to we want to support pretty urls? - weight: 9, }, }, { @@ -160,11 +159,11 @@ export const internalManifests: Array Promise import('../backoffice/dashboards/media-management/dashboard-media-management.element'), + weight: 10, meta: { label: 'Media', sections: ['Umb.Section.Media'], pathname: 'media-management', // TODO: how to we want to support pretty urls? - weight: 10, }, }, { @@ -173,13 +172,13 @@ export const internalManifests: Array Promise import('../backoffice/editors/shared/node/views/edit/editor-view-node-edit.element'), + weight: 100, meta: { // TODO: how do we want to filter where editor views are shown? https://our.umbraco.com/documentation/extending/Content-Apps/#setting-up-the-plugin // this is a temp solution editors: ['Umb.Editor.Document', 'Umb.Editor.Media'], label: 'Info', pathname: 'content', - weight: 100, icon: 'document', }, }, @@ -189,13 +188,13 @@ export const internalManifests: Array Promise import('../backoffice/editors/shared/node/views/info/editor-view-node-info.element'), + weight: 90, meta: { // TODO: how do we want to filter where editor views are shown? https://our.umbraco.com/documentation/extending/Content-Apps/#setting-up-the-plugin // this is a temp solution editors: ['Umb.Editor.Document', 'Umb.Editor.Media'], label: 'Info', pathname: 'info', - weight: 90, icon: 'info', }, }, @@ -204,13 +203,13 @@ export const internalManifests: Array Promise import('../backoffice/editors/data-type/views/edit/editor-view-data-type-edit.element'), + weight: 90, meta: { // TODO: how do we want to filter where editor views are shown? https://our.umbraco.com/documentation/extending/Content-Apps/#setting-up-the-plugin // this is a temp solution editors: ['Umb.Editor.DataType'], label: 'Edit', pathname: 'edit', - weight: 90, icon: 'edit', }, }, @@ -219,13 +218,13 @@ export const internalManifests: Array Promise import('../backoffice/editors/data-type/views/info/editor-view-data-type-info.element'), + weight: 90, meta: { // TODO: how do we want to filter where editor views are shown? https://our.umbraco.com/documentation/extending/Content-Apps/#setting-up-the-plugin // this is a temp solution editors: ['Umb.Editor.DataType'], label: 'Info', pathname: 'info', - weight: 90, icon: 'info', }, }, @@ -235,13 +234,13 @@ export const internalManifests: Array Promise import('../backoffice/editors/document-type/views/editor-view-document-type-design.element'), + weight: 90, meta: { // TODO: how do we want to filter where editor views are shown? https://our.umbraco.com/documentation/extending/Content-Apps/#setting-up-the-plugin // this is a temp solution editors: ['Umb.Editor.DocumentType'], label: 'Design', pathname: 'design', - weight: 90, icon: 'edit', }, }, @@ -251,12 +250,12 @@ export const internalManifests: Array Promise import('../backoffice/sections/packages/packages-overview.element'), + weight: 10, meta: { icon: 'document', label: 'Packages', pathname: 'repo', editors: ['Umb.Editor.Packages'], - weight: 10, }, }, { @@ -265,12 +264,12 @@ export const internalManifests: Array Promise import('../backoffice/sections/packages/packages-installed.element'), + weight: 0, meta: { icon: 'document', label: 'Installed', pathname: 'installed', editors: ['Umb.Editor.Packages'], - weight: 0, }, }, { @@ -298,8 +297,8 @@ export const internalManifests: Array Promise import('../backoffice/trees/data-types/tree-data-types.element'), + weight: 1, meta: { - weight: 1, sections: ['Umb.Section.Settings'], }, }, @@ -308,8 +307,8 @@ export const internalManifests: Array Promise import('../backoffice/trees/document-types/tree-document-types.element'), + weight: 2, meta: { - weight: 2, sections: ['Umb.Section.Settings'], }, }, @@ -319,8 +318,8 @@ export const internalManifests: Array Promise import('../backoffice/dashboards/welcome/dashboard-welcome.element'), + weight: -10, meta: { - weight: -10, pathname: 'welcome', sections: ['Umb.Section.Members'], }, @@ -330,8 +329,8 @@ export const internalManifests: Array Promise import('../backoffice/trees/members/tree-members.element'), + weight: 0, meta: { - weight: 0, sections: ['Umb.Section.Members'], }, }, @@ -340,8 +339,8 @@ export const internalManifests: Array Promise import('../backoffice/trees/member-groups/tree-member-groups.element'), + weight: 1, meta: { - weight: 1, sections: ['Umb.Section.Members'], }, }, @@ -350,8 +349,8 @@ export const internalManifests: Array Promise import('../backoffice/trees/extensions/tree-extensions.element'), + weight: 3, meta: { - weight: 3, sections: ['Umb.Section.Settings'], }, }, @@ -360,8 +359,8 @@ export const internalManifests: Array Promise import('../backoffice/trees/media/tree-media.element'), + weight: 100, meta: { - weight: 100, sections: ['Umb.Section.Media'], }, }, @@ -370,8 +369,8 @@ export const internalManifests: Array Promise import('../backoffice/trees/documents/tree-documents.element'), + weight: 100, meta: { - weight: 100, sections: ['Umb.Section.Content'], }, }, @@ -443,11 +442,11 @@ export const internalManifests: Array Promise import('../backoffice/trees/documents/actions/action-document-create.element'), + weight: 100, meta: { trees: ['Umb.Tree.Content'], label: 'Create', icon: 'add', - weight: 100, }, }, { @@ -455,11 +454,11 @@ export const internalManifests: Array Promise import('../backoffice/trees/documents/actions/action-document-delete.element'), + weight: 100, meta: { trees: ['Umb.Tree.Content'], label: 'Delete', icon: 'delete', - weight: 100, }, }, { @@ -467,11 +466,11 @@ export const internalManifests: Array Promise import('../backoffice/trees/documents/actions/action-document-paged.element'), + weight: 100, meta: { trees: ['Umb.Tree.Content'], label: 'Paged', icon: 'favorite', - weight: 100, }, }, { @@ -479,11 +478,11 @@ export const internalManifests: Array Promise import('../backoffice/trees/data-types/actions/action-data-type-create.element'), + weight: 100, meta: { trees: ['Umb.Tree.DataTypes'], label: 'Create', icon: 'add', - weight: 100, }, }, { @@ -491,11 +490,11 @@ export const internalManifests: Array Promise import('../backoffice/trees/data-types/actions/action-data-type-delete.element'), + weight: 100, meta: { trees: ['Umb.Tree.DataTypes'], label: 'Delete', icon: 'delete', - weight: 100, }, }, ]; From 346585e5a0ac48c780bcdf25a1d567a4bc2f7fc6 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 11 Oct 2022 10:15:41 +0200 Subject: [PATCH 3/7] handle sorting in extension registry --- .../src/core/extension/extension.registry.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/core/extension/extension.registry.ts b/src/Umbraco.Web.UI.Client/src/core/extension/extension.registry.ts index 622425f146..d5bb9aee13 100644 --- a/src/Umbraco.Web.UI.Client/src/core/extension/extension.registry.ts +++ b/src/Umbraco.Web.UI.Client/src/core/extension/extension.registry.ts @@ -70,6 +70,14 @@ export class UmbExtensionRegistry { extensionsOfType(type: 'custom'): Observable>; extensionsOfType(type: string): Observable>; extensionsOfType(type: string): Observable> { - return this.extensions.pipe(map((exts) => exts.filter((ext) => ext.type === type))); + return this.extensions.pipe( + map((exts) => + exts + .filter((ext) => ext.type === type) + .sort((a, b) => { + return (b.weight || 0) - (a.weight || 0); + }) + ) + ); } } From 62966ce12c756f783d47b4a5be1860ba0754c6c2 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 11 Oct 2022 10:16:59 +0200 Subject: [PATCH 4/7] remove individual sort handling --- .../editor-entity-layout.element.ts | 8 +------- .../sections/shared/section-dashboards.element.ts | 4 +--- .../sections/shared/section-trees.element.ts | 15 +++++++-------- .../backoffice/sections/shared/section.element.ts | 8 +------- .../tree-context-menu-page-action-list.element.ts | 8 +++----- .../src/core/stores/section.store.ts | 4 +--- 6 files changed, 14 insertions(+), 33 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/editors/shared/editor-entity-layout/editor-entity-layout.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/editors/shared/editor-entity-layout/editor-entity-layout.element.ts index 43a4d8232e..145ce717ab 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/editors/shared/editor-entity-layout/editor-entity-layout.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/editors/shared/editor-entity-layout/editor-entity-layout.element.ts @@ -116,13 +116,7 @@ export class UmbEditorEntityLayout extends UmbContextConsumerMixin(LitElement) { this._editorViewsSubscription = this._extensionRegistry ?.extensionsOfType('editorView') - .pipe( - map((extensions) => - extensions - .filter((extension) => extension.meta.editors.includes(this.alias)) - .sort((a, b) => b.meta.weight - a.meta.weight) - ) - ) + .pipe(map((extensions) => extensions.filter((extension) => extension.meta.editors.includes(this.alias)))) .subscribe((editorViews) => { this._editorViews = editorViews; this._createRoutes(); diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-dashboards.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-dashboards.element.ts index 69f06da640..5089fe1254 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-dashboards.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-dashboards.element.ts @@ -92,9 +92,7 @@ export class UmbSectionDashboards extends UmbContextConsumerMixin(LitElement) { ?.extensionsOfType('dashboard') .pipe( map((extensions) => - extensions - .filter((extension) => extension.meta.sections.includes(this._currentSectionAlias)) - .sort((a, b) => b.meta.weight - a.meta.weight) + extensions.filter((extension) => extension.meta.sections.includes(this._currentSectionAlias)) ) ) .subscribe((dashboards) => { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-trees.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-trees.element.ts index ed9af511ad..2e4ee8951c 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-trees.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section-trees.element.ts @@ -48,14 +48,13 @@ export class UmbSectionTrees extends UmbContextConsumerMixin(LitElement) { if (!section) return EMPTY; return ( - this._extensionStore?.extensionsOfType('tree').pipe( - map((trees) => - trees - .filter((tree) => tree.meta.sections.includes(section.alias)) - .sort((a, b) => b.meta.weight - a.meta.weight) - .map((tree) => tree.alias) - ) - ) ?? of([]) + this._extensionStore + ?.extensionsOfType('tree') + .pipe( + map((trees) => + trees.filter((tree) => tree.meta.sections.includes(section.alias)).map((tree) => tree.alias) + ) + ) ?? of([]) ); }) ) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section.element.ts index 97295c277e..2160d8228c 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/sections/shared/section.element.ts @@ -72,13 +72,7 @@ export class UmbSectionElement extends UmbContextConsumerMixin(LitElement) { return ( this._extensionRegistry ?.extensionsOfType('tree') - .pipe( - map((trees) => - trees - .filter((tree) => tree.meta.sections.includes(section.alias)) - .sort((a, b) => b.meta.weight - a.meta.weight) - ) - ) ?? of([]) + .pipe(map((trees) => trees.filter((tree) => tree.meta.sections.includes(section.alias)))) ?? of([]) ); }) ) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/trees/shared/context-menu/tree-context-menu-page-action-list.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/trees/shared/context-menu/tree-context-menu-page-action-list.element.ts index c20e75dd96..bb1df03f59 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/trees/shared/context-menu/tree-context-menu-page-action-list.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/trees/shared/context-menu/tree-context-menu-page-action-list.element.ts @@ -90,11 +90,9 @@ export class UmbTreeContextMenuPageActionListElement extends UmbContextConsumerM } private _renderActions() { - return this._actions - .sort((a, b) => a.meta.weight - b.meta.weight) - .map((action) => { - return html` `; - }); + return this._actions.map((action) => { + return html` `; + }); } disconnectedCallback(): void { diff --git a/src/Umbraco.Web.UI.Client/src/core/stores/section.store.ts b/src/Umbraco.Web.UI.Client/src/core/stores/section.store.ts index 34a465a5e9..034cb4c686 100644 --- a/src/Umbraco.Web.UI.Client/src/core/stores/section.store.ts +++ b/src/Umbraco.Web.UI.Client/src/core/stores/section.store.ts @@ -20,9 +20,7 @@ export class UmbSectionStore { this._allowedSection = data.sections; */ - return this._extensionRegistry - ?.extensionsOfType('section') - .pipe(map((extensions) => extensions.sort((a, b) => b.meta.weight - a.meta.weight))); + return this._extensionRegistry?.extensionsOfType('section'); } public setCurrent(alias: string) { From c07814a2fac728af53fe9ce112cb42d0b8c91097 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 11 Oct 2022 10:17:06 +0200 Subject: [PATCH 5/7] clean up --- .../editors/extensions/editor-extensions.element.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/editors/extensions/editor-extensions.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/editors/extensions/editor-extensions.element.ts index 0f2d510ec7..1910189a0d 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/editors/extensions/editor-extensions.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/editors/extensions/editor-extensions.element.ts @@ -37,11 +37,6 @@ export class UmbEditorExtensionsElement extends UmbContextConsumerMixin(LitEleme this._extensionsSubscription = this._extensionRegistry.extensions.subscribe((extensions) => { this._extensions = [...extensions]; // TODO: Though, this is a shallow clone, wouldn't we either do a deep clone or no clone at all? }); - - this._extensionsSubscription = this._extensionRegistry.extensionsOfType('section').subscribe((sections) => { - // In this callback sections are typed. Example meta.weight... - console.log(sections[0].meta.weight); - }); }); } From 7169237f18d3fa693c25fdb6ba61231860c1c187 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 11 Oct 2022 15:45:31 +0200 Subject: [PATCH 6/7] add tests for extension registry --- .../src/core/extension/index.ts | 2 +- .../registry/extension.registry.test.ts | 66 +++++++++++++++++++ .../{ => registry}/extension.registry.ts | 4 +- 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts rename src/Umbraco.Web.UI.Client/src/core/extension/{ => registry}/extension.registry.ts (96%) diff --git a/src/Umbraco.Web.UI.Client/src/core/extension/index.ts b/src/Umbraco.Web.UI.Client/src/core/extension/index.ts index 2f96a3abcd..2c6c0f8315 100644 --- a/src/Umbraco.Web.UI.Client/src/core/extension/index.ts +++ b/src/Umbraco.Web.UI.Client/src/core/extension/index.ts @@ -1,3 +1,3 @@ -export * from './extension.registry'; +export * from './registry/extension.registry'; export * from './create-extension-element.function'; export * from './load-extension.function'; diff --git a/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts b/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts new file mode 100644 index 0000000000..207d740bb7 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts @@ -0,0 +1,66 @@ +import { expect } from '@open-wc/testing'; +import type { ManifestTypes } from '../../models'; +import { UmbExtensionRegistry } from './extension.registry'; + +describe('UmbContextRequestEvent', () => { + let extensionRegistry: UmbExtensionRegistry; + let manifests: Array; + + beforeEach(() => { + extensionRegistry = new UmbExtensionRegistry(); + manifests = [ + { + type: 'section', + name: 'test-section-1', + alias: 'Umb.Test.Section.1', + meta: { + label: 'Test Section 1', + pathname: 'test-section-1', + }, + }, + { + type: 'section', + name: 'test-section-2', + alias: 'Umb.Test.Section.2', + meta: { + label: 'Test Section 2', + pathname: 'test-section-2', + }, + }, + { + type: 'editor', + name: 'test-editor-1', + alias: 'Umb.Test.Editor.1', + meta: { + entityType: 'testEntity', + }, + }, + ]; + + manifests.forEach((manifest) => extensionRegistry.register(manifest)); + }); + + it('should register an extension', () => { + const registeredExtensions = extensionRegistry['_extensions'].getValue(); + expect(registeredExtensions).to.have.lengthOf(3); + expect(registeredExtensions?.[0]?.name).to.eq('test-section-1'); + }); + + it('should get an extension by alias', (done) => { + const alias = 'Umb.Test.Section.1'; + extensionRegistry.getByAlias(alias).subscribe((extension) => { + expect(extension?.alias).to.eq(alias); + done(); + }); + }); + + it('should get all extensions by type', (done) => { + const type = 'section'; + extensionRegistry.extensionsOfType(type).subscribe((extensions) => { + expect(extensions).to.have.lengthOf(2); + expect(extensions?.[0]?.type).to.eq('section'); + expect(extensions?.[1]?.type).to.eq('section'); + done(); + }); + }); +}); diff --git a/src/Umbraco.Web.UI.Client/src/core/extension/extension.registry.ts b/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.ts similarity index 96% rename from src/Umbraco.Web.UI.Client/src/core/extension/extension.registry.ts rename to src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.ts index d5bb9aee13..6228692f05 100644 --- a/src/Umbraco.Web.UI.Client/src/core/extension/extension.registry.ts +++ b/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.ts @@ -12,8 +12,8 @@ import type { ManifestEditor, ManifestCustom, ManifestPackageView, -} from '../models'; -import { createExtensionElement } from './create-extension-element.function'; +} from '../../models'; +import { createExtensionElement } from '../create-extension-element.function'; export type UmbExtensionManifestJSModel = { elementName?: string; From 59bb5f4b7e827f67f2b9939536488909db6160f7 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 11 Oct 2022 15:56:03 +0200 Subject: [PATCH 7/7] test extension order --- .../registry/extension.registry.test.ts | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts b/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts index 207d740bb7..ae6f221a46 100644 --- a/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts +++ b/src/Umbraco.Web.UI.Client/src/core/extension/registry/extension.registry.test.ts @@ -13,6 +13,7 @@ describe('UmbContextRequestEvent', () => { type: 'section', name: 'test-section-1', alias: 'Umb.Test.Section.1', + weight: 1, meta: { label: 'Test Section 1', pathname: 'test-section-1', @@ -22,11 +23,22 @@ describe('UmbContextRequestEvent', () => { type: 'section', name: 'test-section-2', alias: 'Umb.Test.Section.2', + weight: 200, meta: { label: 'Test Section 2', pathname: 'test-section-2', }, }, + { + type: 'section', + name: 'test-section-3', + alias: 'Umb.Test.Section.3', + weight: 25, + meta: { + label: 'Test Section 3', + pathname: 'test-section-3', + }, + }, { type: 'editor', name: 'test-editor-1', @@ -42,7 +54,7 @@ describe('UmbContextRequestEvent', () => { it('should register an extension', () => { const registeredExtensions = extensionRegistry['_extensions'].getValue(); - expect(registeredExtensions).to.have.lengthOf(3); + expect(registeredExtensions).to.have.lengthOf(4); expect(registeredExtensions?.[0]?.name).to.eq('test-section-1'); }); @@ -54,13 +66,25 @@ describe('UmbContextRequestEvent', () => { }); }); - it('should get all extensions by type', (done) => { + describe('getByType', () => { const type = 'section'; - extensionRegistry.extensionsOfType(type).subscribe((extensions) => { - expect(extensions).to.have.lengthOf(2); - expect(extensions?.[0]?.type).to.eq('section'); - expect(extensions?.[1]?.type).to.eq('section'); - done(); + + it('should get all extensions by type', (done) => { + extensionRegistry.extensionsOfType(type).subscribe((extensions) => { + expect(extensions).to.have.lengthOf(3); + expect(extensions?.[0]?.type).to.eq(type); + expect(extensions?.[1]?.type).to.eq(type); + done(); + }); + }); + + it('should return extensions ordered by weight', (done) => { + extensionRegistry.extensionsOfType(type).subscribe((extensions) => { + expect(extensions?.[0]?.weight).to.eq(200); + expect(extensions?.[1]?.weight).to.eq(25); + expect(extensions?.[2]?.weight).to.eq(1); + done(); + }); }); }); });