fix saving document on server
This commit is contained in:
@@ -90,7 +90,17 @@ export class UmbDocumentServerDataSource
|
||||
async insert(document: CreateDocumentRequestModel & { id: string }) {
|
||||
if (!document.id) throw new Error('Id is missing');
|
||||
|
||||
return tryExecuteAndNotify(this.#host, DocumentResource.postDocument({ requestBody: document }));
|
||||
// TODO: Hack to remove some props that ruins the document-type post end-point.
|
||||
const unFroozenDocument = { ...document };
|
||||
(unFroozenDocument as any).$type = undefined;
|
||||
(unFroozenDocument as any).id = undefined;
|
||||
|
||||
(unFroozenDocument.variants as any) =
|
||||
unFroozenDocument.variants?.map((variant) => {
|
||||
return { ...variant, $type: undefined };
|
||||
}) ?? [];
|
||||
|
||||
return tryExecuteAndNotify(this.#host, DocumentResource.postDocument({ requestBody: unFroozenDocument }));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +112,17 @@ export class UmbDocumentServerDataSource
|
||||
async update(id: string, document: UpdateDocumentRequestModel) {
|
||||
if (!id) throw new Error('Id is missing');
|
||||
|
||||
return tryExecuteAndNotify(this.#host, DocumentResource.putDocumentById({ id, requestBody: document }));
|
||||
// TODO: Hack to remove some props that ruins the document-type post end-point.
|
||||
const unFroozenDocument = { ...document };
|
||||
(unFroozenDocument as any).$type = undefined;
|
||||
(unFroozenDocument as any).id = undefined;
|
||||
|
||||
(unFroozenDocument.variants as any) =
|
||||
unFroozenDocument.variants?.map((variant) => {
|
||||
return { ...variant, $type: undefined };
|
||||
}) ?? [];
|
||||
|
||||
return tryExecuteAndNotify(this.#host, DocumentResource.putDocumentById({ id, requestBody: unFroozenDocument }));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from '@umbraco-cms/backoffice/workspace';
|
||||
import type { CreateDocumentRequestModel, DocumentResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
import {
|
||||
appendToFrozenArray,
|
||||
partialUpdateFrozenArray,
|
||||
UmbObjectState,
|
||||
UmbObserverController,
|
||||
@@ -159,12 +160,12 @@ export class UmbDocumentWorkspaceContext
|
||||
}
|
||||
}
|
||||
setPropertyValue(alias: string, value: unknown, variantId?: UmbVariantId) {
|
||||
const partialEntry = { value };
|
||||
const entry = { $type: 'DocumentValueModel', ...variantId?.toObject(), alias, value };
|
||||
const currentData = this.#draft.value;
|
||||
if (currentData) {
|
||||
const values = partialUpdateFrozenArray(
|
||||
const values = appendToFrozenArray(
|
||||
currentData.values || [],
|
||||
partialEntry,
|
||||
entry,
|
||||
(x) => x.alias === alias && (variantId ? variantId.compare(x) : true)
|
||||
);
|
||||
this.#draft.update({ values });
|
||||
|
||||
Reference in New Issue
Block a user