From f5322b5beeda455dd07bdf525d3ef70762b02ea8 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Wed, 3 Sep 2025 15:17:20 +0200 Subject: [PATCH] Fix issue with newly created template under an existing one (#19669) * Fix issue with newly created template under an existing one. * feat: allows to set masterTemplate as preset * fix: create new sub-templates with a preset already set for the master template (if applicable) * fix: always resets master template, because you could be coming from an existing editor * fix: always set the master template even if it is null * fix: adds updateCurrent to also update the underlying _data model also refactor function a bit --------- Co-authored-by: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> --- .../template-detail.server.data-source.ts | 2 +- .../workspace/template-workspace.context.ts | 38 ++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/templates/repository/detail/template-detail.server.data-source.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/templates/repository/detail/template-detail.server.data-source.ts index c6920483d7..f0fe1ab340 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/templates/repository/detail/template-detail.server.data-source.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/templates/repository/detail/template-detail.server.data-source.ts @@ -43,7 +43,7 @@ export class UmbTemplateServerDataSource implements UmbDetailDataSource @@ -72,13 +73,15 @@ export class UmbTemplateWorkspaceContext return response; } - async create(parent: any) { - const data = await this.createScaffold({ parent }); + async create(parent: UmbEntityModel) { + const data = await this.createScaffold({ + parent, + }); + + // Set or reset the master template + // This is important to reset when a new template is created so the UI reflects the correct state + await this.setMasterTemplate(parent.unique); - if (data) { - if (!parent) return; - await this.setMasterTemplate(parent.unique); - } return data; } @@ -98,20 +101,21 @@ export class UmbTemplateWorkspaceContext return this.getData()?.content ? this.getLayoutBlockRegexPattern().test(this.getData()?.content as string) : false; } - async setMasterTemplate(id: string | null) { - if (id === null) { + async setMasterTemplate(unique: string | null) { + if (unique === null) { this.#masterTemplate.setValue(null); - this.#updateMasterTemplateLayoutBlock(); - return null; + } else { + // We need the whole template model if the unique id is provided + const { data } = await this.itemRepository.requestItems([unique]); + if (data) { + this.#masterTemplate.setValue(data[0]); + } } - const { data } = await this.itemRepository.requestItems([id]); - if (data) { - this.#masterTemplate.setValue(data[0]); - this.#updateMasterTemplateLayoutBlock(); - return data[0]; - } - return null; + this.#updateMasterTemplateLayoutBlock(); + this._data.updateCurrent({ masterTemplate: unique ? { unique } : null }); + + return unique; } #updateMasterTemplateLayoutBlock = () => {