dynamicCellValidation() built its editors/getdynamiccolvals payload from a raw dataSource row clone, which always carries the client-only EDIT_STATUS column - unlike saveTable()'s submit path, nothing stripped it before the request went out. Extracted the strip logic (previously private to classifyRow) into a shared withoutEditStatus util and applied it here too.
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { withoutEditStatus } from './withoutEditStatus'
|
|
|
|
export type RowEditStatus = 'M' | 'A' | 'D' | 'U'
|
|
|
|
/**
|
|
* Classifies a single row as Modified/Added/Deleted/Unchanged against the
|
|
* pre-edit snapshot (`dataSourceUnchanged`), PK-matched via `headerPks`.
|
|
*
|
|
* Extracted from editor.component.ts's getRowsSubmittingCount(), which used
|
|
* this same logic inline, only at submit time. Kept here as a pure function
|
|
* so it can run live (e.g. on every afterChange, for the EDIT_STATUS column)
|
|
* without duplicating the diffing rules.
|
|
*/
|
|
export const classifyRow = (
|
|
dataRow: any,
|
|
dataSourceUnchanged: any[],
|
|
headerPks: string[]
|
|
): RowEditStatus => {
|
|
if (dataRow._____DELETE__THIS__RECORD_____ === 'Yes') return 'D'
|
|
|
|
const dataRowUnchanged = dataSourceUnchanged.find((row: any) => {
|
|
for (const pkCol of headerPks) {
|
|
if (row[pkCol] !== dataRow[pkCol]) return false
|
|
}
|
|
|
|
return true
|
|
})
|
|
|
|
if (!dataRowUnchanged) return 'A'
|
|
|
|
// EDIT_STATUS holds this very function's own prior output - comparing it
|
|
// like any other field would self-perpetuate: once a row is written as
|
|
// 'M', its EDIT_STATUS would forever differ from the unchanged snapshot's
|
|
// 'U' even after the real edit is reverted, permanently stuck on 'M'.
|
|
return JSON.stringify(withoutEditStatus(dataRow)) !==
|
|
JSON.stringify(withoutEditStatus(dataRowUnchanged))
|
|
? 'M'
|
|
: 'U'
|
|
}
|