diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/models/index.ts b/src/Umbraco.Web.UI.Client/src/packages/core/models/index.ts index 6c6bb47ba0..a95a2244a8 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/models/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/models/index.ts @@ -50,8 +50,3 @@ export interface UmbUniqueItemModel { name: string; icon?: string; } - -export enum UmbDirectionModel { - ASCENDING = 'Ascending', - DESCENDING = 'Descending', -} diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/utils/direction/index.ts b/src/Umbraco.Web.UI.Client/src/packages/core/utils/direction/index.ts new file mode 100644 index 0000000000..d427c102b1 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/utils/direction/index.ts @@ -0,0 +1,6 @@ +export type UmbDirectionType = 'Ascending' | 'Descending'; + +export const UmbDirection = Object.freeze({ + ASCENDING: 'Ascending', + DESCENDING: 'Descending', +}); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/utils/index.ts b/src/Umbraco.Web.UI.Client/src/packages/core/utils/index.ts index 3782c9eb05..ad688e29d5 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/utils/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/utils/index.ts @@ -1,3 +1,6 @@ +export * from './debounce/debounce.function.js'; +export * from './direction/index.js'; +export * from './download/blob-download.function.js'; export * from './get-processed-image-url.function.js'; export * from './math/math.js'; export * from './pagination-manager/pagination.manager.js'; @@ -7,11 +10,9 @@ export * from './path/path-encode.function.js'; export * from './path/path-folder-name.function.js'; export * from './path/umbraco-path.function.js'; export * from './selection-manager/selection.manager.js'; +export * from './string/from-camel-case.function.js'; export * from './string/generate-umbraco-alias.function.js'; export * from './string/increment-string.function.js'; export * from './string/split-string-to-array.js'; -export * from './type/diff.type.js'; export * from './string/to-camel-case/to-camel-case.function.js'; -export * from './string/from-camel-case.function.js'; -export * from './debounce/debounce.function.js'; -export * from './download/blob-download.function.js'; +export * from './type/diff.type.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/repository/user-collection.server.data-source.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/repository/user-collection.server.data-source.ts index eaf765fd5a..37b5078a7a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/repository/user-collection.server.data-source.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/repository/user-collection.server.data-source.ts @@ -37,17 +37,16 @@ export class UmbUserCollectionServerDataSource implements UmbCollectionDataSourc * @memberof UmbUserCollectionServerDataSource */ async getCollection(filter: UmbUserCollectionFilterModel) { - // TODO: This is a temporary workaround to avoid a type error. const { data, error } = await tryExecuteAndNotify( this.#host, UserService.getFilterUser({ filter: filter.filter, - orderBy: filter.orderBy as unknown as UserOrderModel, - orderDirection: filter.orderDirection as unknown as DirectionModel, + orderBy: filter.orderBy as unknown as UserOrderModel, // TODO: This is a temporary workaround to avoid a type error. + orderDirection: filter.orderDirection as unknown as DirectionModel, // TODO: This is a temporary workaround to avoid a type error. skip: filter.skip, take: filter.take, userGroupIds: filter.userGroupIds, - userStates: filter.userStates as unknown as Array, + userStates: filter.userStates as unknown as Array, // TODO: This is a temporary workaround to avoid a type error. }), ); diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/types.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/types.ts index 1a259f10f1..a1d5e5c99a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/types.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/types.ts @@ -1,12 +1,13 @@ -import type { UmbDirectionModel } from '@umbraco-cms/backoffice/models'; +import type { UmbUserOrderByType, UmbUserStateFilterType } from './utils/index.js'; +import type { UmbDirectionType } from '@umbraco-cms/backoffice/utils'; export interface UmbUserCollectionFilterModel { skip?: number; take?: number; - orderBy?: UmbUserOrderByModel; - orderDirection?: UmbDirectionModel; + orderBy?: UmbUserOrderByType; + orderDirection?: UmbDirectionType; userGroupIds?: string[]; - userStates?: UmbUserStateFilterModel[]; + userStates?: UmbUserStateFilterType[]; filter?: string; } @@ -14,22 +15,7 @@ export interface UmbUserOrderByOption { unique: string; label: string; config: { - orderBy: UmbUserOrderByModel; - orderDirection: UmbDirectionModel; + orderBy: UmbUserOrderByType; + orderDirection: UmbDirectionType; }; } - -export enum UmbUserOrderByModel { - NAME = 'Name', - CREATE_DATE = 'CreateDate', - LAST_LOGIN_DATE = 'LastLoginDate', -} - -export enum UmbUserStateFilterModel { - ACTIVE = 'Active', - DISABLED = 'Disabled', - LOCKED_OUT = 'LockedOut', - INVITED = 'Invited', - INACTIVE = 'Inactive', - ALL = 'All', -} diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/user-collection-header.element.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/user-collection-header.element.ts index 375bbd302d..4147e35f1d 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/user-collection-header.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/user-collection-header.element.ts @@ -1,6 +1,7 @@ import type { UmbUserCollectionContext } from './user-collection.context.js'; import type { UmbUserOrderByOption } from './types.js'; -import { UmbUserStateFilterModel } from './types.js'; +import type { UmbUserStateFilterType } from './utils/index.js'; +import { UmbUserStateFilter } from './utils/index.js'; import type { UUIBooleanInputEvent, UUICheckboxElement } from '@umbraco-cms/backoffice/external/uui'; import { css, html, customElement, state, repeat, ifDefined } from '@umbraco-cms/backoffice/external/lit'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; @@ -12,10 +13,10 @@ import { observeMultiple } from '@umbraco-cms/backoffice/observable-api'; @customElement('umb-user-collection-header') export class UmbUserCollectionHeaderElement extends UmbLitElement { @state() - private _stateFilterOptions: Array = Object.values(UmbUserStateFilterModel); + private _stateFilterOptions: Array = Object.values(UmbUserStateFilter); @state() - private _stateFilterSelection: Array = []; + private _stateFilterSelection: Array = []; @state() private _userGroups: Array = []; @@ -84,7 +85,7 @@ export class UmbUserCollectionHeaderElement extends UmbLitElement { #onStateFilterChange(event: UUIBooleanInputEvent) { event.stopPropagation(); const target = event.currentTarget as UUICheckboxElement; - const value = target.value as UmbUserStateFilterModel; + const value = target.value as UmbUserStateFilterType; const isChecked = target.checked; this._stateFilterSelection = isChecked diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/user-collection.context.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/user-collection.context.ts index 7246c8ee7d..3c81c52ace 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/user-collection.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/user-collection.context.ts @@ -1,51 +1,53 @@ import type { UmbUserDetailModel } from '../types.js'; import { UMB_COLLECTION_VIEW_USER_GRID } from './views/index.js'; -import type { UmbUserCollectionFilterModel, UmbUserOrderByOption, UmbUserStateFilterModel } from './types.js'; -import { UmbUserOrderByModel } from './types.js'; +import type { UmbUserCollectionFilterModel, UmbUserOrderByOption } from './types.js'; +import type { UmbUserOrderByType, UmbUserStateFilterType } from './utils/index.js'; +import { UmbUserOrderBy } from './utils/index.js'; import { UmbDefaultCollectionContext } from '@umbraco-cms/backoffice/collection'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; -import { UmbDirectionModel } from '@umbraco-cms/backoffice/models'; import { UmbArrayState, UmbStringState } from '@umbraco-cms/backoffice/observable-api'; +import type { UmbDirectionType } from '@umbraco-cms/backoffice/utils'; +import { UmbDirection } from '@umbraco-cms/backoffice/utils'; const orderByOptions: Array = [ { unique: 'nameAscending', label: '#user_sortNameAscending', config: { - orderBy: UmbUserOrderByModel.NAME, - orderDirection: UmbDirectionModel.ASCENDING, + orderBy: UmbUserOrderBy.NAME, + orderDirection: UmbDirection.ASCENDING, }, }, { unique: 'nameDescending', label: '#user_sortNameDescending', config: { - orderBy: UmbUserOrderByModel.NAME, - orderDirection: UmbDirectionModel.DESCENDING, + orderBy: UmbUserOrderBy.NAME, + orderDirection: UmbDirection.DESCENDING, }, }, { unique: 'createDateDescending', label: '#user_sortCreateDateDescending', config: { - orderBy: UmbUserOrderByModel.CREATE_DATE, - orderDirection: UmbDirectionModel.DESCENDING, + orderBy: UmbUserOrderBy.CREATE_DATE, + orderDirection: UmbDirection.DESCENDING, }, }, { unique: 'createDateAscending', label: '#user_sortCreateDateAscending', config: { - orderBy: UmbUserOrderByModel.CREATE_DATE, - orderDirection: UmbDirectionModel.ASCENDING, + orderBy: UmbUserOrderBy.CREATE_DATE, + orderDirection: UmbDirection.ASCENDING, }, }, { unique: 'lastLoginDateDescending', label: '#user_sortLastLoginDateDescending', config: { - orderBy: UmbUserOrderByModel.LAST_LOGIN_DATE, - orderDirection: UmbDirectionModel.DESCENDING, + orderBy: UmbUserOrderBy.LAST_LOGIN_DATE, + orderDirection: UmbDirection.DESCENDING, }, }, ]; @@ -73,9 +75,8 @@ export class UmbUserCollectionContext extends UmbDefaultCollectionContext< } /** - * Sets the active order by for the collection and refreshes the collection. - * @param {UmbUserOrderByModel} orderBy - * @param {UmbDirectionModel} orderDirection + * Sets the active order by option for the collection and refreshes the collection. + * @param {string} unique * @memberof UmbUserCollectionContext */ setActiveOrderByOption(unique: string) { @@ -89,7 +90,7 @@ export class UmbUserCollectionContext extends UmbDefaultCollectionContext< * @param {Array} selection * @memberof UmbUserCollectionContext */ - setStateFilter(selection: Array) { + setStateFilter(selection: Array) { this.setFilter({ userStates: selection }); } @@ -98,7 +99,7 @@ export class UmbUserCollectionContext extends UmbDefaultCollectionContext< * @param {UmbUserOrderByModel} orderBy * @memberof UmbUserCollectionContext */ - setOrderByFilter(orderBy: UmbUserOrderByModel) { + setOrderByFilter(orderBy: UmbUserOrderByType) { this.setFilter({ orderBy }); } @@ -113,10 +114,10 @@ export class UmbUserCollectionContext extends UmbDefaultCollectionContext< /** * Sets the order direction filter for the collection and refreshes the collection. - * @param {UmbDirectionModel} orderDirection + * @param {any} orderDirection * @memberof UmbUserCollectionContext */ - setOrderDirectionFilter(orderDirection: UmbDirectionModel) { + setOrderDirectionFilter(orderDirection: UmbDirectionType) { this.setFilter({ orderDirection }); } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/utils/index.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/utils/index.ts new file mode 100644 index 0000000000..21a5ac4fb3 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/user/user/collection/utils/index.ts @@ -0,0 +1,18 @@ +export type UmbUserOrderByType = 'Name' | 'CreateDate' | 'LastLoginDate'; + +export const UmbUserOrderBy = Object.freeze({ + NAME: 'Name', + CREATE_DATE: 'CreateDate', + LAST_LOGIN_DATE: 'LastLoginDate', +}); + +export type UmbUserStateFilterType = 'Active' | 'Disabled' | 'LockedOut' | 'Invited' | 'Inactive' | 'All'; + +export const UmbUserStateFilter = Object.freeze({ + ACTIVE: 'Active', + DISABLED: 'Disabled', + LOCKED_OUT: 'LockedOut', + INVITED: 'Invited', + INACTIVE: 'Inactive', + ALL: 'All', +});