fix: on delete worker update selected worker properly

This commit is contained in:
Methapon Metanipat 2024-11-13 14:36:45 +07:00
parent e40e85102f
commit 6fe81fc47c

View file

@ -208,9 +208,17 @@ watch(
() => props.employeeRows,
(a, b) => {
if (a === undefined || b === undefined) return;
const removed = b.findIndex(
(c) => !a.find((d) => JSON.stringify(c) === JSON.stringify(d)),
);
if (a.length < b.length) {
rows.value.forEach((p) => {
const maxValue = Math.max(...p.workerIndex);
if (removed !== -1) {
p.workerIndex = p.workerIndex.map((i) => (i > removed ? i - 1 : i));
}
p.workerIndex = p.workerIndex.filter((i) => i !== maxValue);
});
}