From 45ec4e0224e9e1ada0bb52dca215999ed6dad645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20M=C3=B8ller=20Jensen?= <26099018+JesmoDev@users.noreply.github.com> Date: Mon, 12 Jun 2023 14:58:35 +1200 Subject: [PATCH 1/7] update create --- .../modal/token/create-dictionary-modal.token.ts | 1 + .../dashboard-translation-dictionary.element.ts | 14 +++++++++----- .../create-dictionary-modal-layout.element.ts | 4 +++- .../entity-actions/create/create.action.ts | 12 +++++++----- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/modal/token/create-dictionary-modal.token.ts b/src/Umbraco.Web.UI.Client/src/packages/core/modal/token/create-dictionary-modal.token.ts index cd2823651e..62dd3f787c 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/modal/token/create-dictionary-modal.token.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/modal/token/create-dictionary-modal.token.ts @@ -8,6 +8,7 @@ export interface UmbCreateDictionaryModalData { export interface UmbCreateDictionaryModalResult { name?: string; + parentId?: string; } export const UMB_CREATE_DICTIONARY_MODAL = new UmbModalToken< diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts index 0da96591f0..8f04a03911 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts @@ -10,6 +10,7 @@ import { UMB_CREATE_DICTIONARY_MODAL, } from '@umbraco-cms/backoffice/modal'; import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api'; +import { log } from '@openid/appauth'; @customElement('umb-dashboard-translation-dictionary') export class UmbDashboardTranslationDictionaryElement extends UmbLitElement { @@ -136,13 +137,16 @@ export class UmbDashboardTranslationDictionaryElement extends UmbLitElement { const modalContext = this.#modalContext?.open(UMB_CREATE_DICTIONARY_MODAL, { unique: null }); - // TODO: get type from modal result - const { name } = await modalContext.onSubmit(); + const { name, parentId } = await modalContext.onSubmit(); if (!name) return; - const { data } = await this.#repo.createScaffold(null); - console.log(data); - // TODO => get location header to route to new item + const { data: url } = await this.#repo.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/translation/workspace/dictionary-item/edit/${id}`); } render() { diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create-dictionary-modal-layout.element.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create-dictionary-modal-layout.element.ts index 7fb155aa05..9fdb3ab7ea 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create-dictionary-modal-layout.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create-dictionary-modal-layout.element.ts @@ -36,9 +36,11 @@ export class UmbCreateDictionaryModalElement extends UmbModalBaseElement< if (!form || !form.checkValidity()) return; const formData = new FormData(form); + const name = formData.get('name') as string; this.modalContext?.submit({ - name: formData.get('name') as string, + name, + parentId: this.data?.unique ?? undefined, }); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts index 42b975382c..be7d31b0e5 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts @@ -44,13 +44,15 @@ export default class UmbCreateDictionaryEntityAction extends UmbEntityActionBase parentName: this.#sectionSidebarContext.headline, }); - // TODO: get type from modal result - const { name } = await modalContext.onSubmit(); + const { name, parentId } = await modalContext.onSubmit(); if (!name) return; - const { data } = await this.repository.createScaffold(this.unique, { name }); + const { data: url } = await this.repository.create({ name, parentId }); + if (!url) return; - // TODO => get location header to route to new item - console.log(data); + //TODO: Why do we need to extract the id like this? + const id = url.substring(url.lastIndexOf('/') + 1); + + history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${id}`); } } From b5458cfe0a1fb45238080bbb2965b7054c19a4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20M=C3=B8ller=20Jensen?= <26099018+JesmoDev@users.noreply.github.com> Date: Mon, 12 Jun 2023 15:07:59 +1200 Subject: [PATCH 2/7] cleanup --- .../dictionary/dashboard-translation-dictionary.element.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts index 8f04a03911..20b9912640 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts @@ -10,7 +10,6 @@ import { UMB_CREATE_DICTIONARY_MODAL, } from '@umbraco-cms/backoffice/modal'; import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api'; -import { log } from '@openid/appauth'; @customElement('umb-dashboard-translation-dictionary') export class UmbDashboardTranslationDictionaryElement extends UmbLitElement { From 4ddb3ed9d364d779b23e18a8456f32610fc4ad7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Mon, 12 Jun 2023 09:53:01 +0200 Subject: [PATCH 3/7] correct to use createScaffold --- .../dashboard-translation-dictionary.element.ts | 12 +++++------- .../entity-actions/create/create.action.ts | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts index 20b9912640..bf9ffd0430 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts @@ -137,15 +137,13 @@ export class UmbDashboardTranslationDictionaryElement extends UmbLitElement { const modalContext = this.#modalContext?.open(UMB_CREATE_DICTIONARY_MODAL, { unique: null }); const { name, parentId } = await modalContext.onSubmit(); - if (!name) return; + if (!name || parentId === undefined) return; - const { data: url } = await this.#repo.create({ name, parentId }); - if (!url) return; + const { data } = await this.#repo.createScaffold(parentId); + if (!data) return; - //TODO: Why do we need to extract the id like this? - const id = url.substring(url.lastIndexOf('/') + 1); - - history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${id}`); + // TODO: Temp url construction: + history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${data.id}`); } render() { diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts index be7d31b0e5..846623acba 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts @@ -45,14 +45,12 @@ export default class UmbCreateDictionaryEntityAction extends UmbEntityActionBase }); const { name, parentId } = await modalContext.onSubmit(); - if (!name) return; + if (!name || parentId === undefined) return; - const { data: url } = await this.repository.create({ name, parentId }); - if (!url) return; + const { data } = await this.repository.createScaffold(parentId); + if (!data) return; - //TODO: Why do we need to extract the id like this? - const id = url.substring(url.lastIndexOf('/') + 1); - - history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${id}`); + // TODO: Temp url construction: + history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${data.id}`); } } From 4e576ac8f1b4e4f5f056e680ef29c22f3dc849c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Mon, 12 Jun 2023 10:16:39 +0200 Subject: [PATCH 4/7] refactor --- .../core/modal/token/create-dictionary-modal.token.ts | 6 +++--- .../dictionary/dashboard-translation-dictionary.element.ts | 3 ++- ...layout.element.ts => create-dictionary-modal.element.ts} | 2 +- .../dictionary/entity-actions/create/create.action.ts | 4 ++-- .../translation/dictionary/entity-actions/manifests.ts | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) rename src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/{create-dictionary-modal-layout.element.ts => create-dictionary-modal.element.ts} (98%) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/modal/token/create-dictionary-modal.token.ts b/src/Umbraco.Web.UI.Client/src/packages/core/modal/token/create-dictionary-modal.token.ts index 62dd3f787c..2f9641df86 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/modal/token/create-dictionary-modal.token.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/modal/token/create-dictionary-modal.token.ts @@ -2,13 +2,13 @@ import { Observable } from '@umbraco-cms/backoffice/external/rxjs'; import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; export interface UmbCreateDictionaryModalData { - unique: string | null; + parentId: string | null; parentName?: Observable; } export interface UmbCreateDictionaryModalResult { - name?: string; - parentId?: string; + name: string; + parentId: string | null; } export const UMB_CREATE_DICTIONARY_MODAL = new UmbModalToken< diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts index bf9ffd0430..029d884b38 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts @@ -134,7 +134,8 @@ export class UmbDashboardTranslationDictionaryElement extends UmbLitElement { if (!this.#modalContext) return; if (!this.#repo) return; - const modalContext = this.#modalContext?.open(UMB_CREATE_DICTIONARY_MODAL, { unique: null }); + console.log('open create:'); + const modalContext = this.#modalContext?.open(UMB_CREATE_DICTIONARY_MODAL, { parentId: null }); const { name, parentId } = await modalContext.onSubmit(); if (!name || parentId === undefined) return; diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create-dictionary-modal-layout.element.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create-dictionary-modal.element.ts similarity index 98% rename from src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create-dictionary-modal-layout.element.ts rename to src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create-dictionary-modal.element.ts index 9fdb3ab7ea..d0e56f6016 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create-dictionary-modal-layout.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create-dictionary-modal.element.ts @@ -40,7 +40,7 @@ export class UmbCreateDictionaryModalElement extends UmbModalBaseElement< this.modalContext?.submit({ name, - parentId: this.data?.unique ?? undefined, + parentId: this.data?.parentId ?? null, }); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts index 846623acba..7b3c486288 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts @@ -11,7 +11,7 @@ import { } from '@umbraco-cms/backoffice/modal'; // TODO: temp import -import './create-dictionary-modal-layout.element.js'; +import './create-dictionary-modal.element.js'; export default class UmbCreateDictionaryEntityAction extends UmbEntityActionBase { static styles = [UUITextStyles]; @@ -40,7 +40,7 @@ export default class UmbCreateDictionaryEntityAction extends UmbEntityActionBase // 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, { - unique: this.unique, + parentId: this.unique, parentName: this.#sectionSidebarContext.headline, }); diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/manifests.ts index d281819bbd..e1bfb8c2a8 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/manifests.ts @@ -107,7 +107,7 @@ const modals: Array = [ type: 'modal', alias: 'Umb.Modal.CreateDictionary', name: 'Create Dictionary Modal', - loader: () => import('./create/create-dictionary-modal-layout.element.js'), + loader: () => import('./create/create-dictionary-modal.element.js'), }, { type: 'modal', From d1bcc778863843d5ddba314bcf2b14bd30632860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Mon, 12 Jun 2023 10:21:52 +0200 Subject: [PATCH 5/7] revert to jesper proposal --- .../dashboard-translation-dictionary.element.ts | 11 +++++++---- .../dictionary/entity-actions/create/create.action.ts | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts index 029d884b38..afe3360612 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts @@ -140,11 +140,14 @@ export class UmbDashboardTranslationDictionaryElement extends UmbLitElement { const { name, parentId } = await modalContext.onSubmit(); if (!name || parentId === undefined) return; - const { data } = await this.#repo.createScaffold(parentId); - if (!data) return; + const { data: url } = await this.#repo.create({ name, parentId }); - // TODO: Temp url construction: - history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${data.id}`); + console.log('got url', url); + if (!url) return; + //TODO: Why do we need to extract the id like this? + const id = url.substring(url.lastIndexOf('/') + 1); + + history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${id}`); } render() { diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts index 7b3c486288..009b8cbe8b 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts @@ -47,10 +47,12 @@ export default class UmbCreateDictionaryEntityAction extends UmbEntityActionBase const { name, parentId } = await modalContext.onSubmit(); if (!name || parentId === undefined) return; - const { data } = await this.repository.createScaffold(parentId); - if (!data) return; + const { data: url } = await this.repository.create({ name, parentId }); + if (!url) return; - // TODO: Temp url construction: - history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${data.id}`); + //TODO: Why do we need to extract the id like this? + const id = url.substring(url.lastIndexOf('/') + 1); + + history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${id}`); } } From 81b2156451df79735d6643d9bf5b430dd17a9573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Mon, 12 Jun 2023 10:23:19 +0200 Subject: [PATCH 6/7] remove import --- .../dictionary/entity-actions/create/create.action.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts index 009b8cbe8b..3681664c98 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dictionary/entity-actions/create/create.action.ts @@ -10,9 +10,6 @@ import { UMB_CREATE_DICTIONARY_MODAL, } from '@umbraco-cms/backoffice/modal'; -// TODO: temp import -import './create-dictionary-modal.element.js'; - export default class UmbCreateDictionaryEntityAction extends UmbEntityActionBase { static styles = [UUITextStyles]; From 16b433130ad9c2957844922a335489d53382c9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Mon, 12 Jun 2023 10:31:03 +0200 Subject: [PATCH 7/7] remove logs --- .../dictionary/dashboard-translation-dictionary.element.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts index afe3360612..4154869964 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/translation/dashboards/dictionary/dashboard-translation-dictionary.element.ts @@ -134,7 +134,6 @@ export class UmbDashboardTranslationDictionaryElement extends UmbLitElement { if (!this.#modalContext) return; if (!this.#repo) return; - console.log('open create:'); const modalContext = this.#modalContext?.open(UMB_CREATE_DICTIONARY_MODAL, { parentId: null }); const { name, parentId } = await modalContext.onSubmit(); @@ -142,7 +141,6 @@ export class UmbDashboardTranslationDictionaryElement extends UmbLitElement { const { data: url } = await this.#repo.create({ name, parentId }); - console.log('got url', url); if (!url) return; //TODO: Why do we need to extract the id like this? const id = url.substring(url.lastIndexOf('/') + 1);