Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

15.3: Hotfix: Content type discard changes #18490

Merged
merged 6 commits into from
Feb 28, 2025
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
@@ -1,4 +1,4 @@
import type { UmbContentTypeCompositionModel, UmbContentTypeDetailModel, UmbContentTypeSortModel } from '../types.js';

Check warning on line 1 in src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/content-type-workspace-context-base.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (release/15.3)

❌ New issue: String Heavy Function Arguments

In this module, 41.7% of all arguments to its 17 functions are strings. The threshold for string arguments is 39.0%. The functions in this file have a high ratio of strings as arguments. Avoid adding more.
import { UmbContentTypeStructureManager } from '../structure/index.js';
import type { UmbContentTypeWorkspaceContext } from './content-type-workspace-context.interface.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
Expand All @@ -10,7 +10,7 @@
type UmbRoutableWorkspaceContext,
} from '@umbraco-cms/backoffice/workspace';
import type { UmbReferenceByUnique } from '@umbraco-cms/backoffice/models';
import { jsonStringComparison, type Observable } from '@umbraco-cms/backoffice/observable-api';
import type { Observable } from '@umbraco-cms/backoffice/observable-api';
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
import {
UmbRequestReloadChildrenOfEntityEvent,
Expand All @@ -21,6 +21,8 @@
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface UmbContentTypeWorkspaceContextArgs extends UmbEntityDetailWorkspaceContextArgs {}

const LOADING_STATE_UNIQUE = 'umbLoadingContentTypeDetail';

export abstract class UmbContentTypeWorkspaceContextBase<
DetailModelType extends UmbContentTypeDetailModel = UmbContentTypeDetailModel,
DetailRepositoryType extends UmbDetailRepository<DetailModelType> = UmbDetailRepository<DetailModelType>,
Expand Down Expand Up @@ -61,6 +63,9 @@
this.allowedContentTypes = this.structure.ownerContentTypeObservablePart((data) => data?.allowedContentTypes);
this.compositions = this.structure.ownerContentTypeObservablePart((data) => data?.compositions);
this.collection = this.structure.ownerContentTypeObservablePart((data) => data?.collection);

// Keep current data in sync with the owner content type - This is used for the discard changes feature
this.observe(this.structure.ownerContentType, (data) => this._data.setCurrent(data));
}

/**
Expand All @@ -72,21 +77,27 @@
args: UmbEntityDetailWorkspaceContextCreateArgs<DetailModelType>,
): Promise<DetailModelType | undefined> {
this.resetState();
this.loading.addState({ unique: LOADING_STATE_UNIQUE, message: `Creating ${this.getEntityType()} scaffold` });
this.setParent(args.parent);

const request = this.structure.createScaffold(args.preset);
this._getDataPromise = request;
let { data } = await request;
if (!data) return undefined;

this.setUnique(data.unique);
if (data) {
data = await this._scaffoldProcessData(data);

if (this.modalContext) {
// Notice if the preset comes with values, they will overwrite the scaffolded values... [NL]
data = { ...data, ...this.modalContext.data.preset };
}

if (this.modalContext) {
data = { ...data, ...this.modalContext.data.preset };
this.setUnique(data.unique);
this.setIsNew(true);
this._data.setPersisted(data);
}

this.setIsNew(true);
this._data.setPersisted(data);
this.loading.removeState(LOADING_STATE_UNIQUE);

return data;
}
Expand All @@ -97,20 +108,38 @@
* @returns { Promise<DetailModelType> } The loaded data
*/
override async load(unique: string) {
if (unique === this.getUnique() && this._getDataPromise) {
return (await this._getDataPromise) as any;
}

this.resetState();
this.setUnique(unique);
this.loading.addState({ unique: LOADING_STATE_UNIQUE, message: `Loading ${this.getEntityType()} Details` });
this._getDataPromise = this.structure.loadType(unique);
const response = await this._getDataPromise;
const data = response.data;

if (data) {
this._data.setPersisted(data);
this.setIsNew(false);

this.observe(
response.asObservable(),
(entity: any) => this.#onDetailStoreChange(entity),
'umbContentTypeDetailStoreObserver',
);
}

this.loading.removeState(LOADING_STATE_UNIQUE);
return response;
}

#onDetailStoreChange(entity: DetailModelType | undefined) {
if (!entity) {
this._data.clear();
}
}

/**
* Creates the Content Type
* @param { DetailModelType } currentData The current data
Expand Down Expand Up @@ -232,12 +261,6 @@
return this.structure.getOwnerContentType();
}

protected override _getHasUnpersistedChanges(): boolean {
const currentData = this.structure.getOwnerContentType();
const persistedData = this._data.getPersisted();
return jsonStringComparison(persistedData, currentData) === false;
}

public override destroy(): void {
this.structure.destroy();
super.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {

override render() {
return html`
<umb-workspace-editor>
<umb-entity-detail-workspace-editor>
<div id="header" slot="header">
<uui-button id="icon" compact label="icon" look="outline" @click=${this._handleIconClick}>
<umb-icon name=${ifDefined(this._icon)}></umb-icon>
Expand All @@ -105,7 +105,7 @@ export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {
@input=${this.#onDescriptionChange}></uui-input>
</div>
</div>
</umb-workspace-editor>
</umb-entity-detail-workspace-editor>
`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class UmbMediaTypeWorkspaceEditorElement extends UmbLitElement {

override render() {
return html`
<umb-workspace-editor>
<umb-entity-detail-workspace-editor>
<div id="header" slot="header">
<uui-button id="icon" compact label="icon" look="outline" @click=${this._handleIconClick}>
<umb-icon name=${ifDefined(this._icon)}></umb-icon>
Expand All @@ -107,7 +107,7 @@ export class UmbMediaTypeWorkspaceEditorElement extends UmbLitElement {
@input=${this.#onDescriptionChange}></uui-input>
</div>
</div>
</umb-workspace-editor>
</umb-entity-detail-workspace-editor>
`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class UmbMemberTypeWorkspaceEditorElement extends UmbLitElement {

override render() {
return html`
<umb-workspace-editor>
<umb-entity-detail-workspace-editor>
<div id="header" slot="header">
<uui-button id="icon" compact label="icon" look="outline" @click=${this._handleIconClick}>
<umb-icon name=${ifDefined(this._icon)}></umb-icon>
Expand All @@ -102,7 +102,7 @@ export class UmbMemberTypeWorkspaceEditorElement extends UmbLitElement {
@input=${this.#onDescriptionChange}></uui-input>
</div>
</div>
</umb-workspace-editor>
</umb-entity-detail-workspace-editor>
`;
}

Expand Down
Loading