keep none saved data when saving
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
export { UMB_CONTENT_PROPERTY_CONTEXT } from './content-property.context-token.js';
|
export { UMB_CONTENT_PROPERTY_CONTEXT } from './content-property.context-token.js';
|
||||||
export { UmbContentPropertyContext } from './content-property.context.js';
|
export { UmbContentPropertyContext } from './content-property.context.js';
|
||||||
export * from './manager/content-data-manager.js';
|
export * from './manager/content-data-manager.js';
|
||||||
|
export * from './controller/merge-content-variant-data.controller.js';
|
||||||
export * from './property-dataset-context/content-property-dataset.context.js';
|
export * from './property-dataset-context/content-property-dataset.context.js';
|
||||||
export * from './workspace/index.js';
|
export * from './workspace/index.js';
|
||||||
export type * from './types.js';
|
export type * from './types.js';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { UmbMergeContentVariantDataController } from './merge-content-variant-data.controller.js';
|
import { UmbMergeContentVariantDataController } from '../controller/merge-content-variant-data.controller.js';
|
||||||
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
|
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
|
||||||
import type { UmbContentDetailModel } from '@umbraco-cms/backoffice/content';
|
import type { UmbContentDetailModel } from '@umbraco-cms/backoffice/content';
|
||||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||||
@@ -31,11 +31,6 @@ export class UmbContentWorkspaceDataManager<
|
|||||||
this.#variantScaffold = variantScaffold;
|
this.#variantScaffold = variantScaffold;
|
||||||
}
|
}
|
||||||
|
|
||||||
setData(incomingData: ModelType | undefined) {
|
|
||||||
this.#persisted.setValue(incomingData);
|
|
||||||
this.current.setValue(incomingData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
setVariesByCulture(vary: boolean | undefined) {
|
setVariesByCulture(vary: boolean | undefined) {
|
||||||
//this.#variesByCulture = vary;
|
//this.#variesByCulture = vary;
|
||||||
|
|||||||
@@ -63,7 +63,11 @@ import {
|
|||||||
} from '@umbraco-cms/backoffice/validation';
|
} from '@umbraco-cms/backoffice/validation';
|
||||||
import { UmbDocumentBlueprintDetailRepository } from '@umbraco-cms/backoffice/document-blueprint';
|
import { UmbDocumentBlueprintDetailRepository } from '@umbraco-cms/backoffice/document-blueprint';
|
||||||
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
|
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
|
||||||
import { UmbContentWorkspaceDataManager, type UmbContentWorkspaceContext } from '@umbraco-cms/backoffice/content';
|
import {
|
||||||
|
UmbContentWorkspaceDataManager,
|
||||||
|
UmbMergeContentVariantDataController,
|
||||||
|
type UmbContentWorkspaceContext,
|
||||||
|
} from '@umbraco-cms/backoffice/content';
|
||||||
import type { UmbDocumentTypeDetailModel } from '@umbraco-cms/backoffice/document-type';
|
import type { UmbDocumentTypeDetailModel } from '@umbraco-cms/backoffice/document-type';
|
||||||
import { UmbIsTrashedEntityContext } from '@umbraco-cms/backoffice/recycle-bin';
|
import { UmbIsTrashedEntityContext } from '@umbraco-cms/backoffice/recycle-bin';
|
||||||
import { UmbReadOnlyVariantStateManager } from '@umbraco-cms/backoffice/utils';
|
import { UmbReadOnlyVariantStateManager } from '@umbraco-cms/backoffice/utils';
|
||||||
@@ -255,7 +259,8 @@ export class UmbDocumentWorkspaceContext
|
|||||||
|
|
||||||
override resetState() {
|
override resetState() {
|
||||||
super.resetState();
|
super.resetState();
|
||||||
this.#data.setData(undefined);
|
this.#data.setPersistedData(undefined);
|
||||||
|
this.#data.setCurrentData(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadLanguages() {
|
async loadLanguages() {
|
||||||
@@ -275,7 +280,8 @@ export class UmbDocumentWorkspaceContext
|
|||||||
this.#entityContext.setUnique(unique);
|
this.#entityContext.setUnique(unique);
|
||||||
this.#isTrashedContext.setIsTrashed(data.isTrashed);
|
this.#isTrashedContext.setIsTrashed(data.isTrashed);
|
||||||
this.setIsNew(false);
|
this.setIsNew(false);
|
||||||
this.#data.setData(data);
|
this.#data.setPersistedData(data);
|
||||||
|
this.#data.setCurrentData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.observe(asObservable(), (entity) => this.#onStoreChange(entity), 'umbDocumentStoreObserver');
|
this.observe(asObservable(), (entity) => this.#onStoreChange(entity), 'umbDocumentStoreObserver');
|
||||||
@@ -509,7 +515,7 @@ export class UmbDocumentWorkspaceContext
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async #performSaveOrCreate(saveData: UmbDocumentDetailModel): Promise<void> {
|
async #performSaveOrCreate(variantIds: Array<UmbVariantId>, saveData: UmbDocumentDetailModel): Promise<void> {
|
||||||
if (this.getIsNew()) {
|
if (this.getIsNew()) {
|
||||||
// Create:
|
// Create:
|
||||||
const parent = this.#parent.getValue();
|
const parent = this.#parent.getValue();
|
||||||
@@ -524,7 +530,17 @@ export class UmbDocumentWorkspaceContext
|
|||||||
this.setIsNew(false);
|
this.setIsNew(false);
|
||||||
this.#data.setPersistedData(data);
|
this.#data.setPersistedData(data);
|
||||||
// TODO: Only update the variants that was chosen to be saved:
|
// TODO: Only update the variants that was chosen to be saved:
|
||||||
this.#data.setCurrentData(data);
|
const currentData = this.#data.getCurrentData();
|
||||||
|
|
||||||
|
const variantIdsIncludingInvariant = [...variantIds, UmbVariantId.CreateInvariant()];
|
||||||
|
|
||||||
|
const newCurrentData = await new UmbMergeContentVariantDataController(this).process(
|
||||||
|
currentData,
|
||||||
|
data,
|
||||||
|
variantIds,
|
||||||
|
variantIdsIncludingInvariant,
|
||||||
|
);
|
||||||
|
this.#data.setCurrentData(newCurrentData);
|
||||||
|
|
||||||
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
|
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
|
||||||
const event = new UmbRequestReloadChildrenOfEntityEvent({
|
const event = new UmbRequestReloadChildrenOfEntityEvent({
|
||||||
@@ -542,7 +558,17 @@ export class UmbDocumentWorkspaceContext
|
|||||||
|
|
||||||
this.#data.setPersistedData(data);
|
this.#data.setPersistedData(data);
|
||||||
// TODO: Only update the variants that was chosen to be saved:
|
// TODO: Only update the variants that was chosen to be saved:
|
||||||
this.#data.setCurrentData(data);
|
const currentData = this.#data.getCurrentData();
|
||||||
|
|
||||||
|
const variantIdsIncludingInvariant = [...variantIds, UmbVariantId.CreateInvariant()];
|
||||||
|
|
||||||
|
const newCurrentData = await new UmbMergeContentVariantDataController(this).process(
|
||||||
|
currentData,
|
||||||
|
data,
|
||||||
|
variantIds,
|
||||||
|
variantIdsIncludingInvariant,
|
||||||
|
);
|
||||||
|
this.#data.setCurrentData(newCurrentData);
|
||||||
|
|
||||||
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
|
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
|
||||||
const event = new UmbRequestReloadStructureForEntityEvent({
|
const event = new UmbRequestReloadStructureForEntityEvent({
|
||||||
@@ -569,10 +595,10 @@ export class UmbDocumentWorkspaceContext
|
|||||||
const { selected } = await this.#determineVariantOptions();
|
const { selected } = await this.#determineVariantOptions();
|
||||||
if (selected.length > 0) {
|
if (selected.length > 0) {
|
||||||
culture = selected[0];
|
culture = selected[0];
|
||||||
const variantId = UmbVariantId.FromString(culture);
|
const variantIds = [UmbVariantId.FromString(culture)];
|
||||||
const saveData = await this.#data.constructData([variantId]);
|
const saveData = await this.#data.constructData(variantIds);
|
||||||
await this.#runMandatoryValidationForSaveData(saveData);
|
await this.#runMandatoryValidationForSaveData(saveData);
|
||||||
await this.#performSaveOrCreate(saveData);
|
await this.#performSaveOrCreate(variantIds, saveData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell the server that we're entering preview mode.
|
// Tell the server that we're entering preview mode.
|
||||||
@@ -640,7 +666,7 @@ export class UmbDocumentWorkspaceContext
|
|||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
// If data of the selection is not valid Then just save:
|
// If data of the selection is not valid Then just save:
|
||||||
await this.#performSaveOrCreate(saveData);
|
await this.#performSaveOrCreate(variantIds, saveData);
|
||||||
// Notifying that the save was successful, but we did not publish, which is what we want to symbolize here. [NL]
|
// Notifying that the save was successful, but we did not publish, which is what we want to symbolize here. [NL]
|
||||||
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
|
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
|
||||||
// TODO: Get rid of the save notification.
|
// TODO: Get rid of the save notification.
|
||||||
@@ -675,7 +701,7 @@ export class UmbDocumentWorkspaceContext
|
|||||||
const unique = this.getUnique();
|
const unique = this.getUnique();
|
||||||
if (!unique) throw new Error('Unique is missing');
|
if (!unique) throw new Error('Unique is missing');
|
||||||
|
|
||||||
await this.#performSaveOrCreate(saveData);
|
await this.#performSaveOrCreate(variantIds, saveData);
|
||||||
|
|
||||||
await this.publishingRepository.publish(
|
await this.publishingRepository.publish(
|
||||||
unique,
|
unique,
|
||||||
@@ -723,7 +749,7 @@ export class UmbDocumentWorkspaceContext
|
|||||||
|
|
||||||
const saveData = await this.#data.constructData(variantIds);
|
const saveData = await this.#data.constructData(variantIds);
|
||||||
await this.#runMandatoryValidationForSaveData(saveData);
|
await this.#runMandatoryValidationForSaveData(saveData);
|
||||||
return await this.#performSaveOrCreate(saveData);
|
return await this.#performSaveOrCreate(variantIds, saveData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override requestSubmit() {
|
public override requestSubmit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user