фикс sort-order при удалении/добавлении
This commit is contained in:
parent
022aa7b186
commit
dc621a1223
@ -84,7 +84,6 @@ export function updateCells(data, newRows) {
|
|||||||
Object.keys(newData).forEach((key) => {
|
Object.keys(newData).forEach((key) => {
|
||||||
if (row.data && row.data[key]) {
|
if (row.data && row.data[key]) {
|
||||||
if (typeof row.data[key] === "object") {
|
if (typeof row.data[key] === "object") {
|
||||||
console.log(newData[key], row.data[key], key, newData);
|
|
||||||
row.data[key] = deepMerge(row.data[key], newData[key]);
|
row.data[key] = deepMerge(row.data[key], newData[key]);
|
||||||
} else {
|
} else {
|
||||||
row.data[key] = newData[key];
|
row.data[key] = newData[key];
|
||||||
@ -132,24 +131,30 @@ export function insertCell(data, newRow, expense_item_id) {
|
|||||||
return updatedRows;
|
return updatedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let adding = false;
|
||||||
function findAndUpdate(rows) {
|
function findAndUpdate(rows) {
|
||||||
for (let i = 0; i < rows.length; i++) {
|
for (let i = 0; i < rows.length; i++) {
|
||||||
const row = rows[i];
|
const row = rows[i];
|
||||||
|
|
||||||
if (row.data.header.expense_item_id === expense_item_id) {
|
if (
|
||||||
|
(row.sort_order >= newRowObject.sort_order) &
|
||||||
|
(row.data.line_id != newRowObject.data.line_id)
|
||||||
|
) {
|
||||||
|
row.sort_order = row.sort_order + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!adding & (row.data.header.expense_item_id === expense_item_id)) {
|
||||||
if (!("subRows" in row)) {
|
if (!("subRows" in row)) {
|
||||||
row.subRows = [];
|
row.subRows = [];
|
||||||
}
|
}
|
||||||
row.subRows.push(newRowObject);
|
row.subRows.push(newRowObject);
|
||||||
return true;
|
adding = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (row.subRows && Array.isArray(row.subRows) && row.subRows.length > 0) {
|
if (row.subRows && Array.isArray(row.subRows) && row.subRows.length > 0) {
|
||||||
const found = findAndUpdate(row.subRows);
|
const found = findAndUpdate(row.subRows);
|
||||||
if (found) return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
findAndUpdate(updatedRows);
|
findAndUpdate(updatedRows);
|
||||||
return updatedRows;
|
return updatedRows;
|
||||||
@ -158,21 +163,25 @@ export function insertCell(data, newRow, expense_item_id) {
|
|||||||
export function deleteRow(data, lineId) {
|
export function deleteRow(data, lineId) {
|
||||||
const updatedRows = JSON.parse(JSON.stringify(data));
|
const updatedRows = JSON.parse(JSON.stringify(data));
|
||||||
|
|
||||||
|
let rowDeleteSortOrder = false;
|
||||||
function findAndDelete(rows) {
|
function findAndDelete(rows) {
|
||||||
for (let i = 0; i < rows.length; i++) {
|
for (let i = 0; i < rows.length; i++) {
|
||||||
const row = rows[i];
|
const row = rows[i];
|
||||||
|
|
||||||
if (row.data.line_id == lineId) {
|
if (row.data.line_id == lineId) {
|
||||||
|
rowDeleteSortOrder = row.sort_order;
|
||||||
rows.splice(i, 1);
|
rows.splice(i, 1);
|
||||||
return true;
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((rowDeleteSortOrder > 0) & (row.sort_order >= rowDeleteSortOrder)) {
|
||||||
|
row.sort_order = row.sort_order - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (row.subRows && Array.isArray(row.subRows) && row.subRows.length > 0) {
|
if (row.subRows && Array.isArray(row.subRows) && row.subRows.length > 0) {
|
||||||
const found = findAndDelete(row.subRows);
|
const found = findAndDelete(row.subRows);
|
||||||
if (found) return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
findAndDelete(updatedRows);
|
findAndDelete(updatedRows);
|
||||||
return updatedRows;
|
return updatedRows;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user