diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/export/export.action.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/export/export.action.ts index 58502935a1..c0f21cefb6 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/export/export.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/export/export.action.ts @@ -27,7 +27,7 @@ export default class UmbExportDictionaryEntityAction extends UmbEntityActionBase const { includeChildren } = await modalContext.onSubmit(); // Export the file - const result = await this.repository?.export(this.unique, includeChildren); + const result = await this.repository?.requestExport(this.unique, includeChildren); const blobContent = await result?.data; if (!blobContent) return; diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/import/import-dictionary-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/import/import-dictionary-modal.element.ts index 430b67c38a..412fdf957e 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/import/import-dictionary-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/import/import-dictionary-modal.element.ts @@ -1,16 +1,11 @@ import { UMB_DICTIONARY_TREE_ALIAS } from '../../tree/manifests.js'; import { UmbDictionaryImportRepository } from '../../repository/index.js'; -import { UMB_DICTIONARY_ENTITY_TYPE } from '../../entity.js'; import type { UmbImportDictionaryModalData, UmbImportDictionaryModalValue } from './import-dictionary-modal.token.js'; import { css, html, customElement, query, state, when } from '@umbraco-cms/backoffice/external/lit'; import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'; import { UmbId } from '@umbraco-cms/backoffice/id'; -import type { - UmbEntityTreeItemModel, - UmbTreeElement, - UmbTreeSelectionConfiguration, -} from '@umbraco-cms/backoffice/tree'; +import type { UmbTreeElement, UmbTreeSelectionConfiguration } from '@umbraco-cms/backoffice/tree'; import { UmbTemporaryFileRepository } from '@umbraco-cms/backoffice/temporary-file'; interface UmbDictionaryItemPreview { @@ -32,7 +27,7 @@ export class UmbImportDictionaryModalLayout extends UmbModalBaseElement< }; @state() - private _parentId?: string; + private _parentUnique: string | null = null; @state() private _temporaryFileId = ''; @@ -64,42 +59,16 @@ export class UmbImportDictionaryModalLayout extends UmbModalBaseElement< connectedCallback(): void { super.connectedCallback(); - this._parentId = this.data?.unique ?? undefined; - this._selectionConfiguration.selection = this._parentId ? [this._parentId] : []; - } - - #handleClose() { - this.modalContext?.reject(); - } - - #createTreeEntitiesFromTempFile(): Array { - const data: Array = []; - - const list = this.#dictionaryPreviewItemBuilder(this.#fileNodes); - const scaffold = (items: Array, parentId?: string) => { - items.forEach((item) => { - data.push({ - id: item.id, - name: item.name, - entityType: UMB_DICTIONARY_ENTITY_TYPE, - hasChildren: item.children.length ? true : false, - parentId: parentId || null, - isFolder: false, - }); - scaffold(item.children, item.id); - }); - }; - - scaffold(list, this._parentId); - return data; + this._parentUnique = this.data?.unique ?? null; + this._selectionConfiguration.selection = this._parentUnique ? [this._parentUnique] : []; } async #submit() { - const { error } = await this.#dictionaryImportRepository.import(this._temporaryFileId, this._parentId); + const { error } = await this.#dictionaryImportRepository.requestImport(this._temporaryFileId, this._parentUnique); + debugger; if (error) return; - this.value = { entityItems: this.#createTreeEntitiesFromTempFile(), parentId: this._parentId }; - this.modalContext?.submit(); + this._submitModal(); } #dictionaryPreviewBuilder(htmlString: string) { @@ -145,7 +114,7 @@ export class UmbImportDictionaryModalLayout extends UmbModalBaseElement< } #onParentChange() { - this._parentId = this._treeElement?.getSelection()[0] ?? undefined; + this._parentUnique = this._treeElement?.getSelection()[0] ?? null; } async #onFileInput() { @@ -171,7 +140,7 @@ export class UmbImportDictionaryModalLayout extends UmbModalBaseElement< slot="actions" type="button" label=${this.localize.term('general_cancel')} - @click=${this.#handleClose}> + @click=${this._rejectModal}> `; } diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/import/import-dictionary-modal.token.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/import/import-dictionary-modal.token.ts index 1d4dfec98f..2143169632 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/import/import-dictionary-modal.token.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/entity-action/import/import-dictionary-modal.token.ts @@ -1,14 +1,10 @@ import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; -import type { UmbEntityTreeItemModel } from '@umbraco-cms/backoffice/tree'; export interface UmbImportDictionaryModalData { unique: string | null; } -export interface UmbImportDictionaryModalValue { - entityItems: Array; - parentId?: string; -} +export interface UmbImportDictionaryModalValue {} export const UMB_IMPORT_DICTIONARY_MODAL = new UmbModalToken< UmbImportDictionaryModalData, diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/export/dictionary-export.repository.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/export/dictionary-export.repository.ts index f6089f0882..76412696b3 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/export/dictionary-export.repository.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/export/dictionary-export.repository.ts @@ -17,7 +17,7 @@ export class UmbDictionaryExportRepository extends UmbRepositoryBase { * @return {*} * @memberof UmbDictionaryExportRepository */ - async export(unique: string, includeChildren = false) { + async requestExport(unique: string, includeChildren = false) { if (!unique) { throw new Error('Unique is missing'); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/import/dictionary-import.repository.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/import/dictionary-import.repository.ts index 11759ed7a6..6ddc71e2c2 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/import/dictionary-import.repository.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/import/dictionary-import.repository.ts @@ -1,13 +1,16 @@ +import { UmbDictionaryDetailRepository } from '../detail/index.js'; import { UmbDictionaryImportServerDataSource } from './dictionary-import.server.data-source.js'; import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; export class UmbDictionaryImportRepository extends UmbRepositoryBase { #importSource: UmbDictionaryImportServerDataSource; + #detailRepository: UmbDictionaryDetailRepository; constructor(host: UmbControllerHost) { super(host); this.#importSource = new UmbDictionaryImportServerDataSource(host); + this.#detailRepository = new UmbDictionaryDetailRepository(host); } /** @@ -17,10 +20,17 @@ export class UmbDictionaryImportRepository extends UmbRepositoryBase { * @return {*} * @memberof UmbDictionaryImportRepository */ - import(temporaryFileUnique: string, parentUnique: string | null) { + async requestImport(temporaryFileUnique: string, parentUnique: string | null) { if (!temporaryFileUnique) throw new Error('Temporary file unique is missing'); if (parentUnique === undefined) throw new Error('Parent unique is missing'); - return this.#importSource.import(temporaryFileUnique, parentUnique); + const { data, error } = await this.#importSource.import(temporaryFileUnique, parentUnique); + + if (data) { + // Request the detail for the imported dictionary. This will also append it to the detail store + return this.#detailRepository.requestByUnique(data); + } + + return { data, error }; } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/import/dictionary-import.server.data-source.ts b/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/import/dictionary-import.server.data-source.ts index d0214c07ce..9623603d81 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/import/dictionary-import.server.data-source.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/dictionary/repository/import/dictionary-import.server.data-source.ts @@ -17,7 +17,7 @@ export class UmbDictionaryImportServerDataSource { * @returns {*} * @memberof UmbDictionaryImportServerDataSource */ - import(temporaryFileUnique: string, parentUnique: string | null) { + async import(temporaryFileUnique: string, parentUnique: string | null) { if (!temporaryFileUnique) throw new Error('temporaryFileUnique is required'); if (parentUnique === undefined) throw new Error('parentUnique is required');