All files / src/table/util get-row-key-from-record-key.ts

100% Statements 10/10
100% Branches 4/4
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17      10x 10x 3x 7x 6x 48x       4x   10x    
import { TableProps } from "../TableProps";
 
export function getRowKeyFromRecordKey(recordKey: TableProps["recordKey"]) {
  let getRowKey: Exclude<typeof recordKey, string> = null;
  if (typeof recordKey === "function") {
    getRowKey = recordKey;
  } else if (typeof recordKey === "string") {
    const keyName = recordKey;
    getRowKey = (record, recordIndex) => String(record[keyName]);
  } else {
    // 如果未提供 rowKey,使用索引生成
    // TODO: 输出告警
    getRowKey = (record, recordIndex) => `record_${recordIndex}`;
  }
  return getRowKey;
}