Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
*/
#viewContext?: typeof UMB_VIEW_CONTEXT.TYPE;

@state()
private _loaded = false;

@state()
private _hasRootGroups = false;

Expand Down Expand Up @@ -84,6 +87,13 @@
this.#structureManager = workspaceContext?.structure;
this._tabsStructureHelper.setStructureManager(workspaceContext?.structure);
this.#observeRootGroups();
this.observe(
this.#structureManager?.contentTypeLoaded,
(loaded) => {
this._loaded = loaded ?? false;
},
'observeContentTypeLoaded',
);
});
}

Expand Down Expand Up @@ -197,7 +207,9 @@
}

override render() {
if (!this._routes || !this._tabs) return;
if (!this._loaded || !this._routes || this._routes.length === 0 || !this._tabs) {

Check warning on line 210 in src/Umbraco.Web.UI.Client/src/packages/content/content/workspace/views/edit/content-editor.element.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Complex Conditional

UmbContentWorkspaceViewEditElement.render has 1 complex conditionals with 3 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
return html`<umb-view-loader></umb-view-loader>`;
}
return html`
<umb-body-layout header-fit-height>
${this._routerPath && (this._tabs.length > 1 || (this._tabs.length === 1 && this._hasRootGroups))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export * from './ref-item/index.js';
export * from './split-panel/index.js';
export * from './stack/index.js';
export * from './table/index.js';
export * from './view-loader/view-loader.element.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { LitElement, css, customElement, html } from '@umbraco-cms/backoffice/external/lit';

@customElement('umb-view-loader')
export class UmbViewLoaderElement extends LitElement {
// Note just LitElement, not Umbraco Element.

override render() {
return html` <uui-loader></uui-loader>`;
}

static override styles = [
css`
:host {
display: flex;
width: 100%;
justify-content: center;
height: 100%;
align-items: center;
opacity: 0;
animation: fadeIn 240ms 240ms forwards;
}

@keyframes fadeIn {
100% {
opacity: 100%;
}
}
`,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import './workspace-split-view-variant-selector.element.js';
*/
@customElement('umb-workspace-split-view')
export class UmbWorkspaceSplitViewElement extends UmbLitElement {
@property({ type: Boolean })
public loading = false;

@property({ type: Boolean })
displayNavigation = false;

Expand All @@ -52,7 +55,7 @@ export class UmbWorkspaceSplitViewElement extends UmbLitElement {
@state()
private _variantId?: UmbVariantId;

splitViewContext = new UmbWorkspaceSplitViewContext(this);
readonly splitViewContext = new UmbWorkspaceSplitViewContext(this);

#onVariantSelectorSlotChanged(e: Event) {
this._variantSelectorSlotHasContent = (e.target as HTMLSlotElement).assignedNodes({ flatten: true }).length > 0;
Expand Down Expand Up @@ -81,6 +84,7 @@ export class UmbWorkspaceSplitViewElement extends UmbLitElement {
override render() {
return html`
<umb-workspace-editor
.loading=${this.loading}
back-path=${ifDefined(this.backPath)}
.hideNavigation=${!this.displayNavigation}
.variantId=${this._variantId}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ManifestWorkspace } from './extensions/types.js';
import { nothing, customElement, property, type PropertyValueMap, state } from '@umbraco-cms/backoffice/external/lit';
import { customElement, property, type PropertyValueMap, state, html } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import {
UmbExtensionsApiInitializer,
Expand Down Expand Up @@ -62,7 +62,7 @@ export class UmbWorkspaceElement extends UmbLitElement {
}

override render() {
return this._component ?? nothing;
return this._component ?? html`<umb-view-loader></umb-view-loader>`;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
@state()
private _routes?: Array<UmbRoute>;

@state()
private _loading?: boolean = true;

constructor() {
super();

Expand Down Expand Up @@ -55,11 +58,19 @@
},
'_observeForbidden',
);

this.observe(
this.#workspaceContext?.loading.isOn,
(loading) => {
this._loading = loading ?? false;
},
'_observeLoading',
);
});
}

