diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/create-empty.action.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/create-empty.action.ts deleted file mode 100644 index f6103963d6..0000000000 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/create-empty.action.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'; -import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; - -export class UmbCreateScriptAction }> extends UmbEntityActionBase { - constructor(host: UmbControllerHostElement, repositoryAlias: string, unique: string) { - super(host, repositoryAlias, unique); - } - - async execute() { - if (this.unique !== null) { - // Note: %2F is a slash (/) - this.unique = this.unique.replace(/\//g, '%2F'); - } - - history.pushState(null, '', `section/settings/workspace/script/create/${this.unique ?? 'null'}`); - } -} diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/create.action.ts new file mode 100644 index 0000000000..67e3de6dba --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/create.action.ts @@ -0,0 +1,27 @@ +import { UMB_SCRIPT_CREATE_OPTIONS_MODAL } from './options-modal/index.js'; +import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'; +import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; +import { UmbModalManagerContext, UMB_MODAL_MANAGER_CONTEXT_TOKEN } from '@umbraco-cms/backoffice/modal'; + +export class UmbScriptCreateOptionsEntityAction extends UmbEntityActionBase { + #modalManagerContext?: UmbModalManagerContext; + + constructor(host: UmbControllerHostElement, repositoryAlias: string, unique: string) { + super(host, repositoryAlias, unique); + + this.consumeContext(UMB_MODAL_MANAGER_CONTEXT_TOKEN, (instance) => { + this.#modalManagerContext = instance; + }); + } + + async execute() { + if (!this.#modalManagerContext) throw new Error('Modal manager context is not available'); + if (!this.repository) throw new Error('Repository is not available'); + + this.#modalManagerContext?.open(UMB_SCRIPT_CREATE_OPTIONS_MODAL, { + data: { + parentUnique: this.unique, + }, + }); + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/manifests.ts new file mode 100644 index 0000000000..1d2209278e --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/manifests.ts @@ -0,0 +1,26 @@ +import { UMB_SCRIPT_FOLDER_ENTITY_TYPE, UMB_SCRIPT_ROOT_ENTITY_TYPE } from '../../entity.js'; +import { UMB_SCRIPT_DETAIL_REPOSITORY_ALIAS } from '../../repository/manifests.js'; +import { UmbScriptCreateOptionsEntityAction } from './create.action.js'; +import { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry'; + +export const manifests: Array = [ + { + type: 'entityAction', + alias: 'Umb.EntityAction.Script.CreateOptions', + name: 'Script Create Options Entity Action', + weight: 1000, + api: UmbScriptCreateOptionsEntityAction, + meta: { + icon: 'icon-add', + label: 'Create...', + repositoryAlias: UMB_SCRIPT_DETAIL_REPOSITORY_ALIAS, + entityTypes: [UMB_SCRIPT_ROOT_ENTITY_TYPE, UMB_SCRIPT_FOLDER_ENTITY_TYPE], + }, + }, + { + type: 'modal', + alias: 'Umb.Modal.Script.CreateOptions', + name: 'Script Create Options Modal', + js: () => import('./options-modal/script-create-options-modal.element.js'), + }, +]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/options-modal/index.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/options-modal/index.ts new file mode 100644 index 0000000000..f3b3126bb7 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/options-modal/index.ts @@ -0,0 +1,15 @@ +import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; + +export interface UmbScriptCreateOptionsModalData { + parentUnique: string | null; +} + +export const UMB_SCRIPT_CREATE_OPTIONS_MODAL = new UmbModalToken( + 'Umb.Modal.Script.CreateOptions', + { + modal: { + type: 'sidebar', + size: 'small', + }, + }, +); diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/options-modal/script-create-options-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/options-modal/script-create-options-modal.element.ts new file mode 100644 index 0000000000..ebf1dde004 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/options-modal/script-create-options-modal.element.ts @@ -0,0 +1,84 @@ +import { UMB_SCRIPT_FOLDER_REPOSITORY_ALIAS } from '../../../tree/folder/index.js'; +import { UmbScriptCreateOptionsModalData } from './index.js'; +import { html, customElement } from '@umbraco-cms/backoffice/external/lit'; +import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; +import { + UMB_MODAL_MANAGER_CONTEXT_TOKEN, + UmbModalManagerContext, + UmbModalBaseElement, +} from '@umbraco-cms/backoffice/modal'; +import { UmbCreateFolderEntityAction } from '@umbraco-cms/backoffice/tree'; + +@customElement('umb-script-create-options-modal') +export class UmbScriptCreateOptionsModalElement extends UmbModalBaseElement { + #modalManager?: UmbModalManagerContext; + #createFolderAction?: UmbCreateFolderEntityAction; + + constructor() { + super(); + + this.consumeContext(UMB_MODAL_MANAGER_CONTEXT_TOKEN, (instance) => { + this.#modalManager = instance; + }); + } + + connectedCallback(): void { + super.connectedCallback(); + + if (this.data?.parentUnique === undefined) throw new Error('A parent unique is required to create a folder'); + + this.#createFolderAction = new UmbCreateFolderEntityAction( + this, + UMB_SCRIPT_FOLDER_REPOSITORY_ALIAS, + this.data.parentUnique, + ); + } + + async #onCreateFolderClick(event: PointerEvent) { + event.stopPropagation(); + + try { + await this.#createFolderAction?.execute(); + this._submitModal(); + } catch (error) { + console.error(error); + } + } + + // close the modal when navigating to data type + #onNavigate() { + this._submitModal(); + } + + render() { + return html` + + + + + } + + + + } + + + + Cancel + + `; + } + + static styles = [UmbTextStyles]; +} + +export default UmbScriptCreateOptionsModalElement; + +declare global { + interface HTMLElementTagNameMap { + 'umb-script-create-options-modal': UmbScriptCreateOptionsModalElement; + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/manifests.ts index 28bd08fd8f..a8f9b9afb6 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/manifests.ts @@ -1,11 +1,10 @@ import { UMB_SCRIPT_DETAIL_REPOSITORY_ALIAS } from '../repository/index.js'; -import { UMB_SCRIPT_ENTITY_TYPE, UMB_SCRIPT_FOLDER_ENTITY_TYPE, UMB_SCRIPT_ROOT_ENTITY_TYPE } from '../entity.js'; -import { UmbCreateScriptAction } from './create/create-empty.action.js'; +import { UMB_SCRIPT_ENTITY_TYPE } from '../entity.js'; +import { manifests as createManifests } from './create/manifests.js'; import { UmbDeleteEntityAction } from '@umbraco-cms/backoffice/entity-action'; import { ManifestEntityAction } from '@umbraco-cms/backoffice/extension-registry'; export const UMB_DELETE_SCRIPT_ENTITY_ACTION_ALIAS = 'Umb.EntityAction.Script.Delete'; -export const UMB_CREATE_SCRIPT_ENTITY_ACTION_ALIAS = 'Umb.EntityAction.Script.Create'; const scriptViewActions: Array = [ { @@ -22,19 +21,4 @@ const scriptViewActions: Array = [ }, ]; -const scriptFolderActions: Array = [ - { - type: 'entityAction', - alias: UMB_CREATE_SCRIPT_ENTITY_ACTION_ALIAS, - name: 'Create Script Under Directory Entity Action', - api: UmbCreateScriptAction, - meta: { - icon: 'icon-article', - label: 'New empty script', - repositoryAlias: UMB_SCRIPT_DETAIL_REPOSITORY_ALIAS, - entityTypes: [UMB_SCRIPT_FOLDER_ENTITY_TYPE, UMB_SCRIPT_ROOT_ENTITY_TYPE], - }, - }, -]; - -export const manifests = [...scriptViewActions, ...scriptFolderActions]; +export const manifests = [...scriptViewActions, ...createManifests]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/tree/folder/index.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/tree/folder/index.ts index ae1d18208a..83ac344c66 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/tree/folder/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/tree/folder/index.ts @@ -1,6 +1,2 @@ export { UmbScriptFolderRepository } from './script-folder.repository.js'; -export { - UMB_SCRIPT_FOLDER_REPOSITORY_ALIAS, - UMB_DELETE_SCRIPT_FOLDER_ENTITY_ACTION_ALIAS, - UMB_CREATE_SCRIPT_FOLDER_ENTITY_ACTION_ALIAS, -} from './manifests.js'; +export { UMB_SCRIPT_FOLDER_REPOSITORY_ALIAS, UMB_DELETE_SCRIPT_FOLDER_ENTITY_ACTION_ALIAS } from './manifests.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/tree/folder/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/tree/folder/manifests.ts index 017ab70edb..1288d808b2 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/tree/folder/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/tree/folder/manifests.ts @@ -1,6 +1,6 @@ -import { UMB_SCRIPT_FOLDER_ENTITY_TYPE, UMB_SCRIPT_ROOT_ENTITY_TYPE } from '../../entity.js'; +import { UMB_SCRIPT_FOLDER_ENTITY_TYPE } from '../../entity.js'; import { UmbScriptFolderRepository } from './script-folder.repository.js'; -import { UmbCreateFolderEntityAction, UmbDeleteFolderEntityAction } from '@umbraco-cms/backoffice/tree'; +import { UmbDeleteFolderEntityAction } from '@umbraco-cms/backoffice/tree'; import type { ManifestRepository } from '@umbraco-cms/backoffice/extension-registry'; export const UMB_SCRIPT_FOLDER_REPOSITORY_ALIAS = 'Umb.Repository.Script.Folder'; @@ -13,21 +13,8 @@ const folderRepository: ManifestRepository = { }; export const UMB_DELETE_SCRIPT_FOLDER_ENTITY_ACTION_ALIAS = 'Umb.EntityAction.Script.Folder.Delete'; -export const UMB_CREATE_SCRIPT_FOLDER_ENTITY_ACTION_ALIAS = 'Umb.EntityAction.Script.Folder.Create'; const entityActions = [ - { - type: 'entityAction', - alias: UMB_CREATE_SCRIPT_FOLDER_ENTITY_ACTION_ALIAS, - name: 'Create Script folder', - api: UmbCreateFolderEntityAction, - meta: { - icon: 'icon-add', - label: 'Create folder...', - repositoryAlias: UMB_SCRIPT_FOLDER_REPOSITORY_ALIAS, - entityTypes: [UMB_SCRIPT_ROOT_ENTITY_TYPE, UMB_SCRIPT_FOLDER_ENTITY_TYPE], - }, - }, { type: 'entityAction', alias: UMB_DELETE_SCRIPT_FOLDER_ENTITY_ACTION_ALIAS,