save do not require attribute for isNew
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user