Skip to content
Merged
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 @@ -8,6 +8,7 @@
import { createExtensionApiByAlias } from '@umbraco-cms/backoffice/extension-registry';
import { UmbPaginationManager } from '@umbraco-cms/backoffice/utils';
import { observeMultiple } from '@umbraco-cms/backoffice/observable-api';
import type { UUIButtonState } from '@umbraco-cms/backoffice/external/uui';
import type {
UmbTableColumn,
UmbTableConfig,
Expand Down Expand Up @@ -46,6 +47,9 @@
@state()
private _sortable = false;

@state()
private _submitButtonState?: UUIButtonState;

protected _sortedUniques = new Set<string>();

#pagination = new UmbPaginationManager();
Expand Down Expand Up @@ -135,21 +139,32 @@
}

async #onSubmit(event: PointerEvent) {
if (this._submitButtonState === 'waiting') return;
event?.stopPropagation();
if (!this.data?.sortChildrenOfRepositoryAlias) throw new Error('sortChildrenOfRepositoryAlias is required');

const sortChildrenOfRepository = await createExtensionApiByAlias<UmbSortChildrenOfRepository>(
this,
this.data.sortChildrenOfRepositoryAlias,
);
this._submitButtonState = 'waiting';

const { error } = await sortChildrenOfRepository.sortChildrenOf({
unique: this.data.unique,
sorting: this.#getSortOrderOfSortedItems(),
});
try {
const sortChildrenOfRepository = await createExtensionApiByAlias<UmbSortChildrenOfRepository>(
this,
this.data.sortChildrenOfRepositoryAlias,
);

if (!error) {
this._submitModal();
const { error } = await sortChildrenOfRepository.sortChildrenOf({
unique: this.data.unique,
sorting: this.#getSortOrderOfSortedItems(),
});

if (!error) {
this._submitButtonState = 'success';
this._submitModal();
} else {
this._submitButtonState = 'failed';
}
} catch (error) {
this._submitButtonState = 'failed';
throw error;

Check warning on line 167 in src/Umbraco.Web.UI.Client/src/packages/core/tree/entity-actions/sort-children-of/modal/sort-children-of-modal.element.ts

View check run for this annotation

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

❌ New issue: Complex Method

UmbSortChildrenOfModalElement.onSubmit has a cyclomatic complexity of 9, 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.
}
}

Expand Down Expand Up @@ -213,7 +228,13 @@
<umb-body-layout headline=${this.localize.term('actions_sort')}>
${this._children.length === 0 ? this.#renderEmptyState() : this.#renderTable()}
<uui-button slot="actions" label=${this.localize.term('general_cancel')} @click="${this._rejectModal}"></uui-button>
<uui-button slot="actions" color="positive" look="primary" label=${this.localize.term('general_sort')} @click=${this.#onSubmit}></uui-button>
<uui-button
slot="actions"
color="positive"
look="primary"
label=${this.localize.term('general_sort')}
.state=${this._submitButtonState}
@click=${this.#onSubmit}></uui-button>
</umb-body-layout>
`;
}
Expand Down
Loading