From f0d8caa9cfdaa12d2bc8fa3c6b1eb2f9b54f4f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 7 Jun 2023 19:06:44 +0200 Subject: [PATCH] focus and clear observers --- .../document-type-workspace-editor.element.ts | 15 ++++++++++++--- .../workspace/document-type-workspace.context.ts | 1 + .../workspace/document-type-workspace.element.ts | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace-editor.element.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace-editor.element.ts index 2009d4860d..45ffc89de6 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace-editor.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace-editor.element.ts @@ -46,9 +46,18 @@ export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement { #observeDocumentType() { if (!this.#workspaceContext) return; - this.observe(this.#workspaceContext.name, (name) => (this._name = name)); - this.observe(this.#workspaceContext.alias, (alias) => (this._alias = alias)); - this.observe(this.#workspaceContext.icon, (icon) => (this._icon = icon)); + this.observe(this.#workspaceContext.name, (name) => (this._name = name), '_observeName'); + this.observe(this.#workspaceContext.alias, (alias) => (this._alias = alias), '_observeAlias'); + this.observe(this.#workspaceContext.icon, (icon) => (this._icon = icon), '_observeIcon'); + + this.observe(this.#workspaceContext.isNew, (isNew) => { + if(isNew) { + // TODO: Would be good with a more general way to bring focus to the name input. + (this.shadowRoot?.querySelector('#name') as HTMLElement)?.focus(); + } + this.removeControllerByUnique('_observeIsNew'); + }, '_observeIsNew'); + } // TODO. find a way where we don't have to do this for all workspaces. diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace.context.ts index 9d6f1d5ff5..a3da2de2c1 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace.context.ts @@ -115,6 +115,7 @@ export class UmbDocumentTypeWorkspaceContext } async create(parentId: string | null) { + const { data } = await this.structure.createScaffold(parentId); if (!data) return undefined; diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace.element.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace.element.ts index 080d6b1f64..125606706d 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/document-type-workspace.element.ts @@ -40,6 +40,7 @@ export class UmbDocumentTypeWorkspaceElement extends UmbLitElement { path: 'edit/:id', component: import('./document-type-workspace-editor.element.js'), setup: (_component, info) => { + this.removeControllerByUnique('_observeIsNew'); const id = info.match.params.id; this.#workspaceContext.load(id); },