Skip to content

Commit

Permalink
Merge pull request #1977 from apuliasoft/inputpanel
Browse files Browse the repository at this point in the history
  • Loading branch information
lucafoscili authored Jul 3, 2024
2 parents e3f7101 + 6ca1ad3 commit 40a56ae
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions packages/ketchup/src/components/kup-input-panel/kup-input-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
KupComboboxIconClickEventPayload,
KupDataCell,
KupDataTableDataset,
KupDataTableRow,
} from '../../components';
import { FButton } from '../../f-components/f-button/f-button';
import { FCell } from '../../f-components/f-cell/f-cell';
Expand Down Expand Up @@ -836,7 +837,7 @@ export class KupInputPanel {
): KupDataTableDataset {
const updated: KupDataTableDataset = {
...tableValue,
rows: [],
rows: tableValue.rows.map((row) => ({ ...row, cells: {} })),
};

const editableColsId = tableValue.columns
Expand All @@ -853,23 +854,34 @@ export class KupInputPanel {
);

updated.rows = tableValue.rows.map((row, i) =>
editableColsId.reduce((cells, colId) => {
const changed =
row.cells[colId].value !==
beforeTableValue.rows[i].cells[colId].value;
editableColsId.reduce<KupDataTableRow>(
(updatedRow, colId) => {
const changed =
row.cells[colId].value !==
beforeTableValue.rows[i].cells[colId].value;

if (changed) {
return {
...beforeTableValue.rows[i],
cells: {
...updatedRow.cells,
[colId]: {
...beforeTableValue.rows[i].cells[
colId
],
value: row.cells[colId].value,
},
},
};
}

if (changed) {
return {
...cells,
[colId]: {
...beforeTableValue.rows[i].cells[colId],
value: row.cells[colId].value,
},
...beforeTableValue.rows[i],
cells: updatedRow.cells,
};
}

return cells;
}, {})
},
{ ...beforeTableValue.rows[i], cells: {} }
)
);

return updated;
Expand Down

0 comments on commit 40a56ae

Please sign in to comment.