use objects instead of enums

This commit is contained in:
Mads Rasmussen
2024-04-18 15:28:14 +02:00
parent e984e23b49
commit d8b659291e
8 changed files with 65 additions and 58 deletions

View File

@@ -50,8 +50,3 @@ export interface UmbUniqueItemModel {
name: string;
icon?: string;
}
export enum UmbDirectionModel {
ASCENDING = 'Ascending',
DESCENDING = 'Descending',
}

View File

@@ -0,0 +1,6 @@
export type UmbDirectionType = 'Ascending' | 'Descending';
export const UmbDirection = Object.freeze({
ASCENDING: 'Ascending',
DESCENDING: 'Descending',
});

View File

@@ -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';

View File

@@ -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<UserStateModel>,
userStates: filter.userStates as unknown as Array<UserStateModel>, // TODO: This is a temporary workaround to avoid a type error.
}),
);

View File

@@ -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',
}

View File

@@ -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<UmbUserStateFilterModel> = Object.values(UmbUserStateFilterModel);
private _stateFilterOptions: Array<UmbUserStateFilterType> = Object.values(UmbUserStateFilter);
@state()
private _stateFilterSelection: Array<UmbUserStateFilterModel> = [];
private _stateFilterSelection: Array<UmbUserStateFilterType> = [];
@state()
private _userGroups: Array<UmbUserGroupDetailModel> = [];
@@ -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

View File

@@ -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<UmbUserOrderByOption> = [
{
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<UmbUserStateFilterModel>} selection
* @memberof UmbUserCollectionContext
*/
setStateFilter(selection: Array<UmbUserStateFilterModel>) {
setStateFilter(selection: Array<UmbUserStateFilterType>) {
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 });
}
}

View File

@@ -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',
});