mirror of https://github.com/portainer/portainer
fix(ui/datatables): simplify getRowId
parent
bb7c6077d5
commit
ca4130b221
|
@ -1,25 +1,17 @@
|
||||||
import { DefaultType } from './types';
|
import { DefaultType } from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets row id by looking for one of id, Id, or ID keys on the object
|
||||||
|
*/
|
||||||
export function defaultGetRowId<D extends DefaultType>(row: D): string {
|
export function defaultGetRowId<D extends DefaultType>(row: D): string {
|
||||||
if (
|
const key = ['id', 'Id', 'ID'].find((key) =>
|
||||||
'id' in row &&
|
Object.hasOwn(row, key)
|
||||||
(typeof row.id === 'string' || typeof row.id === 'number')
|
) as keyof D;
|
||||||
) {
|
|
||||||
return row.id.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
const value = row[key];
|
||||||
'Id' in row &&
|
|
||||||
(typeof row.Id === 'string' || typeof row.Id === 'number')
|
|
||||||
) {
|
|
||||||
return row.Id.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (typeof value === 'string' || typeof value === 'number') {
|
||||||
'ID' in row &&
|
return value.toString();
|
||||||
(typeof row.ID === 'string' || typeof row.ID === 'number')
|
|
||||||
) {
|
|
||||||
return row.ID.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
|
|
Loading…
Reference in New Issue