diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/delete/delete.action.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/delete/delete.action.ts index 9f6d111f40..2fe29b097d 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/delete/delete.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/delete/delete.action.ts @@ -9,7 +9,7 @@ import { import { UmbDetailRepository, UmbItemRepository } from '@umbraco-cms/backoffice/repository'; export class UmbDeleteEntityAction< - T extends UmbDetailRepository & UmbItemRepository + T extends UmbDetailRepository & UmbItemRepository, > extends UmbEntityActionBase { #modalManager?: UmbModalManagerContext; diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/entity-actions/create/create.action.ts index 981171b665..7eed91c078 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/entity-actions/create/create.action.ts @@ -1,55 +1,16 @@ import { UmbDictionaryRepository } from '../../repository/dictionary.repository.js'; -import { UmbTextStyles } from "@umbraco-cms/backoffice/style"; -import { UmbSectionSidebarContext, UMB_SECTION_SIDEBAR_CONTEXT_TOKEN } from '@umbraco-cms/backoffice/section'; +import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'; import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; -import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api'; -import { - UmbModalManagerContext, - UMB_MODAL_MANAGER_CONTEXT_TOKEN, - UMB_CREATE_DICTIONARY_MODAL, -} from '@umbraco-cms/backoffice/modal'; export default class UmbCreateDictionaryEntityAction extends UmbEntityActionBase { static styles = [UmbTextStyles]; - #modalContext?: UmbModalManagerContext; - - #sectionSidebarContext!: UmbSectionSidebarContext; - constructor(host: UmbControllerHostElement, repositoryAlias: string, unique: string) { super(host, repositoryAlias, unique); - - new UmbContextConsumerController(this.host, UMB_MODAL_MANAGER_CONTEXT_TOKEN, (instance) => { - this.#modalContext = instance; - }); - - new UmbContextConsumerController(this.host, UMB_SECTION_SIDEBAR_CONTEXT_TOKEN, (instance) => { - this.#sectionSidebarContext = instance; - }); } async execute() { - // TODO: what to do if modal service is not available? - if (!this.#modalContext) return; - if (!this.repository) return; - - // TODO: how can we get the current entity detail in the modal? Passing the observable - // feels a bit hacky. Works, but hacky. - const modalContext = this.#modalContext?.open(UMB_CREATE_DICTIONARY_MODAL, { - parentId: this.unique, - parentName: this.#sectionSidebarContext.headline, - }); - - const { name, parentId } = await modalContext.onSubmit(); - if (!name || parentId === undefined) return; - - const { data: url } = await this.repository.create({ name, parentId }); - if (!url) return; - - //TODO: Why do we need to extract the id like this? - const id = url.substring(url.lastIndexOf('/') + 1); - - history.pushState({}, '', `/section/dictionary/workspace/dictionary-item/edit/${id}`); + history.pushState({}, '', `/section/dictionary/workspace/dictionary-item/create/${this.unique ?? 'null'}`); } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/repository/dictionary.repository.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/repository/dictionary.repository.ts index 892ef11790..cde5cfd399 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/repository/dictionary.repository.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/repository/dictionary.repository.ts @@ -110,6 +110,19 @@ export class UmbDictionaryRepository return { data, error, asObservable: () => this.#treeStore!.items(ids) }; } + async requestItems(ids: Array) { + if (!ids) throw new Error('Dictionary Ids are missing'); + await this.#init; + + const { data, error } = await this.#treeSource.getItems(ids); + + if (data) { + this.#treeStore?.appendItems(data); + } + + return { data, error, asObservable: () => this.#treeStore!.items(ids) }; + } + async rootTreeItems() { await this.#init; return this.#treeStore!.rootItems; diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/workspace/dictionary-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/workspace/dictionary-workspace.context.ts index 6e762a44fe..a343cb0aeb 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/workspace/dictionary-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/workspace/dictionary-workspace.context.ts @@ -68,9 +68,8 @@ export class UmbDictionaryWorkspaceContext const { data } = await this.repository.createScaffold(parentId); if (!data) return; this.setIsNew(true); - // TODO: This is a hack to get around the fact that the data is not typed correctly. - // Create and response models are different. We need to look into this. - this.#data.next(data as unknown as DictionaryItemResponseModel); + + this.#data.next(data as DictionaryItemResponseModel); } async save() { diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/workspace/dictionary-workspace.element.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/workspace/dictionary-workspace.element.ts index 99b9099679..20bdb7706a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/workspace/dictionary-workspace.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/dictionary/workspace/dictionary-workspace.element.ts @@ -4,6 +4,7 @@ import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import { html, customElement, state } from '@umbraco-cms/backoffice/external/lit'; import type { UmbRoute } from '@umbraco-cms/backoffice/router'; import { UmbLitElement } from '@umbraco-cms/internal/lit-element'; +import { UmbWorkspaceIsNewRedirectController } from '@umbraco-cms/backoffice/workspace'; @customElement('umb-dictionary-workspace') export class UmbWorkspaceDictionaryElement extends UmbLitElement { @@ -23,9 +24,16 @@ export class UmbWorkspaceDictionaryElement extends UmbLitElement { { path: 'create/:parentId', component: () => this.#element, - setup: (_component, info) => { + setup: async (_component, info) => { const parentId = info.match.params.parentId === 'null' ? null : info.match.params.parentId; this.#workspaceContext.create(parentId); + await this.#workspaceContext.create(parentId); + + new UmbWorkspaceIsNewRedirectController( + this, + this.#workspaceContext, + this.shadowRoot!.querySelector('umb-router-slot')!, + ); }, }, ];