Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export abstract class UmbContentTypeWorkspaceContextBase<
let { data } = await request;

if (data) {
data = await this._processIncomingData(data);
data = await this._scaffoldProcessData(data);

if (this.modalContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,7 @@
this.variesBySegment,
(varies) => {
this._data.setVariesBySegment(varies);
this.#variesBySegment = varies;

Check notice on line 370 in src/Umbraco.Web.UI.Client/src/packages/content/content/workspace/content-detail-workspace-base.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (release/17.0)

✅ Getting better: Complex Method

constructor decreases in cyclomatic complexity from 28 to 27, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
if (varies) {
this.loadSegments();
} else {
this._segments.setValue([]);
}
},
null,
);
Expand All @@ -393,20 +388,28 @@
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() {
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(
`UmbContentDetailWorkspaceContextBase: Segments are not implemented in the workspace context for "${this.getEntityType()}" types.`,
);
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> {
const contentTypeUnique: string | undefined = (data as any)[this.#contentTypePropertyName].unique;
if (!contentTypeUnique) {
Expand All @@ -415,24 +418,28 @@
// 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);

// 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:
const cultures = this.#languages.getValue().map((x) => x.unique);

if (this.structure.variesBySegment) {
// TODO: v.17 Engage please note we have not implemented support for segments yet. [NL]
console.warn('Segments are not yet implemented for preset');
let segments: Array<string> | undefined;
if (this.#variesBySegment) {
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 propertyTypes = await this.structure.getContentTypeProperties();
const contentTypeVariesByCulture = this.structure.getVariesByCulture();
const contentTypeVariesBySegment = this.structure.getVariesByCulture();
const contentTypeVariesBySegment = this.structure.getVariesBySegment();
const valueDefinitions = await Promise.all(
propertyTypes.map(async (property) => {
// TODO: Implement caching for data-type requests. [NL]
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.
if (!dataType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
}
}
} else if (data) {
const processedData = await this._processIncomingData(data);
const processedData = await this._scaffoldProcessData(data);

this._data.setPersisted(processedData);
this._data.setCurrent(processedData);
Expand Down Expand Up @@ -311,7 +311,6 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
let { data } = await request;

if (data) {
data = await this._processIncomingData(data);
data = await this._scaffoldProcessData(data);

if (this.modalContext) {
Expand All @@ -336,7 +335,7 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
* @returns {Promise<DetailModelType>} The processed data.
*/
protected async _scaffoldProcessData(data: DetailModelType): Promise<DetailModelType> {
return data;
return await this._processIncomingData(data);
}
protected async _processIncomingData(data: DetailModelType): Promise<DetailModelType> {
return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,22 +227,16 @@ export class UmbDocumentWorkspaceContext
this.#isTrashedContext.setIsTrashed(false);
}

protected override async loadSegments(): Promise<void> {
this.observe(
this.unique,
async (unique) => {
if (!unique) {
this._segments.setValue([]);
return;
}
const { data } = await this.#documentSegmentRepository.getDocumentByIdSegmentOptions(unique, {
skip: 0,
take: 9999,
});
this._segments.setValue(data?.items ?? []);
},
'_loadSegmentsUnique',
);
protected override async _loadSegmentsFor(unique: string): Promise<void> {
if (!unique) {
this._segments.setValue([]);
return;
}
const { data } = await this.#documentSegmentRepository.getDocumentByIdSegmentOptions(unique, {
skip: 0,
take: 9999,
});
this._segments.setValue(data?.items ?? []);
}

async create(parent: UmbEntityModel, documentTypeUnique: string, blueprintUnique?: string) {
Expand Down
Loading