correct save and publish
This commit is contained in:
@@ -3,6 +3,7 @@ import type { UmbSaveableWorkspaceContextInterface } from './saveable-workspace-
|
||||
export interface UmbPublishableWorkspaceContextInterface<EntityType = unknown>
|
||||
extends UmbSaveableWorkspaceContextInterface<EntityType> {
|
||||
//getData(): EntityType | undefined;
|
||||
saveAndPublish(): Promise<void>;
|
||||
publish(): Promise<void>;
|
||||
unpublish(): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -218,7 +218,26 @@ export class UmbDocumentRepository
|
||||
return { error };
|
||||
}
|
||||
|
||||
async saveAndPublish(id: string, variantIds: Array<UmbVariantId>) {
|
||||
async saveAndPublish(id: string, item: UpdateDocumentRequestModel, variantIds: Array<UmbVariantId>) {
|
||||
if (!id) throw new Error('id is missing');
|
||||
if (!variantIds) throw new Error('variant IDs are missing');
|
||||
//await this.#init;
|
||||
|
||||
await this.save(id, item);
|
||||
|
||||
const { error } = await this.#detailDataSource.saveAndPublish(id, variantIds);
|
||||
|
||||
if (!error) {
|
||||
// TODO: Update other stores based on above effect.
|
||||
|
||||
const notification = { data: { message: `Document saved and published` } };
|
||||
this.#notificationContext?.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { error };
|
||||
}
|
||||
|
||||
async publish(id: string, variantIds: Array<UmbVariantId>) {
|
||||
if (!id) throw new Error('id is missing');
|
||||
if (!variantIds) throw new Error('variant IDs are missing');
|
||||
await this.#init;
|
||||
|
||||
@@ -217,7 +217,19 @@ export class UmbDocumentWorkspaceContext
|
||||
const variantIds = currentData.variants?.map((x) => UmbVariantId.Create(x));
|
||||
const id = this.getEntityId();
|
||||
if(variantIds && id) {
|
||||
await this.repository.saveAndPublish(id, variantIds);
|
||||
await this.repository.publish(id, variantIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async saveAndPublish() {
|
||||
// TODO: This might be right to publish all, but we need a method that just saves and publishes a declared range of variants.
|
||||
const currentData = this.#currentData.value;
|
||||
if(currentData) {
|
||||
const variantIds = currentData.variants?.map((x) => UmbVariantId.Create(x));
|
||||
const id = currentData.id;
|
||||
if(variantIds && id) {
|
||||
await this.repository.saveAndPublish(id, currentData, variantIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user