Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class UmbDefaultCollectionContext<
}

setupView(viewElement: UmbControllerHost) {
// TODO: Consider to remove this one as well:
new UmbModalRouteRegistrationController(viewElement, UMB_WORKSPACE_MODAL)
.addAdditionalPath('entity/:entityType')
.onSetup((params) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { UMB_DOCUMENT_COLLECTION_CONTEXT } from '../document-collection.context-token.js';
import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '../../workspace/constants.js';
import { UMB_CREATE_DOCUMENT_WORKSPACE_PATH_PATTERN } from '../../paths.js';
import { UMB_DOCUMENT_ENTITY_TYPE, UMB_DOCUMENT_ROOT_ENTITY_TYPE } from '../../entity.js';
Expand All @@ -8,16 +7,12 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import type { ManifestCollectionAction } from '@umbraco-cms/backoffice/collection';
import type { UmbAllowedDocumentTypeModel } from '@umbraco-cms/backoffice/document-type';
import type { UmbEntityUnique } from '@umbraco-cms/backoffice/entity';
import type { UmbModalRouteBuilder } from '@umbraco-cms/backoffice/router';

@customElement('umb-create-document-collection-action')
export class UmbCreateDocumentCollectionActionElement extends UmbLitElement {
@state()
private _allowedDocumentTypes: Array<UmbAllowedDocumentTypeModel> = [];

@state()
private _workspacePathBuilder?: UmbModalRouteBuilder;

@state()
private _documentUnique?: UmbEntityUnique;

Expand All @@ -43,12 +38,6 @@ export class UmbCreateDocumentCollectionActionElement extends UmbLitElement {
this._documentTypeUnique = documentTypeUnique;
});
});

this.consumeContext(UMB_DOCUMENT_COLLECTION_CONTEXT, (collectionContext) => {
this.observe(collectionContext?.workspacePathBuilder, (builder) => {
this._workspacePathBuilder = builder;
});
});
}

override async firstUpdated() {
Expand All @@ -73,14 +62,14 @@ export class UmbCreateDocumentCollectionActionElement extends UmbLitElement {
}

#getCreateUrl(item: UmbAllowedDocumentTypeModel) {
return item.unique && this._workspacePathBuilder
? this._workspacePathBuilder({ entityType: UMB_DOCUMENT_ENTITY_TYPE }) +
UMB_CREATE_DOCUMENT_WORKSPACE_PATH_PATTERN.generateLocal({
parentEntityType: this._documentUnique ? UMB_DOCUMENT_ENTITY_TYPE : UMB_DOCUMENT_ROOT_ENTITY_TYPE,
parentUnique: this._documentUnique ?? 'null',
documentTypeUnique: item.unique,
})
: '';
if (!item.unique) {
throw new Error('Item unique is missing');
}
return UMB_CREATE_DOCUMENT_WORKSPACE_PATH_PATTERN.generateAbsolute({
parentEntityType: this._documentUnique ? UMB_DOCUMENT_ENTITY_TYPE : UMB_DOCUMENT_ROOT_ENTITY_TYPE,
parentUnique: this._documentUnique ?? 'null',
documentTypeUnique: item.unique,
});
}

override render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import type { UmbDocumentCollectionFilterModel, UmbDocumentCollectionItemModel }
import { css, customElement, html, repeat, state } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import type { UmbDefaultCollectionContext, UmbCollectionColumnConfiguration } from '@umbraco-cms/backoffice/collection';
import type { UmbModalRouteBuilder } from '@umbraco-cms/backoffice/router';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';

import '@umbraco-cms/backoffice/ufm';
import './document-grid-collection-card.element.js';

@customElement('umb-document-grid-collection-view')
export class UmbDocumentGridCollectionViewElement extends UmbLitElement {
@state()
private _workspacePathBuilder?: UmbModalRouteBuilder;

@state()
private _items: Array<UmbDocumentCollectionItemModel> = [];

Expand All @@ -32,13 +28,6 @@ export class UmbDocumentGridCollectionViewElement extends UmbLitElement {
this.consumeContext(UMB_DOCUMENT_COLLECTION_CONTEXT, (collectionContext) => {
this.#collectionContext = collectionContext;
collectionContext?.setupView(this);
this.observe(
collectionContext?.workspacePathBuilder,
(builder) => {
this._workspacePathBuilder = builder;
},
'observePath',
);
this.#observeCollectionContext();
});
}
Expand Down Expand Up @@ -76,12 +65,9 @@ export class UmbDocumentGridCollectionViewElement extends UmbLitElement {
}

#getEditUrl(item: UmbDocumentCollectionItemModel) {
return item.unique && this._workspacePathBuilder
? this._workspacePathBuilder({ entityType: item.entityType }) +
UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN.generateLocal({
unique: item.unique,
})
: '';
return UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN.generateAbsolute({
unique: item.unique,
});
}

