From 93b5ea7f898e50335dabe63e6cf963fbb6409386 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Sat, 25 Sep 2021 10:43:26 +0300 Subject: [PATCH] move common properties to IListable --- src/lib/listing/listing-component.directive.ts | 7 +++++-- src/lib/listing/models/listable.ts | 1 + src/lib/utils/types/utility-types.ts | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lib/listing/listing-component.directive.ts b/src/lib/listing/listing-component.directive.ts index c6d30f0..459cd89 100644 --- a/src/lib/listing/listing-component.directive.ts +++ b/src/lib/listing/listing-component.directive.ts @@ -21,6 +21,9 @@ export abstract class ListingComponent extends AutoUnsubscr readonly noContent$ = this._noContent$; readonly sortedDisplayedEntities$ = this._sortedDisplayedEntities$; readonly listingMode$: Observable; + /** + * @deprecated Use routerLink getter from IListable + */ readonly routerLinkFn?: (entity: T) => string | string[]; abstract readonly tableColumnConfigs: readonly TableColumnConfig[]; @@ -30,8 +33,8 @@ export abstract class ListingComponent extends AutoUnsubscr * Key used in the *trackBy* function with **ngFor* or **cdkVirtualFor* * and in the default sorting and as the search field * @protected + * @deprecated Use searchKey getter from IListable */ - protected abstract readonly _primaryKey: KeysOf; private readonly _listingMode$ = new BehaviorSubject(ListingModes.table); protected constructor(protected readonly _injector: Injector) { @@ -87,6 +90,6 @@ export abstract class ListingComponent extends AutoUnsubscr @Bind() trackByPrimaryKey(index: number, item: T): unknown { - return item[this._primaryKey]; + return item.searchKey ?? item[this._primaryKey]; } } diff --git a/src/lib/listing/models/listable.ts b/src/lib/listing/models/listable.ts index f262be6..55857ca 100644 --- a/src/lib/listing/models/listable.ts +++ b/src/lib/listing/models/listable.ts @@ -1,4 +1,5 @@ export interface IListable { readonly id: string; + readonly searchKey?: string; readonly routerLink?: string; } diff --git a/src/lib/utils/types/utility-types.ts b/src/lib/utils/types/utility-types.ts index 7d680c2..1df4fa4 100644 --- a/src/lib/utils/types/utility-types.ts +++ b/src/lib/utils/types/utility-types.ts @@ -7,9 +7,9 @@ * // Expect: "name | setName | someKeys | someFn" * type Keys = KeysOf; */ -export type KeysOf = { - [K in keyof T]: K; -}[keyof T]; +export type KeysOf = { + [Key in keyof Type]: Type[Key] extends ExtendedType ? Key : never; +}[keyof Type]; /** * ValuesOf