|
|
@ -4,31 +4,27 @@ export default function mapDefaultDisplayValue<T extends ColumnType>( |
|
|
|
columnsArr: Array<T> |
|
|
|
columnsArr: Array<T> |
|
|
|
): void | T { |
|
|
|
): void | T { |
|
|
|
if (!columnsArr.some((column) => column.pv)) { |
|
|
|
if (!columnsArr.some((column) => column.pv)) { |
|
|
|
let len = columnsArr.length; |
|
|
|
const pkIndex = columnsArr.findIndex((column) => column.pk) |
|
|
|
let pkIndex = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (len--) { |
|
|
|
|
|
|
|
if (columnsArr[len].pk) { |
|
|
|
|
|
|
|
pkIndex = len; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if PK is at the end of table
|
|
|
|
// if PK is at the end of table
|
|
|
|
if (pkIndex === columnsArr.length - 1) { |
|
|
|
if (pkIndex === columnsArr.length - 1) { |
|
|
|
if (pkIndex > 0) { |
|
|
|
if (pkIndex > 0) { |
|
|
|
columnsArr[pkIndex - 1].pv = true; |
|
|
|
columnsArr[pkIndex - 1].pv = true; |
|
|
|
return columnsArr[pkIndex - 1]; |
|
|
|
return columnsArr[pkIndex - 1]; |
|
|
|
|
|
|
|
} else if (columnsArr.length > 0) { |
|
|
|
|
|
|
|
columnsArr[0].pv = true; |
|
|
|
|
|
|
|
return columnsArr[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// pk is not at the end of table
|
|
|
|
// pk is not at the end of table
|
|
|
|
else if (pkIndex > -1) { |
|
|
|
} else if (pkIndex > -1) {
|
|
|
|
columnsArr[pkIndex + 1].pv = true; |
|
|
|
columnsArr[pkIndex + 1].pv = true; |
|
|
|
return columnsArr[pkIndex + 1]; |
|
|
|
return columnsArr[pkIndex + 1]; |
|
|
|
} |
|
|
|
|
|
|
|
// no pk at all
|
|
|
|
// no pk at all
|
|
|
|
else { |
|
|
|
} else { |
|
|
|
// todo:
|
|
|
|
if (columnsArr.length > 0) { |
|
|
|
|
|
|
|
columnsArr[0].pv = true; |
|
|
|
|
|
|
|
return columnsArr[0]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|