override render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { css, customElement, html, state } from '@umbraco-cms/backoffice/externa
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import type { UmbCollectionColumnConfiguration } from '@umbraco-cms/backoffice/collection';
import type { UmbModalRouteBuilder } from '@umbraco-cms/backoffice/router';
import type {
UmbTableColumn,
UmbTableConfig,
Expand All @@ -24,9 +23,6 @@ import './column-layouts/document-table-column-state.element.js';

@customElement('umb-document-table-collection-view')
export class UmbDocumentTableCollectionViewElement extends UmbLitElement {
@state()
private _workspacePathBuilder?: UmbModalRouteBuilder;

@state()
private _userDefinedProperties?: Array<UmbCollectionColumnConfiguration>;

Expand Down Expand Up @@ -70,16 +66,6 @@ export class UmbDocumentTableCollectionViewElement extends UmbLitElement {
this.consumeContext(UMB_DOCUMENT_COLLECTION_CONTEXT, (collectionContext) => {
this.#collectionContext = collectionContext;
collectionContext?.setupView(this);
this.observe(
collectionContext?.workspacePathBuilder,
(builder) => {
this._workspacePathBuilder = builder;
if (this.#collectionContext) {
this.#createTableItems(this.#collectionContext.getItems());
}
},
'observePath',
);
this.#observeCollectionContext();
});
}
Expand Down Expand Up @@ -148,13 +134,9 @@ export class UmbDocumentTableCollectionViewElement extends UmbLitElement {
};
}

const editPath =
item.unique && this._workspacePathBuilder
? this._workspacePathBuilder({ entityType: item.entityType }) +
UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN.generateLocal({
unique: item.unique,
})
: '';
const editPath = UMB_EDIT_DOCUMENT_WORKSPACE_PATH_PATTERN.generateAbsolute({
unique: item.unique,
});

return {
columnAlias: column.alias,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { UMB_MEDIA_COLLECTION_CONTEXT } from '../media-collection.context-token.js';
import { UMB_MEDIA_WORKSPACE_CONTEXT } from '../../constants.js';
import { UMB_CREATE_MEDIA_WORKSPACE_PATH_PATTERN } from '../../paths.js';
import { UMB_MEDIA_ENTITY_TYPE, UMB_MEDIA_ROOT_ENTITY_TYPE } from '../../entity.js';
Expand All @@ -8,16 +7,12 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import type { ManifestCollectionAction } from '@umbraco-cms/backoffice/collection';
import type { UmbAllowedMediaTypeModel } from '@umbraco-cms/backoffice/media-type';
import type { UmbEntityUnique } from '@umbraco-cms/backoffice/entity';
import type { UmbModalRouteBuilder } from '@umbraco-cms/backoffice/router';

@customElement('umb-create-media-collection-action')
export class UmbCreateMediaCollectionActionElement extends UmbLitElement {
@state()
private _allowedMediaTypes: Array<UmbAllowedMediaTypeModel> = [];

@state()
private _workspacePathBuilder?: UmbModalRouteBuilder;

@state()
private _mediaUnique?: UmbEntityUnique;

Expand All @@ -44,12 +39,6 @@ export class UmbCreateMediaCollectionActionElement extends UmbLitElement {
this._mediaTypeUnique = mediaTypeUnique;
});
});

this.consumeContext(UMB_MEDIA_COLLECTION_CONTEXT, (collectionContext) => {
this.observe(collectionContext?.workspacePathBuilder, (builder) => {
this._workspacePathBuilder = builder;
});
});
}

override async firstUpdated() {
Expand All @@ -71,14 +60,14 @@ export class UmbCreateMediaCollectionActionElement extends UmbLitElement {
}

#getCreateUrl(item: UmbAllowedMediaTypeModel) {
return item.unique && this._workspacePathBuilder
? this._workspacePathBuilder({ entityType: UMB_MEDIA_ENTITY_TYPE }) +
UMB_CREATE_MEDIA_WORKSPACE_PATH_PATTERN.generateLocal({
parentEntityType: this._mediaUnique ? UMB_MEDIA_ENTITY_TYPE : UMB_MEDIA_ROOT_ENTITY_TYPE,
parentUnique: this._mediaUnique ?? 'null',
mediaTypeUnique: item.unique,
})
: '';
if (!item.unique) {
throw new Error('Item does not have a unique identifier');
}
return UMB_CREATE_MEDIA_WORKSPACE_PATH_PATTERN.generateAbsolute({
parentEntityType: this._mediaUnique ? UMB_MEDIA_ENTITY_TYPE : UMB_MEDIA_ROOT_ENTITY_TYPE,
parentUnique: this._mediaUnique ?? 'null',
mediaTypeUnique: item.unique,
});
}

