Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { UmbBlockWorkspaceElementManagerNames } from '../../block-workspace.context.js';

Check warning on line 1 in src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/views/edit/block-workspace-view-edit.element.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Overall Code Complexity

This module has a mean cyclomatic complexity of 4.57 across 7 functions. The mean complexity threshold is 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
import { UMB_BLOCK_WORKSPACE_CONTEXT } from '../../block-workspace.context-token.js';
import type { UmbBlockWorkspaceViewEditTabElement } from './block-workspace-view-edit-tab.element.js';
import { css, html, customElement, state, repeat, property } from '@umbraco-cms/backoffice/external/lit';
import { css, html, customElement, state, repeat, property, nothing } from '@umbraco-cms/backoffice/external/lit';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import type { UmbContentTypeModel, UmbPropertyTypeContainerMergedModel } from '@umbraco-cms/backoffice/content-type';
import { UmbContentTypeContainerStructureHelper } from '@umbraco-cms/backoffice/content-type';
Expand Down Expand Up @@ -101,39 +101,38 @@
if (!this._tabs || !this.#blockWorkspace) return;
const routes: UmbRoute[] = [];

if (this._hasRootGroups || this._hasRootProperties) {
routes.push({
path: 'root',
component: () => import('./block-workspace-view-edit-tab.element.js'),
setup: (component) => {
(component as UmbBlockWorkspaceViewEditTabElement).managerName = this.#managerName;
(component as UmbBlockWorkspaceViewEditTabElement).containerId = null;
},
});
}

if (this._tabs.length > 0) {
this._tabs?.forEach((tab) => {
const tabName = tab.name ?? '';
routes.push({
path: `tab/${encodeFolderName(tabName)}`,
component: () => import('./block-workspace-view-edit-tab.element.js'),
setup: (component) => {
(component as UmbBlockWorkspaceViewEditTabElement).managerName = this.#managerName;
(component as UmbBlockWorkspaceViewEditTabElement).containerId = tab.ids[0];
},
});
});
}

if (this._hasRootGroups || this._hasRootProperties) {
if (routes.length !== 0) {
routes.push({
...routes[0],
unique: routes[0].path,
path: '',
component: () => import('./block-workspace-view-edit-tab.element.js'),
setup: (component) => {
(component as UmbBlockWorkspaceViewEditTabElement).managerName = this.#managerName;
(component as UmbBlockWorkspaceViewEditTabElement).containerId = null;
},
});
}

Check notice on line 135 in src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/views/edit/block-workspace-view-edit.element.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ No longer an issue: Complex Method

UmbBlockWorkspaceViewEditElement.createRoutes is no longer above the threshold for cyclomatic complexity. 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 (routes.length !== 0) {
if (!this._hasRootGroups) {
routes.push({
path: '',
pathMatch: 'full',
redirectTo: routes[0]?.path,
});
}
routes.push({
path: `**`,
component: async () => (await import('@umbraco-cms/backoffice/router')).UmbRouteNotFoundElement,
Expand All @@ -147,29 +146,18 @@
if (!this._routes || !this._tabs) return;
return html`
<umb-body-layout header-fit-height>
${this._routerPath && (this._tabs.length > 1 || (this._tabs.length === 1 && (this._hasRootGroups || this._hasRootProperties)))
${this._routerPath &&
(this._tabs.length > 1 || (this._tabs.length === 1 && (this._hasRootGroups || this._hasRootProperties)))
? html` <uui-tab-group slot="header">
${(this._hasRootGroups || this._hasRootProperties) && this._tabs.length > 0
? html`
<uui-tab
label="Content"
.active=${this._routerPath + '/' === this._activePath}
href=${this._routerPath + '/'}>
<umb-localize key="general_content">Content</umb-localize>
</uui-tab>
`
: ''}
? this.#renderTab(null, '#general_generic')
: nothing}
${repeat(
this._tabs,
(tab) => tab.name,
(tab) => {
const path = this._routerPath + '/tab/' + encodeFolderName(tab.name || '');
return html`<uui-tab
label=${this.localize.string(tab.name ?? '#general_unknown')}
.active=${path === this._activePath}
href=${path}>
${this.localize.string(tab.name)}
</uui-tab>`;
(tab, index) => {
const path = 'tab/' + encodeFolderName(tab.name || '');
return this.#renderTab(path, tab.name, index);
},
)}
</uui-tab-group>`
Expand All @@ -188,6 +176,20 @@
`;
}

#renderTab(path: string | null, name: string, index = 0) {
const hasRootItems = this._hasRootGroups || this._hasRootProperties;
const fullPath = this._routerPath + '/' + (path ? path : '');
const active =
fullPath === this._activePath ||
(!hasRootItems && index === 0 && this._routerPath + '/' === this._activePath) ||
(hasRootItems && path === null && this._routerPath + '/' === this._activePath);
return html`<uui-tab
label=${this.localize.string(name ?? '#general_unnamed')}
.active=${active}
href=${fullPath}
data-mark="content-tab:${path ?? 'root'}"></uui-tab>`;
}

static override readonly styles = [
UmbTextStyles,
css`
Expand Down
Loading