move common properties to IListable

This commit is contained in:
Dan Percic 2021-09-25 10:43:26 +03:00
parent 29c267104e
commit 93b5ea7f89
3 changed files with 9 additions and 5 deletions

View File

@ -21,6 +21,9 @@ export abstract class ListingComponent<T extends IListable> extends AutoUnsubscr
readonly noContent$ = this._noContent$;
readonly sortedDisplayedEntities$ = this._sortedDisplayedEntities$;
readonly listingMode$: Observable<ListingMode>;
/**
* @deprecated Use routerLink getter from IListable
*/
readonly routerLinkFn?: (entity: T) => string | string[];
abstract readonly tableColumnConfigs: readonly TableColumnConfig<T>[];
@ -30,8 +33,8 @@ export abstract class ListingComponent<T extends IListable> 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<T>;
private readonly _listingMode$ = new BehaviorSubject<ListingMode>(ListingModes.table);
protected constructor(protected readonly _injector: Injector) {
@ -87,6 +90,6 @@ export abstract class ListingComponent<T extends IListable> extends AutoUnsubscr
@Bind()
trackByPrimaryKey(index: number, item: T): unknown {
return item[this._primaryKey];
return item.searchKey ?? item[this._primaryKey];
}
}

View File

@ -1,4 +1,5 @@
export interface IListable {
readonly id: string;
readonly searchKey?: string;
readonly routerLink?: string;
}

View File

@ -7,9 +7,9 @@
* // Expect: "name | setName | someKeys | someFn"
* type Keys = KeysOf<Object>;
*/
export type KeysOf<T> = {
[K in keyof T]: K;
}[keyof T];
export type KeysOf<Type, ExtendedType = unknown> = {
[Key in keyof Type]: Type[Key] extends ExtendedType ? Key : never;
}[keyof Type];
/**
* ValuesOf