override render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import { css, customElement, html, ifDefined, repeat, state } from '@umbraco-cms
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import { UmbFileDropzoneItemStatus } from '@umbraco-cms/backoffice/dropzone';
import type { UmbModalRouteBuilder } from '@umbraco-cms/backoffice/router';

import '@umbraco-cms/backoffice/imaging';

@customElement('umb-media-grid-collection-view')
export class UmbMediaGridCollectionViewElement extends UmbLitElement {
@state()
private _workspacePathBuilder?: UmbModalRouteBuilder;

@state()
private _items: Array<UmbMediaCollectionItemModel> = [];

Expand All @@ -29,13 +25,6 @@ export class UmbMediaGridCollectionViewElement extends UmbLitElement {
this.consumeContext(UMB_MEDIA_COLLECTION_CONTEXT, (collectionContext) => {
this.#collectionContext = collectionContext;
collectionContext?.setupView(this);
this.observe(
collectionContext?.workspacePathBuilder,
(builder) => {
this._workspacePathBuilder = builder;
},
'observePath',
);
this.#observeCollectionContext();
});
}
Expand Down Expand Up @@ -69,12 +58,7 @@ export class UmbMediaGridCollectionViewElement extends UmbLitElement {
}

#getEditUrl(item: UmbMediaCollectionItemModel) {
return item.unique && this._workspacePathBuilder
? this._workspacePathBuilder({ entityType: item.entityType }) +
UMB_EDIT_MEDIA_WORKSPACE_PATH_PATTERN.generateLocal({
unique: item.unique,
})
: '';
return UMB_EDIT_MEDIA_WORKSPACE_PATH_PATTERN.generateAbsolute({ unique: item.unique });
}

override render() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UMB_EDIT_MEDIA_WORKSPACE_PATH_PATTERN } from '../../../paths.js';

Check notice on line 1 in src/Umbraco.Web.UI.Client/src/packages/media/media/collection/views/table/media-table-collection-view.element.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (v17/dev)

✅ No longer an issue: Overall Code Complexity

The mean cyclomatic complexity in this module is no longer above the threshold
import type { UmbMediaCollectionItemModel } from '../../types.js';
import { UMB_MEDIA_COLLECTION_CONTEXT } from '../../media-collection.context-token.js';
import { css, customElement, html, state } from '@umbraco-cms/backoffice/external/lit';
Expand All @@ -16,16 +16,12 @@
} from '@umbraco-cms/backoffice/components';

import './column-layouts/media-table-column-name.element.js';
import type { UmbModalRouteBuilder } from '@umbraco-cms/backoffice/router';

@customElement('umb-media-table-collection-view')
export class UmbMediaTableCollectionViewElement extends UmbLitElement {
@state()
private _userDefinedProperties?: Array<UmbCollectionColumnConfiguration>;

@state()
private _workspacePathBuilder?: UmbModalRouteBuilder;

@state()
private _items?: Array<UmbMediaCollectionItemModel>;

Expand Down Expand Up @@ -60,14 +56,6 @@
this.#collectionContext = collectionContext;
this.#observeCollectionContext();
collectionContext?.setupView(this);
this.observe(
collectionContext?.workspacePathBuilder,
(builder) => {
this._workspacePathBuilder = builder;
this.#createTableItems();
},
'observePath',
);
});
}

Expand Down Expand Up @@ -126,37 +114,32 @@
#createTableItems() {
this._tableItems = [];

if (this._items === undefined) return;
if (this._workspacePathBuilder === undefined) return;

if (this._tableColumns.length === 0) {
this.#createTableHeadings();
}

this._tableItems = this._items.map((item) => {
if (!item.unique) throw new Error('Item id is missing.');

const data =
this._tableColumns?.map((column) => {
if (column.alias === 'entityActions') {
return {
columnAlias: 'entityActions',
value: html`<umb-entity-actions-table-column-view
.value=${{
entityType: item.entityType,
unique: item.unique,
name: item.name,
}}></umb-entity-actions-table-column-view>`,
};
}

const editPath =
item.unique && this._workspacePathBuilder
? this._workspacePathBuilder({ entityType: item.entityType }) +
UMB_EDIT_MEDIA_WORKSPACE_PATH_PATTERN.generateLocal({
unique: item.unique,
})
: '';
const editPath = UMB_EDIT_MEDIA_WORKSPACE_PATH_PATTERN.generateAbsolute({
unique: item.unique,
});

Check notice on line 142 in src/Umbraco.Web.UI.Client/src/packages/media/media/collection/views/table/media-table-collection-view.element.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (v17/dev)

✅ No longer an issue: Complex Method

UmbMediaTableCollectionViewElement.createTableItems 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.

return {
columnAlias: column.alias,
Expand Down
Loading