diff --git a/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts index e56e1bc889..726b8ab7d4 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts @@ -12,6 +12,8 @@ export class UmbDataTypeWorkspaceContext #data = new UmbObjectState(undefined); data = this.#data.asObservable(); + #preset?: Partial; + name = this.#data.getObservablePart((data) => data?.name); id = this.#data.getObservablePart((data) => data?.id); @@ -19,6 +21,10 @@ export class UmbDataTypeWorkspaceContext super(host, new UmbDataTypeRepository(host)); } + public setPreset(preset: Partial) { + this.#preset = preset; + } + async load(id: string) { const { data } = await this.repository.requestById(id); if (data) { @@ -28,7 +34,10 @@ export class UmbDataTypeWorkspaceContext } async createScaffold(parentId: string | null) { - const { data } = await this.repository.createScaffold(parentId); + let { data } = await this.repository.createScaffold(parentId); + if (this.#preset) { + data = { ...data, ...this.#preset }; + } 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. @@ -80,8 +89,8 @@ export class UmbDataTypeWorkspaceContext } else { await this.repository.save(this.#data.value.id, this.#data.value); } - // If it went well, then its not new anymore?. - this.setIsNew(false); + + this.saveComplete(this.#data.value); } async delete(id: string) {