33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import type { ElaprApln } from "@/entities/elapr";
|
|
|
|
import { assignAtrzSeqNumbers } from "./assign-atrz-seq";
|
|
import { getVisibleRows } from "./validators";
|
|
import type { ElaprAplnRow } from "../model/apln-row-types";
|
|
|
|
function rowDiffersFromServer(row: ElaprAplnRow, serverRow: ElaprApln): boolean {
|
|
return (
|
|
row.aprvrUuid !== serverRow.aprvrUuid ||
|
|
row.atrzSeComCd !== serverRow.atrzSeComCd ||
|
|
row.atrzSeqNo !== serverRow.atrzSeqNo
|
|
);
|
|
}
|
|
|
|
export function hasUnsavedChanges(rows: ElaprAplnRow[], serverRows: ElaprApln[]): boolean {
|
|
if (rows.some((row) => row.isDeleted && row.aplnId)) return true;
|
|
if (rows.some((row) => row.isNew && !row.isDeleted)) return true;
|
|
|
|
const visibleWithSeq = assignAtrzSeqNumbers(getVisibleRows(rows));
|
|
|
|
for (const row of visibleWithSeq) {
|
|
if (row.isNew) continue;
|
|
if (!row.aplnId) continue;
|
|
if (row.isDirty) return true;
|
|
|
|
const serverRow = serverRows.find((s) => s.aplnId === row.aplnId);
|
|
if (!serverRow) continue;
|
|
if (rowDiffersFromServer(row, serverRow)) return true;
|
|
}
|
|
|
|
return false;
|
|
}
|