save do not require attribute for isNew

This commit is contained in:
Niels Lyngsø
2023-02-06 16:39:58 +01:00
parent 21f72fdf4c
commit 5aff2c99da
2 changed files with 12 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ export class UmbDocumentWorkspaceContext
extends UmbWorkspaceContext
implements UmbWorkspaceEntityContextInterface<EntityType | undefined>
{
#isNew = false;
#host: UmbControllerHostInterface;
#templateDetailRepo: UmbDocumentRepository;
@@ -84,6 +85,7 @@ export class UmbDocumentWorkspaceContext
async load(entityKey: string) {
const { data } = await this.#templateDetailRepo.requestDetails(entityKey);
if (data) {
this.#isNew = false;
this.#data.next(data);
}
}
@@ -91,14 +93,19 @@ export class UmbDocumentWorkspaceContext
async createScaffold(parentKey: string | null) {
const { data } = await this.#templateDetailRepo.createDetailsScaffold(parentKey);
if (!data) return;
this.#isNew = true;
this.#data.next(data);
}
async save(isNew: boolean) {
async save() {
if (!this.#data.value) return;
isNew
? this.#templateDetailRepo.createDetail(this.#data.value)
: this.#templateDetailRepo.saveDetail(this.#data.value);
if (this.#isNew) {
await this.#templateDetailRepo.createDetail(this.#data.value);
} else {
await this.#templateDetailRepo.saveDetail(this.#data.value);
}
// If it went well, then its not new anymore?.
this.#isNew = false;
}
async delete(key: string) {

View File

@@ -11,5 +11,5 @@ export interface UmbWorkspaceEntityContextInterface<T = unknown> extends UmbWork
setPropertyValue(alias: string, value: unknown): void;
save(isNew: boolean): Promise<void>;
save(): Promise<void>;
}