#generateRoutes() {
if (!this.#variants || !this.#appCulture) {
if (!this.#variants || this.#variants.length === 0 || !this.#appCulture) {

Check warning on line 73 in src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace-editor.element.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Complex Conditional

UmbDocumentWorkspaceEditorElement.generateRoutes has 1 complex conditionals with 2 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
this._routes = [];
return;
}
Expand Down Expand Up @@ -145,9 +156,9 @@
};

override render() {
return this._routes
return !this._loading && this._routes
? html`<umb-router-slot .routes=${this._routes} @init=${this._gotWorkspaceRoute}></umb-router-slot>`
: '';
: html`<umb-view-loader></umb-view-loader>`;
}

static override styles = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export class UmbDocumentWorkspaceSplitViewElement extends UmbLitElement {
@state()
private _overrides?: Array<UmbDeepPartialObject<ManifestWorkspaceView>>;

@state()
private _loading = true;

constructor() {
super();

Expand All @@ -29,6 +32,7 @@ export class UmbDocumentWorkspaceSplitViewElement extends UmbLitElement {
this._workspaceContext = context;
this.#observeActiveVariantInfo();
this.#observeIcon();
this.#observeLoading();
this.#observeCollectionOverrides();
});
}
Expand All @@ -44,15 +48,33 @@ export class UmbDocumentWorkspaceSplitViewElement extends UmbLitElement {
}

#observeIcon() {
this.observe(this._workspaceContext?.contentTypeIcon, (icon) => {
this._icon = icon ?? undefined;
});
this.observe(
this._workspaceContext?.contentTypeIcon,
(icon) => {
this._icon = icon ?? undefined;
},
'observeIcon',
);
}

#observeLoading() {
this.observe(
this._workspaceContext?.loading.isOn,
(loading) => {
this._loading = loading ?? false;
},
'observeIcon',
);
}

#observeCollectionOverrides() {
this.observe(this._workspaceContext?.collection.manifestOverrides, (overrides) => {
this._overrides = overrides ? [overrides] : undefined;
});
this.observe(
this._workspaceContext?.collection.manifestOverrides,
(overrides) => {
this._overrides = overrides ? [overrides] : undefined;
},
'observeCollectionOverrides',
);
}

override render() {
Expand All @@ -64,6 +86,7 @@ export class UmbDocumentWorkspaceSplitViewElement extends UmbLitElement {
view.index + '_' + (view.culture ?? '') + '_' + (view.segment ?? '') + '_' + this._variants!.length,
(view) => html`
<umb-workspace-split-view
.loading=${this._loading}
.displayNavigation=${view.index === this._variants!.length - 1}
.overrides=${this._overrides}
.splitViewIndex=${view.index}>
Expand Down Expand Up @@ -96,10 +119,6 @@ export class UmbDocumentWorkspaceSplitViewElement extends UmbLitElement {
width: 100%;
height: calc(100% - var(--umb-footer-layout-height));
}

#breadcrumbs {
margin: 0 var(--uui-size-layout-1);
}
`,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,24 @@
this.#publishingContext = context;
});

this.observe(this.isNew, (isNew) => {
if (isNew === undefined) return;
if (isNew) {
this.#enforceUserPermission(
UMB_USER_PERMISSION_DOCUMENT_CREATE,
'You do not have permission to create documents.',
);
} else {
this.#enforceUserPermission(
UMB_USER_PERMISSION_DOCUMENT_UPDATE,
'You do not have permission to update documents.',
);
}
});
this.observe(
this.isNew,
(isNew) => {
if (isNew === undefined) return;
if (isNew) {
this.#enforceUserPermission(
UMB_USER_PERMISSION_DOCUMENT_CREATE,
'You do not have permission to create documents.',
);
} else {
this.#enforceUserPermission(
UMB_USER_PERMISSION_DOCUMENT_UPDATE,
'You do not have permission to update documents.',
);
}
},
null,
);

Check warning on line 147 in src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ Getting worse: Complex Method

UmbDocumentWorkspaceContext.constructor already has high cyclomatic complexity, and now it increases in Lines of Code from 103 to 107. 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.

this.routes.setRoutes([
{
Expand Down
Loading