Segments: Fix for processing data for Segments-variants (#21018)
* refactor to load segments before processing incoming data * clean up * remove unused segment promise
This commit is contained in:
@@ -92,7 +92,6 @@ export abstract class UmbContentTypeWorkspaceContextBase<
|
|||||||
let { data } = await request;
|
let { data } = await request;
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
data = await this._processIncomingData(data);
|
|
||||||
data = await this._scaffoldProcessData(data);
|
data = await this._scaffoldProcessData(data);
|
||||||
|
|
||||||
if (this.modalContext) {
|
if (this.modalContext) {
|
||||||
|
|||||||
@@ -368,11 +368,6 @@ export abstract class UmbContentDetailWorkspaceContextBase<
|
|||||||
(varies) => {
|
(varies) => {
|
||||||
this._data.setVariesBySegment(varies);
|
this._data.setVariesBySegment(varies);
|
||||||
this.#variesBySegment = varies;
|
this.#variesBySegment = varies;
|
||||||
if (varies) {
|
|
||||||
this.loadSegments();
|
|
||||||
} else {
|
|
||||||
this._segments.setValue([]);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
@@ -393,20 +388,28 @@ export abstract class UmbContentDetailWorkspaceContextBase<
|
|||||||
this.#languages.setValue(data?.items ?? []);
|
this.#languages.setValue(data?.items ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Call `_loadSegmentsFor` instead. `loadSegments` will be removed in v.18.
|
||||||
|
* (note this was introduced in v.17, and deprecated in v.17.0.1)
|
||||||
|
*/
|
||||||
protected async loadSegments() {
|
protected async loadSegments() {
|
||||||
|
console.warn('Stop using loadSegments, call _loadSegmentsFor instead. loadSegments will be removed in v.18.');
|
||||||
|
const unique = await firstValueFrom(this.unique);
|
||||||
|
if (!unique) {
|
||||||
|
this._segments.setValue([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._loadSegmentsFor(unique);
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
protected async _loadSegmentsFor(unique: string): Promise<void> {
|
||||||
console.warn(
|
console.warn(
|
||||||
`UmbContentDetailWorkspaceContextBase: Segments are not implemented in the workspace context for "${this.getEntityType()}" types.`,
|
`UmbContentDetailWorkspaceContextBase: Segments are not implemented in the workspace context for "${this.getEntityType()}" types.`,
|
||||||
);
|
);
|
||||||
this._segments.setValue([]);
|
this._segments.setValue([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Call `_processIncomingData` instead. `_scaffoldProcessData` will be removed in v.18.
|
|
||||||
*/
|
|
||||||
protected override _scaffoldProcessData(data: DetailModelType): Promise<DetailModelType> {
|
|
||||||
return this._processIncomingData(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override async _processIncomingData(data: DetailModelType): Promise<DetailModelType> {
|
protected override async _processIncomingData(data: DetailModelType): Promise<DetailModelType> {
|
||||||
const contentTypeUnique: string | undefined = (data as any)[this.#contentTypePropertyName].unique;
|
const contentTypeUnique: string | undefined = (data as any)[this.#contentTypePropertyName].unique;
|
||||||
if (!contentTypeUnique) {
|
if (!contentTypeUnique) {
|
||||||
@@ -415,24 +418,28 @@ export abstract class UmbContentDetailWorkspaceContextBase<
|
|||||||
// Load the content type structure, usually this comes from the data, but in this case we are making the data, and we need this to be able to complete the data. [NL]
|
// Load the content type structure, usually this comes from the data, but in this case we are making the data, and we need this to be able to complete the data. [NL]
|
||||||
await this.structure.loadType(contentTypeUnique);
|
await this.structure.loadType(contentTypeUnique);
|
||||||
|
|
||||||
|
// Load segments if varying by segment, or reset to empty array:
|
||||||
|
if (this.#variesBySegment) {
|
||||||
|
await this._loadSegmentsFor(data.unique);
|
||||||
|
} else {
|
||||||
|
this._segments.setValue([]);
|
||||||
|
}
|
||||||
|
|
||||||
// Set culture and segment for all values:
|
// Set culture and segment for all values:
|
||||||
const cultures = this.#languages.getValue().map((x) => x.unique);
|
const cultures = this.#languages.getValue().map((x) => x.unique);
|
||||||
|
|
||||||
if (this.structure.variesBySegment) {
|
let segments: Array<string> | undefined;
|
||||||
// TODO: v.17 Engage please note we have not implemented support for segments yet. [NL]
|
if (this.#variesBySegment) {
|
||||||
console.warn('Segments are not yet implemented for preset');
|
segments = this._segments.getValue().map((s) => s.alias);
|
||||||
}
|
}
|
||||||
// TODO: Add Segments for Presets:
|
|
||||||
const segments: Array<string> | undefined = this.structure.variesBySegment ? [] : undefined;
|
|
||||||
|
|
||||||
const repo = new UmbDataTypeDetailRepository(this);
|
const repo = new UmbDataTypeDetailRepository(this);
|
||||||
|
|
||||||
const propertyTypes = await this.structure.getContentTypeProperties();
|
const propertyTypes = await this.structure.getContentTypeProperties();
|
||||||
const contentTypeVariesByCulture = this.structure.getVariesByCulture();
|
const contentTypeVariesByCulture = this.structure.getVariesByCulture();
|
||||||
const contentTypeVariesBySegment = this.structure.getVariesByCulture();
|
const contentTypeVariesBySegment = this.structure.getVariesBySegment();
|
||||||
const valueDefinitions = await Promise.all(
|
const valueDefinitions = await Promise.all(
|
||||||
propertyTypes.map(async (property) => {
|
propertyTypes.map(async (property) => {
|
||||||
// TODO: Implement caching for data-type requests. [NL]
|
|
||||||
const dataType = (await repo.requestByUnique(property.dataType.unique)).data;
|
const dataType = (await repo.requestByUnique(property.dataType.unique)).data;
|
||||||
// This means if its not loaded this will never resolve and the error below will never happen.
|
// This means if its not loaded this will never resolve and the error below will never happen.
|
||||||
if (!dataType) {
|
if (!dataType) {
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (data) {
|
} else if (data) {
|
||||||
const processedData = await this._processIncomingData(data);
|
const processedData = await this._scaffoldProcessData(data);
|
||||||
|
|
||||||
this._data.setPersisted(processedData);
|
this._data.setPersisted(processedData);
|
||||||
this._data.setCurrent(processedData);
|
this._data.setCurrent(processedData);
|
||||||
@@ -311,7 +311,6 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
|
|||||||
let { data } = await request;
|
let { data } = await request;
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
data = await this._processIncomingData(data);
|
|
||||||
data = await this._scaffoldProcessData(data);
|
data = await this._scaffoldProcessData(data);
|
||||||
|
|
||||||
if (this.modalContext) {
|
if (this.modalContext) {
|
||||||
@@ -336,7 +335,7 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
|
|||||||
* @returns {Promise<DetailModelType>} The processed data.
|
* @returns {Promise<DetailModelType>} The processed data.
|
||||||
*/
|
*/
|
||||||
protected async _scaffoldProcessData(data: DetailModelType): Promise<DetailModelType> {
|
protected async _scaffoldProcessData(data: DetailModelType): Promise<DetailModelType> {
|
||||||
return data;
|
return await this._processIncomingData(data);
|
||||||
}
|
}
|
||||||
protected async _processIncomingData(data: DetailModelType): Promise<DetailModelType> {
|
protected async _processIncomingData(data: DetailModelType): Promise<DetailModelType> {
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -227,22 +227,16 @@ export class UmbDocumentWorkspaceContext
|
|||||||
this.#isTrashedContext.setIsTrashed(false);
|
this.#isTrashedContext.setIsTrashed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async loadSegments(): Promise<void> {
|
protected override async _loadSegmentsFor(unique: string): Promise<void> {
|
||||||
this.observe(
|
if (!unique) {
|
||||||
this.unique,
|
this._segments.setValue([]);
|
||||||
async (unique) => {
|
return;
|
||||||
if (!unique) {
|
}
|
||||||
this._segments.setValue([]);
|
const { data } = await this.#documentSegmentRepository.getDocumentByIdSegmentOptions(unique, {
|
||||||
return;
|
skip: 0,
|
||||||
}
|
take: 9999,
|
||||||
const { data } = await this.#documentSegmentRepository.getDocumentByIdSegmentOptions(unique, {
|
});
|
||||||
skip: 0,
|
this._segments.setValue(data?.items ?? []);
|
||||||
take: 9999,
|
|
||||||
});
|
|
||||||
this._segments.setValue(data?.items ?? []);
|
|
||||||
},
|
|
||||||
'_loadSegmentsUnique',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(parent: UmbEntityModel, documentTypeUnique: string, blueprintUnique?: string) {
|
async create(parent: UmbEntityModel, documentTypeUnique: string, blueprintUnique?: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user