From f4b86a489f732eeb61dd8ed733179993af86af11 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 9 Sep 2024 17:59:20 +0200 Subject: [PATCH 01/15] scaffold help package + header app --- src/apps/backoffice/backoffice.element.ts | 1 + src/packages/help/help-header-app.element.ts | 21 ++++++++++++++++++++ src/packages/help/manifests.ts | 16 +++++++++++++++ src/packages/help/umbraco-package.ts | 9 +++++++++ src/packages/help/vite.config.ts | 12 +++++++++++ 5 files changed, 59 insertions(+) create mode 100644 src/packages/help/help-header-app.element.ts create mode 100644 src/packages/help/manifests.ts create mode 100644 src/packages/help/umbraco-package.ts create mode 100644 src/packages/help/vite.config.ts diff --git a/src/apps/backoffice/backoffice.element.ts b/src/apps/backoffice/backoffice.element.ts index d59e98126c..cdaffce824 100644 --- a/src/apps/backoffice/backoffice.element.ts +++ b/src/apps/backoffice/backoffice.element.ts @@ -18,6 +18,7 @@ const CORE_PACKAGES = [ import('../../packages/dictionary/umbraco-package.js'), import('../../packages/documents/umbraco-package.js'), import('../../packages/health-check/umbraco-package.js'), + import('../../packages/help/umbraco-package.js'), import('../../packages/language/umbraco-package.js'), import('../../packages/log-viewer/umbraco-package.js'), import('../../packages/markdown-editor/umbraco-package.js'), diff --git a/src/packages/help/help-header-app.element.ts b/src/packages/help/help-header-app.element.ts new file mode 100644 index 0000000000..e34b0d906b --- /dev/null +++ b/src/packages/help/help-header-app.element.ts @@ -0,0 +1,21 @@ +import type { CSSResultGroup } from '@umbraco-cms/backoffice/external/lit'; +import { css, html, customElement } from '@umbraco-cms/backoffice/external/lit'; +import { UmbHeaderAppButtonElement } from '@umbraco-cms/backoffice/components'; + +const elementName = 'umb-help-header-app'; +@customElement(elementName) +export class UmbHelpHeaderAppElement extends UmbHeaderAppButtonElement { + override render() { + return html`
My Header App
`; + } + + static override styles: CSSResultGroup = [UmbHeaderAppButtonElement.styles, css``]; +} + +export { UmbHelpHeaderAppElement as element }; + +declare global { + interface HTMLElementTagNameMap { + [elementName]: UmbHelpHeaderAppElement; + } +} diff --git a/src/packages/help/manifests.ts b/src/packages/help/manifests.ts new file mode 100644 index 0000000000..9504557d0d --- /dev/null +++ b/src/packages/help/manifests.ts @@ -0,0 +1,16 @@ +import type { ManifestTypes, UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry'; + +export const manifests: Array = [ + { + type: 'headerApp', + alias: 'Umb.HeaderApp.Help', + name: 'Help Header App', + element: () => import('./help-header-app.element.js'), + weight: 0, + meta: { + label: 'TODO: how should we enable this to not be set.', + icon: 'TODO: how should we enable this to not be set.', + pathname: 'help', + }, + }, +]; diff --git a/src/packages/help/umbraco-package.ts b/src/packages/help/umbraco-package.ts new file mode 100644 index 0000000000..bbf3a996b9 --- /dev/null +++ b/src/packages/help/umbraco-package.ts @@ -0,0 +1,9 @@ +export const name = 'Umbraco.Core.Help'; +export const extensions = [ + { + name: 'Help Bundle', + alias: 'Umb.Bundle.Help', + type: 'bundle', + js: () => import('./manifests.js'), + }, +]; diff --git a/src/packages/help/vite.config.ts b/src/packages/help/vite.config.ts new file mode 100644 index 0000000000..a320e9a053 --- /dev/null +++ b/src/packages/help/vite.config.ts @@ -0,0 +1,12 @@ +import { defineConfig } from 'vite'; +import { rmSync } from 'fs'; +import { getDefaultConfig } from '../../vite-config-base'; + +const dist = '../../../dist-cms/packages/help'; + +// delete the unbundled dist folder +rmSync(dist, { recursive: true, force: true }); + +export default defineConfig({ + ...getDefaultConfig({ dist, entry: ['manifests.ts', 'umbraco-package.ts'] }), +}); From fc0f5c84ec5022d907bce8f9ad7fb9a4c6691206 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 9 Sep 2024 18:04:44 +0200 Subject: [PATCH 02/15] render button with icon --- src/packages/help/help-header-app.element.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/packages/help/help-header-app.element.ts b/src/packages/help/help-header-app.element.ts index e34b0d906b..bafddc24b0 100644 --- a/src/packages/help/help-header-app.element.ts +++ b/src/packages/help/help-header-app.element.ts @@ -6,7 +6,11 @@ const elementName = 'umb-help-header-app'; @customElement(elementName) export class UmbHelpHeaderAppElement extends UmbHeaderAppButtonElement { override render() { - return html`
My Header App
`; + return html` + + + + `; } static override styles: CSSResultGroup = [UmbHeaderAppButtonElement.styles, css``]; From 67ed209ba7b6eab8e44afae9096ad48a6fe9ed68 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 9 Sep 2024 19:07:43 +0200 Subject: [PATCH 03/15] split into header app and menu + register two menu items --- .../header-app/help-header-app.element.ts | 48 +++++++++++++++++++ src/packages/help/header-app/manifests.ts | 11 +++++ src/packages/help/help-header-app.element.ts | 25 ---------- src/packages/help/manifests.ts | 17 ++----- src/packages/help/menu/constants.ts | 1 + src/packages/help/menu/index.ts | 1 + src/packages/help/menu/manifests.ts | 32 +++++++++++++ 7 files changed, 96 insertions(+), 39 deletions(-) create mode 100644 src/packages/help/header-app/help-header-app.element.ts create mode 100644 src/packages/help/header-app/manifests.ts delete mode 100644 src/packages/help/help-header-app.element.ts create mode 100644 src/packages/help/menu/constants.ts create mode 100644 src/packages/help/menu/index.ts create mode 100644 src/packages/help/menu/manifests.ts diff --git a/src/packages/help/header-app/help-header-app.element.ts b/src/packages/help/header-app/help-header-app.element.ts new file mode 100644 index 0000000000..7b0b767d13 --- /dev/null +++ b/src/packages/help/header-app/help-header-app.element.ts @@ -0,0 +1,48 @@ +import { UMB_HELP_MENU_ALIAS } from '../menu/index.js'; +import type { CSSResultGroup } from '@umbraco-cms/backoffice/external/lit'; +import { css, html, customElement, state } from '@umbraco-cms/backoffice/external/lit'; +import { UmbHeaderAppButtonElement } from '@umbraco-cms/backoffice/components'; +import type { ManifestMenu } from '@umbraco-cms/backoffice/extension-registry'; + +const elementName = 'umb-help-header-app'; +@customElement(elementName) +export class UmbHelpHeaderAppElement extends UmbHeaderAppButtonElement { + @state() + private _popoverOpen = false; + + #onPopoverToggle(event: ToggleEvent) { + // TODO: This ignorer is just neede for JSON SCHEMA TO WORK, As its not updated with latest TS jet. + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + this._popoverOpen = event.newState === 'open'; + } + + override render() { + return html` + + + + + + + + + + + + `; + } + + static override styles: CSSResultGroup = [UmbHeaderAppButtonElement.styles, css``]; +} + +export { UmbHelpHeaderAppElement as element }; + +declare global { + interface HTMLElementTagNameMap { + [elementName]: UmbHelpHeaderAppElement; + } +} diff --git a/src/packages/help/header-app/manifests.ts b/src/packages/help/header-app/manifests.ts new file mode 100644 index 0000000000..46bb441c2c --- /dev/null +++ b/src/packages/help/header-app/manifests.ts @@ -0,0 +1,11 @@ +import type { ManifestTypes, UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry'; + +export const manifests: Array = [ + { + type: 'headerApp', + alias: 'Umb.HeaderApp.Help', + name: 'Help Header App', + element: () => import('./help-header-app.element.js'), + weight: 500, + }, +]; diff --git a/src/packages/help/help-header-app.element.ts b/src/packages/help/help-header-app.element.ts deleted file mode 100644 index bafddc24b0..0000000000 --- a/src/packages/help/help-header-app.element.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { CSSResultGroup } from '@umbraco-cms/backoffice/external/lit'; -import { css, html, customElement } from '@umbraco-cms/backoffice/external/lit'; -import { UmbHeaderAppButtonElement } from '@umbraco-cms/backoffice/components'; - -const elementName = 'umb-help-header-app'; -@customElement(elementName) -export class UmbHelpHeaderAppElement extends UmbHeaderAppButtonElement { - override render() { - return html` - - - - `; - } - - static override styles: CSSResultGroup = [UmbHeaderAppButtonElement.styles, css``]; -} - -export { UmbHelpHeaderAppElement as element }; - -declare global { - interface HTMLElementTagNameMap { - [elementName]: UmbHelpHeaderAppElement; - } -} diff --git a/src/packages/help/manifests.ts b/src/packages/help/manifests.ts index 9504557d0d..223544e6db 100644 --- a/src/packages/help/manifests.ts +++ b/src/packages/help/manifests.ts @@ -1,16 +1,5 @@ +import { manifests as headerAppManifests } from './header-app/manifests.js'; +import { manifests as menuManifests } from './menu/manifests.js'; import type { ManifestTypes, UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry'; -export const manifests: Array = [ - { - type: 'headerApp', - alias: 'Umb.HeaderApp.Help', - name: 'Help Header App', - element: () => import('./help-header-app.element.js'), - weight: 0, - meta: { - label: 'TODO: how should we enable this to not be set.', - icon: 'TODO: how should we enable this to not be set.', - pathname: 'help', - }, - }, -]; +export const manifests: Array = [...menuManifests, ...headerAppManifests]; diff --git a/src/packages/help/menu/constants.ts b/src/packages/help/menu/constants.ts new file mode 100644 index 0000000000..cae4c017c3 --- /dev/null +++ b/src/packages/help/menu/constants.ts @@ -0,0 +1 @@ +export const UMB_HELP_MENU_ALIAS = 'Umb.Menu.Help'; diff --git a/src/packages/help/menu/index.ts b/src/packages/help/menu/index.ts new file mode 100644 index 0000000000..4f07201dcf --- /dev/null +++ b/src/packages/help/menu/index.ts @@ -0,0 +1 @@ +export * from './constants.js'; diff --git a/src/packages/help/menu/manifests.ts b/src/packages/help/menu/manifests.ts new file mode 100644 index 0000000000..06cab3d506 --- /dev/null +++ b/src/packages/help/menu/manifests.ts @@ -0,0 +1,32 @@ +import { UMB_HELP_MENU_ALIAS } from './constants.js'; +import type { ManifestTypes, UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry'; + +export const manifests: Array = [ + { + type: 'menu', + alias: UMB_HELP_MENU_ALIAS, + name: 'Help Menu', + }, + { + type: 'menuItem', + alias: 'Umb.MenuItem.Help.LearningBase', + name: 'Learning Base Help Menu Item', + weight: 200, + meta: { + label: 'Umbraco Learning Base', + icon: 'icon-movie-alt', + menus: [UMB_HELP_MENU_ALIAS], + }, + }, + { + type: 'menuItem', + alias: 'Umb.MenuItem.Help.CommunityWebsite', + name: 'Community Website Help Menu Item', + weight: 100, + meta: { + label: 'Community Website', + icon: 'icon-hearts', + menus: [UMB_HELP_MENU_ALIAS], + }, + }, +]; From af2b663b0569a527dc3dccc25ec059735cad92b6 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 10 Sep 2024 08:53:36 +0200 Subject: [PATCH 04/15] add link menu item kind --- .../core/extension-registry/models/index.ts | 3 +- .../models/menu-item.model.ts | 10 +++++++ src/packages/core/manifests.ts | 2 ++ .../menu-item-layout.element.ts | 11 +++++++- .../menu-item/link/link-menu-item.element.ts | 28 +++++++++++++++++++ .../components/menu-item/link/manifests.ts | 14 ++++++++++ .../menu/components/menu-item/manifests.ts | 4 +++ src/packages/core/menu/manifests.ts | 4 +++ src/packages/help/menu/manifests.ts | 8 ++++-- 9 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/packages/core/menu/components/menu-item/link/link-menu-item.element.ts create mode 100644 src/packages/core/menu/components/menu-item/link/manifests.ts create mode 100644 src/packages/core/menu/components/menu-item/manifests.ts create mode 100644 src/packages/core/menu/manifests.ts diff --git a/src/packages/core/extension-registry/models/index.ts b/src/packages/core/extension-registry/models/index.ts index adc53de04c..278207f19a 100644 --- a/src/packages/core/extension-registry/models/index.ts +++ b/src/packages/core/extension-registry/models/index.ts @@ -30,7 +30,7 @@ import type { ManifestHealthCheck } from './health-check.model.js'; import type { ManifestIcons } from './icons.model.js'; import type { ManifestLocalization } from './localization.model.js'; import type { ManifestMenu } from './menu.model.js'; -import type { ManifestMenuItem, ManifestMenuItemTreeKind } from './menu-item.model.js'; +import type { ManifestMenuItem, ManifestMenuItemLinkKind, ManifestMenuItemTreeKind } from './menu-item.model.js'; import type { ManifestModal } from './modal.model.js'; import type { ManifestPackageView } from './package-view.model.js'; import type { ManifestPreviewAppProvider } from './preview-app.model.js'; @@ -186,6 +186,7 @@ export type ManifestTypes = | ManifestMenu | ManifestMenuItem | ManifestMenuItemTreeKind + | ManifestMenuItemLinkKind | ManifestMfaLoginProvider | ManifestModal | ManifestMonacoMarkdownEditorAction diff --git a/src/packages/core/extension-registry/models/menu-item.model.ts b/src/packages/core/extension-registry/models/menu-item.model.ts index 05eeb81b78..68f7d2f354 100644 --- a/src/packages/core/extension-registry/models/menu-item.model.ts +++ b/src/packages/core/extension-registry/models/menu-item.model.ts @@ -26,3 +26,13 @@ export interface MetaMenuItemTreeKind extends MetaMenuItem { treeAlias: string; hideTreeRoot?: boolean; } + +export interface ManifestMenuItemLinkKind extends ManifestMenuItem { + type: 'menuItem'; + kind: 'link'; + meta: MetaMenuItemLinkKind; +} + +export interface MetaMenuItemLinkKind extends MetaMenuItem { + href: string; +} diff --git a/src/packages/core/manifests.ts b/src/packages/core/manifests.ts index 893b161f1f..5fc8f5c5a8 100644 --- a/src/packages/core/manifests.ts +++ b/src/packages/core/manifests.ts @@ -9,6 +9,7 @@ import { manifests as entityBulkActionManifests } from './entity-bulk-action/man import { manifests as extensionManifests } from './extension-registry/manifests.js'; import { manifests as iconRegistryManifests } from './icon-registry/manifests.js'; import { manifests as localizationManifests } from './localization/manifests.js'; +import { manifests as menuManifests } from './menu/manifests.js'; import { manifests as modalManifests } from './modal/common/manifests.js'; import { manifests as pickerManifests } from './picker/manifests.js'; import { manifests as propertyActionManifests } from './property-action/manifests.js'; @@ -35,6 +36,7 @@ export const manifests: Array = [ ...extensionManifests, ...iconRegistryManifests, ...localizationManifests, + ...menuManifests, ...modalManifests, ...pickerManifests, ...propertyActionManifests, diff --git a/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts b/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts index e9d7291e34..af64f06949 100644 --- a/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts +++ b/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts @@ -47,6 +47,14 @@ export class UmbMenuItemLayoutElement extends UmbLitElement { #debouncedCheckIsActive = debounce(() => this.#checkIsActive(), 100); + #getTarget() { + if (this.href && this.href.startsWith('http')) { + return '_blank'; + } + + return '_self'; + } + #checkIsActive() { if (!this.href) { this._isActive = false; @@ -63,7 +71,8 @@ export class UmbMenuItemLayoutElement extends UmbLitElement { label=${this.label} .caretLabel=${this.localize.term('visuallyHiddenTexts_expandChildItems') + ' ' + this.label} ?active=${this._isActive} - ?has-children=${this.hasChildren}> + ?has-children=${this.hasChildren} + target=${this.#getTarget()}> ${this.entityType ? html` + + `; + } +} + +export { UmbLinkMenuItemElement as element }; + +declare global { + interface HTMLElementTagNameMap { + [elementName]: UmbLinkMenuItemElement; + } +} diff --git a/src/packages/core/menu/components/menu-item/link/manifests.ts b/src/packages/core/menu/components/menu-item/link/manifests.ts new file mode 100644 index 0000000000..1645bd2edc --- /dev/null +++ b/src/packages/core/menu/components/menu-item/link/manifests.ts @@ -0,0 +1,14 @@ +import type { ManifestTypes, UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry'; + +export const manifests: Array = [ + { + type: 'kind', + alias: 'Umb.Kind.MenuItem.Link', + matchKind: 'link', + matchType: 'menuItem', + manifest: { + type: 'menuItem', + element: () => import('./link-menu-item.element.js'), + }, + }, +]; diff --git a/src/packages/core/menu/components/menu-item/manifests.ts b/src/packages/core/menu/components/menu-item/manifests.ts new file mode 100644 index 0000000000..08daa5be16 --- /dev/null +++ b/src/packages/core/menu/components/menu-item/manifests.ts @@ -0,0 +1,4 @@ +import { manifests as linkManifests } from './link/manifests.js'; +import type { ManifestTypes, UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry'; + +export const manifests: Array = [...linkManifests]; diff --git a/src/packages/core/menu/manifests.ts b/src/packages/core/menu/manifests.ts new file mode 100644 index 0000000000..88cfb7bd3d --- /dev/null +++ b/src/packages/core/menu/manifests.ts @@ -0,0 +1,4 @@ +import { manifests as menuItemManifests } from './components/menu-item/manifests.js'; +import type { ManifestTypes, UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry'; + +export const manifests: Array = [...menuItemManifests]; diff --git a/src/packages/help/menu/manifests.ts b/src/packages/help/menu/manifests.ts index 06cab3d506..4d9985a5b5 100644 --- a/src/packages/help/menu/manifests.ts +++ b/src/packages/help/menu/manifests.ts @@ -9,24 +9,28 @@ export const manifests: Array = [ }, { type: 'menuItem', + kind: 'link', alias: 'Umb.MenuItem.Help.LearningBase', name: 'Learning Base Help Menu Item', weight: 200, meta: { + menus: [UMB_HELP_MENU_ALIAS], label: 'Umbraco Learning Base', icon: 'icon-movie-alt', - menus: [UMB_HELP_MENU_ALIAS], + href: 'https://learn.umbraco.com', }, }, { type: 'menuItem', + kind: 'link', alias: 'Umb.MenuItem.Help.CommunityWebsite', name: 'Community Website Help Menu Item', weight: 100, meta: { + menus: [UMB_HELP_MENU_ALIAS], label: 'Community Website', icon: 'icon-hearts', - menus: [UMB_HELP_MENU_ALIAS], + href: 'https://our.umbraco.com', }, }, ]; From fb493685a0d04c62294e0b189082b407004c7466 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 10 Sep 2024 14:36:00 +0200 Subject: [PATCH 05/15] move target logic to link element --- .../menu-item-layout.element.ts | 19 ++++++++++--------- .../menu-item/link/link-menu-item.element.ts | 11 +++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts b/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts index af64f06949..b6471e064d 100644 --- a/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts +++ b/src/packages/core/menu/components/menu-item-layout/menu-item-layout.element.ts @@ -37,6 +37,15 @@ export class UmbMenuItemLayoutElement extends UmbLitElement { @property({ type: String }) public href?: string; + /** + * Set an anchor tag target, only used when using href. + * @type {string} + * @attr + * @default undefined + */ + @property({ type: String }) + public target?: '_blank' | '_parent' | '_self' | '_top'; + @state() private _isActive = false; @@ -47,14 +56,6 @@ export class UmbMenuItemLayoutElement extends UmbLitElement { #debouncedCheckIsActive = debounce(() => this.#checkIsActive(), 100); - #getTarget() { - if (this.href && this.href.startsWith('http')) { - return '_blank'; - } - - return '_self'; - } - #checkIsActive() { if (!this.href) { this._isActive = false; @@ -72,7 +73,7 @@ export class UmbMenuItemLayoutElement extends UmbLitElement { .caretLabel=${this.localize.term('visuallyHiddenTexts_expandChildItems') + ' ' + this.label} ?active=${this._isActive} ?has-children=${this.hasChildren} - target=${this.#getTarget()}> + target=${ifDefined(this.href && this.target ? this.target : undefined)}> ${this.entityType ? html` From 22553b6bbf117c8d326a184e659be282ee54543b Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 10 Sep 2024 14:59:31 +0200 Subject: [PATCH 06/15] add condition to check if the current user is admin --- .../conditions/is-admin/constants.ts | 1 + .../current-user/conditions/is-admin/index.ts | 1 + .../is-admin/is-admin.condition.manifest.ts | 9 +++++++++ .../conditions/is-admin/is-admin.condition.ts | 20 +++++++++++++++++++ .../user/current-user/conditions/manifests.ts | 3 +++ src/packages/user/current-user/manifests.ts | 16 +++++++-------- 6 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 src/packages/user/current-user/conditions/is-admin/constants.ts create mode 100644 src/packages/user/current-user/conditions/is-admin/index.ts create mode 100644 src/packages/user/current-user/conditions/is-admin/is-admin.condition.manifest.ts create mode 100644 src/packages/user/current-user/conditions/is-admin/is-admin.condition.ts create mode 100644 src/packages/user/current-user/conditions/manifests.ts diff --git a/src/packages/user/current-user/conditions/is-admin/constants.ts b/src/packages/user/current-user/conditions/is-admin/constants.ts new file mode 100644 index 0000000000..2d3a8d78da --- /dev/null +++ b/src/packages/user/current-user/conditions/is-admin/constants.ts @@ -0,0 +1 @@ +export const UMB_CURRENT_USER_IS_ADMIN_CONDITION_ALIAS = 'Umb.Condition.CurrentUser.IsAdmin'; diff --git a/src/packages/user/current-user/conditions/is-admin/index.ts b/src/packages/user/current-user/conditions/is-admin/index.ts new file mode 100644 index 0000000000..4f07201dcf --- /dev/null +++ b/src/packages/user/current-user/conditions/is-admin/index.ts @@ -0,0 +1 @@ +export * from './constants.js'; diff --git a/src/packages/user/current-user/conditions/is-admin/is-admin.condition.manifest.ts b/src/packages/user/current-user/conditions/is-admin/is-admin.condition.manifest.ts new file mode 100644 index 0000000000..b9c81293e0 --- /dev/null +++ b/src/packages/user/current-user/conditions/is-admin/is-admin.condition.manifest.ts @@ -0,0 +1,9 @@ +import { UMB_CURRENT_USER_IS_ADMIN_CONDITION_ALIAS } from './constants.js'; +import type { ManifestCondition } from '@umbraco-cms/backoffice/extension-api'; + +export const manifest: ManifestCondition = { + type: 'condition', + name: 'Current user is admin Condition', + alias: UMB_CURRENT_USER_IS_ADMIN_CONDITION_ALIAS, + api: () => import('./is-admin.condition.js'), +}; diff --git a/src/packages/user/current-user/conditions/is-admin/is-admin.condition.ts b/src/packages/user/current-user/conditions/is-admin/is-admin.condition.ts new file mode 100644 index 0000000000..438258d6f4 --- /dev/null +++ b/src/packages/user/current-user/conditions/is-admin/is-admin.condition.ts @@ -0,0 +1,20 @@ +import { isCurrentUserAnAdmin } from '../../utils/is-current-user.function.js'; +import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; +import type { + UmbConditionConfigBase, + UmbConditionControllerArguments, + UmbExtensionCondition, +} from '@umbraco-cms/backoffice/extension-api'; +import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry'; + +export class UmbContentHasPropertiesWorkspaceCondition + extends UmbConditionBase + implements UmbExtensionCondition +{ + constructor(host: UmbControllerHost, args: UmbConditionControllerArguments) { + super(host, args); + isCurrentUserAnAdmin(host).then((isAdmin) => (this.permitted = isAdmin)); + } +} + +export { UmbContentHasPropertiesWorkspaceCondition as api }; diff --git a/src/packages/user/current-user/conditions/manifests.ts b/src/packages/user/current-user/conditions/manifests.ts new file mode 100644 index 0000000000..63918c839e --- /dev/null +++ b/src/packages/user/current-user/conditions/manifests.ts @@ -0,0 +1,3 @@ +import { manifest as isAdminManifests } from './is-admin/is-admin.condition.manifest.js'; + +export const manifests = [isAdminManifests]; diff --git a/src/packages/user/current-user/manifests.ts b/src/packages/user/current-user/manifests.ts index dce911901e..32ebb91d36 100644 --- a/src/packages/user/current-user/manifests.ts +++ b/src/packages/user/current-user/manifests.ts @@ -1,11 +1,13 @@ import { manifest as actionDefaultKindManifest } from './action/default.kind.js'; -import { manifests as modalManifests } from './modals/manifests.js'; -import { manifests as historyManifests } from './history/manifests.js'; +import { manifests as conditionManifests } from './conditions/manifests.js'; import { manifests as externalLoginProviderManifests } from './external-login/manifests.js'; +import { manifests as historyManifests } from './history/manifests.js'; import { manifests as mfaLoginProviderManifests } from './mfa-login/manifests.js'; +import { manifests as modalManifests } from './modals/manifests.js'; import { manifests as profileManifests } from './profile/manifests.js'; -import { manifests as themeManifests } from './theme/manifests.js'; import { manifests as repositoryManifests } from './repository/manifests.js'; +import { manifests as themeManifests } from './theme/manifests.js'; + import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry'; export const headerApps: Array = [ @@ -21,19 +23,15 @@ export const headerApps: Array = [ name: 'Current User', element: () => import('./current-user-header-app.element.js'), weight: 0, - meta: { - label: 'TODO: how should we enable this to not be set.', - icon: 'TODO: how should we enable this to not be set.', - pathname: 'user', - }, }, ]; export const manifests = [ actionDefaultKindManifest, + ...conditionManifests, + ...externalLoginProviderManifests, ...headerApps, ...historyManifests, - ...externalLoginProviderManifests, ...mfaLoginProviderManifests, ...modalManifests, ...profileManifests, From 7e8860ad135a700aa6dd2498010bbeaf8a24917c Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 10 Sep 2024 15:01:55 +0200 Subject: [PATCH 07/15] export condition alias --- src/packages/user/current-user/conditions/index.ts | 1 + src/packages/user/current-user/index.ts | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 src/packages/user/current-user/conditions/index.ts diff --git a/src/packages/user/current-user/conditions/index.ts b/src/packages/user/current-user/conditions/index.ts new file mode 100644 index 0000000000..8e80a3f329 --- /dev/null +++ b/src/packages/user/current-user/conditions/index.ts @@ -0,0 +1 @@ +export * from './is-admin/index.js'; diff --git a/src/packages/user/current-user/index.ts b/src/packages/user/current-user/index.ts index 343c0ed765..606a128e69 100644 --- a/src/packages/user/current-user/index.ts +++ b/src/packages/user/current-user/index.ts @@ -1,9 +1,10 @@ export * from './action/index.js'; export * from './components/index.js'; -export * from './history/current-user-history.store.js'; -export * from './utils/index.js'; -export * from './repository/index.js'; +export * from './conditions/index.js'; export * from './current-user.context.js'; export * from './current-user.context.token.js'; +export * from './history/current-user-history.store.js'; +export * from './repository/index.js'; +export * from './utils/index.js'; export type * from './types.js'; From f1c50d07c97f9e73e0f200553b00f13bd96249a2 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 10 Sep 2024 15:02:09 +0200 Subject: [PATCH 08/15] add conditions to links --- src/packages/help/menu/manifests.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/packages/help/menu/manifests.ts b/src/packages/help/menu/manifests.ts index 4d9985a5b5..aa4b9d68c9 100644 --- a/src/packages/help/menu/manifests.ts +++ b/src/packages/help/menu/manifests.ts @@ -1,4 +1,5 @@ import { UMB_HELP_MENU_ALIAS } from './constants.js'; +import { UMB_CURRENT_USER_IS_ADMIN_CONDITION_ALIAS } from '@umbraco-cms/backoffice/current-user'; import type { ManifestTypes, UmbBackofficeManifestKind } from '@umbraco-cms/backoffice/extension-registry'; export const manifests: Array = [ @@ -19,6 +20,11 @@ export const manifests: Array = [ icon: 'icon-movie-alt', href: 'https://learn.umbraco.com', }, + conditions: [ + { + alias: UMB_CURRENT_USER_IS_ADMIN_CONDITION_ALIAS, + }, + ], }, { type: 'menuItem', @@ -32,5 +38,10 @@ export const manifests: Array = [ icon: 'icon-hearts', href: 'https://our.umbraco.com', }, + conditions: [ + { + alias: UMB_CURRENT_USER_IS_ADMIN_CONDITION_ALIAS, + }, + ], }, ]; From 41c0d7016e3914d5f777fc0aa41dc30dfd05e002 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 10 Sep 2024 15:54:25 +0200 Subject: [PATCH 09/15] update links --- src/packages/help/menu/manifests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/packages/help/menu/manifests.ts b/src/packages/help/menu/manifests.ts index aa4b9d68c9..ee466c9a80 100644 --- a/src/packages/help/menu/manifests.ts +++ b/src/packages/help/menu/manifests.ts @@ -18,7 +18,7 @@ export const manifests: Array = [ menus: [UMB_HELP_MENU_ALIAS], label: 'Umbraco Learning Base', icon: 'icon-movie-alt', - href: 'https://learn.umbraco.com', + href: 'https://umbra.co/ulb', }, conditions: [ { @@ -36,7 +36,7 @@ export const manifests: Array = [ menus: [UMB_HELP_MENU_ALIAS], label: 'Community Website', icon: 'icon-hearts', - href: 'https://our.umbraco.com', + href: 'https://our.umbraco.com?utm_source=core&utm_medium=help&utm_content=link&utm_campaign=our', }, conditions: [ { From 6f5474851f307f7c657f1daf7dd246cc4f1834aa Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 11 Sep 2024 10:34:20 +0200 Subject: [PATCH 10/15] add help module --- package-lock.json | 4 ++-- package.json | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 826baef473..434bbdb8ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@umbraco-cms/backoffice", - "version": "14.3.0", + "version": "15.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@umbraco-cms/backoffice", - "version": "14.3.0", + "version": "15.0.0", "license": "MIT", "workspaces": [ "./src/packages/block", diff --git a/package.json b/package.json index 075d0e1d0a..9e7ba1eee0 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "./entity": "./dist-cms/packages/core/entity/index.js", "./event": "./dist-cms/packages/core/event/index.js", "./extension-registry": "./dist-cms/packages/core/extension-registry/index.js", + "./help": "./dist-cms/packages/core/help/index.js", "./icon": "./dist-cms/packages/core/icon-registry/index.js", "./id": "./dist-cms/packages/core/id/index.js", "./imaging": "./dist-cms/packages/media/imaging/index.js", From b949c32f2b04aabb38f6d98c337ae726f2b06336 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 11 Sep 2024 10:34:29 +0200 Subject: [PATCH 11/15] export alias --- src/packages/help/index.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/packages/help/index.ts diff --git a/src/packages/help/index.ts b/src/packages/help/index.ts new file mode 100644 index 0000000000..f15384a062 --- /dev/null +++ b/src/packages/help/index.ts @@ -0,0 +1 @@ +export * from './menu/index.js'; From 0bda6b1e45211829ade7ded911cd43a941f9a02f Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 11 Sep 2024 10:34:45 +0200 Subject: [PATCH 12/15] Update tsconfig.json --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index 1d69cbe783..89fcb27d48 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -67,6 +67,7 @@ DON'T EDIT THIS FILE DIRECTLY. It is generated by /devops/tsconfig/index.js "@umbraco-cms/backoffice/entity": ["./src/packages/core/entity/index.ts"], "@umbraco-cms/backoffice/event": ["./src/packages/core/event/index.ts"], "@umbraco-cms/backoffice/extension-registry": ["./src/packages/core/extension-registry/index.ts"], + "@umbraco-cms/backoffice/help": ["./src/packages/core/help/index.ts"], "@umbraco-cms/backoffice/icon": ["./src/packages/core/icon-registry/index.ts"], "@umbraco-cms/backoffice/id": ["./src/packages/core/id/index.ts"], "@umbraco-cms/backoffice/imaging": ["./src/packages/media/imaging/index.ts"], From a02863c8bcd2cc0f5ed6252bc3700bbf55178c48 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 11 Sep 2024 12:11:12 +0200 Subject: [PATCH 13/15] only render header app if menu has items --- .../header-app/help-header-app.element.ts | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/packages/help/header-app/help-header-app.element.ts b/src/packages/help/header-app/help-header-app.element.ts index 7b0b767d13..0c8ff69b84 100644 --- a/src/packages/help/header-app/help-header-app.element.ts +++ b/src/packages/help/header-app/help-header-app.element.ts @@ -1,8 +1,9 @@ import { UMB_HELP_MENU_ALIAS } from '../menu/index.js'; import type { CSSResultGroup } from '@umbraco-cms/backoffice/external/lit'; -import { css, html, customElement, state } from '@umbraco-cms/backoffice/external/lit'; +import { css, html, customElement, state, nothing } from '@umbraco-cms/backoffice/external/lit'; import { UmbHeaderAppButtonElement } from '@umbraco-cms/backoffice/components'; -import type { ManifestMenu } from '@umbraco-cms/backoffice/extension-registry'; +import { umbExtensionsRegistry, type ManifestMenu } from '@umbraco-cms/backoffice/extension-registry'; +import { UmbExtensionsManifestInitializer } from '@umbraco-cms/backoffice/extension-api'; const elementName = 'umb-help-header-app'; @customElement(elementName) @@ -10,6 +11,24 @@ export class UmbHelpHeaderAppElement extends UmbHeaderAppButtonElement { @state() private _popoverOpen = false; + @state() + private _helpMenuHasMenuItems = false; + + constructor() { + super(); + + new UmbExtensionsManifestInitializer( + this, + umbExtensionsRegistry, + 'menuItem', + (manifest) => manifest.meta.menus.includes(UMB_HELP_MENU_ALIAS), + (menuItems) => { + const manifests = menuItems.map((menuItem) => menuItem.manifest); + this._helpMenuHasMenuItems = manifests.length > 0; + }, + ); + } + #onPopoverToggle(event: ToggleEvent) { // TODO: This ignorer is just neede for JSON SCHEMA TO WORK, As its not updated with latest TS jet. // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -18,11 +37,21 @@ export class UmbHelpHeaderAppElement extends UmbHeaderAppButtonElement { } override render() { + return html` ${this.#renderButton()} ${this.#renderPopover()} `; + } + + #renderButton() { + if (!this._helpMenuHasMenuItems) return nothing; + return html` + `; + } + #renderPopover() { + return html` From 591b07e2e1d17da7a46b01b0dc967ee14f567c1c Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 11 Sep 2024 12:19:56 +0200 Subject: [PATCH 14/15] update package build --- package.json | 2 +- src/packages/help/package.json | 8 ++++++++ src/packages/help/vite.config.ts | 2 +- tsconfig.json | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/packages/help/package.json diff --git a/package.json b/package.json index cefbbb4419..a522d9d100 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "./entity": "./dist-cms/packages/core/entity/index.js", "./event": "./dist-cms/packages/core/event/index.js", "./extension-registry": "./dist-cms/packages/core/extension-registry/index.js", - "./help": "./dist-cms/packages/core/help/index.js", + "./help": "./dist-cms/packages/help/index.js", "./icon": "./dist-cms/packages/core/icon-registry/index.js", "./id": "./dist-cms/packages/core/id/index.js", "./imaging": "./dist-cms/packages/media/imaging/index.js", diff --git a/src/packages/help/package.json b/src/packages/help/package.json new file mode 100644 index 0000000000..3cae8e94ec --- /dev/null +++ b/src/packages/help/package.json @@ -0,0 +1,8 @@ +{ + "name": "@umbraco-backoffice/help", + "private": true, + "type": "module", + "scripts": { + "build": "vite build" + } +} \ No newline at end of file diff --git a/src/packages/help/vite.config.ts b/src/packages/help/vite.config.ts index a320e9a053..965d250b98 100644 --- a/src/packages/help/vite.config.ts +++ b/src/packages/help/vite.config.ts @@ -8,5 +8,5 @@ const dist = '../../../dist-cms/packages/help'; rmSync(dist, { recursive: true, force: true }); export default defineConfig({ - ...getDefaultConfig({ dist, entry: ['manifests.ts', 'umbraco-package.ts'] }), + ...getDefaultConfig({ dist }), }); diff --git a/tsconfig.json b/tsconfig.json index 89fcb27d48..7807084b15 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -67,7 +67,7 @@ DON'T EDIT THIS FILE DIRECTLY. It is generated by /devops/tsconfig/index.js "@umbraco-cms/backoffice/entity": ["./src/packages/core/entity/index.ts"], "@umbraco-cms/backoffice/event": ["./src/packages/core/event/index.ts"], "@umbraco-cms/backoffice/extension-registry": ["./src/packages/core/extension-registry/index.ts"], - "@umbraco-cms/backoffice/help": ["./src/packages/core/help/index.ts"], + "@umbraco-cms/backoffice/help": ["./src/packages/help/index.ts"], "@umbraco-cms/backoffice/icon": ["./src/packages/core/icon-registry/index.ts"], "@umbraco-cms/backoffice/id": ["./src/packages/core/id/index.ts"], "@umbraco-cms/backoffice/imaging": ["./src/packages/media/imaging/index.ts"], From ca9728d5709f5513c4de445e2a78f08dd5738be6 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 11 Sep 2024 12:38:12 +0200 Subject: [PATCH 15/15] Update package-lock.json --- package-lock.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 5005f8e5d4..14b88b3569 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7811,6 +7811,10 @@ "resolved": "src/packages/health-check", "link": true }, + "node_modules/@umbraco-backoffice/help": { + "resolved": "src/packages/help", + "link": true + }, "node_modules/@umbraco-backoffice/language": { "resolved": "src/packages/language", "link": true @@ -23078,6 +23082,7 @@ "src/packages/health-check": { "name": "@umbraco-backoffice/health-check" }, + "src/packages/help": {}, "src/packages/language": { "name": "@umbraco-backoffice/language" }, @@ -23120,7 +23125,9 @@ "src/packages/static-file": { "name": "@umbraco-backoffice/static-file" }, - "src/packages/sysinfo": {}, + "src/packages/sysinfo": { + "name": "@umbraco-backoffice/sysinfo" + }, "src/packages/tags": { "name": "@umbraco-backoffice/tag" },