diff --git a/app/client/src/widgets/TableWidget/widget/derived.js b/app/client/src/widgets/TableWidget/widget/derived.js index a756cfa78b..4e9166b3e8 100644 --- a/app/client/src/widgets/TableWidget/widget/derived.js +++ b/app/client/src/widgets/TableWidget/widget/derived.js @@ -25,15 +25,16 @@ export default { } const filteredTableData = props.filteredTableData || props.sanitizedTableData || []; + const internalKeysToOmit = ["__originalIndex__", "__primaryKey__"]; if (selectedRowIndex === -1) { const emptyRow = { ...filteredTableData[0] }; Object.keys(emptyRow).forEach((key) => { emptyRow[key] = ""; }); - return emptyRow; + return _.omit(emptyRow, internalKeysToOmit); } const selectedRow = { ...filteredTableData[selectedRowIndex] }; - return selectedRow; + return _.omit(selectedRow, internalKeysToOmit); }, // getTriggeredRow: (props, moment, _) => { @@ -43,15 +44,16 @@ export default { ? -1 : parseInt(props.triggeredRowIndex); const tableData = props.sanitizedTableData || []; + const internalKeysToOmit = ["__originalIndex__", "__primaryKey__"]; if (triggeredRowIndex === -1) { const emptyRow = { ...tableData[0] }; Object.keys(emptyRow).forEach((key) => { emptyRow[key] = ""; }); - return emptyRow; + return _.omit(emptyRow, internalKeysToOmit); } const triggeredRow = { ...tableData[triggeredRowIndex] }; - return triggeredRow; + return _.omit(triggeredRow, internalKeysToOmit); }, // getSelectedRows: (props, moment, _) => { @@ -61,8 +63,9 @@ export default { const filteredTableData = props.filteredTableData || props.sanitizedTableData || []; - const selectedRows = selectedRowIndices.map( - (ind) => filteredTableData[ind], + const internalKeysToOmit = ["__originalIndex__", "__primaryKey__"]; + const selectedRows = selectedRowIndices.map((ind) => + _.omit(filteredTableData[ind], internalKeysToOmit), ); return selectedRows; }, diff --git a/app/client/src/widgets/TableWidget/widget/derived.test.js b/app/client/src/widgets/TableWidget/widget/derived.test.js index 0f49303b64..459f3842e4 100644 --- a/app/client/src/widgets/TableWidget/widget/derived.test.js +++ b/app/client/src/widgets/TableWidget/widget/derived.test.js @@ -1251,7 +1251,7 @@ describe("Validates Derived Properties", () => { }); describe("Validate getSelectedRow function", () => { - it("Multple row selection, with selected rows", () => { + it("Multiple row selection, with selected rows", () => { const { getSelectedRow } = derivedProperty; const input = { multiRowSelection: true, @@ -1267,12 +1267,11 @@ describe("Validate getSelectedRow function", () => { id: 234, name: "Jane Doe", extra: "Extra2", - __originalIndex__: 2, }); }); - it("Multple row selection, with no selected rows", () => { - const { getSelectedRow } = derivedProperty; + it("Multiple row selection, with no selected rows", () => { + const { getSelectedRows } = derivedProperty; const input = { multiRowSelection: true, selectedRowIndices: [], @@ -1283,12 +1282,7 @@ describe("Validate getSelectedRow function", () => { { id: 123, name: "John Doe", extra: "Extra1", __originalIndex__: 1 }, ], }; - expect(getSelectedRow(input, moment, _)).toStrictEqual({ - id: "", - name: "", - extra: "", - __originalIndex__: "", - }); + expect(getSelectedRows(input, moment, _)).toStrictEqual([]); }); it("Single row selection, with selected row", () => { @@ -1307,14 +1301,13 @@ describe("Validate getSelectedRow function", () => { id: 234, name: "Jane Doe", extra: "Extra2", - __originalIndex__: 2, }); }); it("Single row selection, without selected row", () => { const { getSelectedRow } = derivedProperty; const input = { - multiRowSelection: true, + multiRowSelection: false, selectedRowIndices: [], selectedRowIndex: -1, sanitizedTableData: [ @@ -1328,7 +1321,6 @@ describe("Validate getSelectedRow function", () => { id: "", name: "", extra: "", - __originalIndex__: "", }); }); @@ -1349,7 +1341,6 @@ describe("Validate getSelectedRow function", () => { id: "", name: "", extra: "", - __originalIndex__: "", }); }); it("Single row selection, with indices undefined", () => { @@ -1369,7 +1360,6 @@ describe("Validate getSelectedRow function", () => { id: "", name: "", extra: "", - __originalIndex__: "", }); }); it("Single row selection, with invalid indices", () => { @@ -1389,7 +1379,6 @@ describe("Validate getSelectedRow function", () => { id: "", name: "", extra: "", - __originalIndex__: "", }); }); it("Single row selection, with invalid indices", () => { @@ -1409,7 +1398,6 @@ describe("Validate getSelectedRow function", () => { id: "", name: "", extra: "", - __originalIndex__: "", }); }); it("Single row selection, with invalid indices", () => { @@ -1429,7 +1417,6 @@ describe("Validate getSelectedRow function", () => { id: "", name: "", extra: "", - __originalIndex__: "", }); }); it("Single row selection, with invalid indices", () => { @@ -1449,7 +1436,6 @@ describe("Validate getSelectedRow function", () => { id: "", name: "", extra: "", - __originalIndex__: "", }); }); it("Single row selection, with invalid indices", () => { @@ -1469,7 +1455,25 @@ describe("Validate getSelectedRow function", () => { id: "", name: "", extra: "", - __originalIndex__: "", + }); + }); +}); + +describe("Validate getSelectedRow function", () => { + it("Trigger row selection", () => { + const { getTriggeredRow } = derivedProperty; + const input = { + triggeredRowIndex: 0, + sanitizedTableData: [ + { id: 1234, name: "Jim Doe", extra: "", __originalIndex__: 0 }, + { id: 234, name: "Jane Doe", extra: "Extra2", __originalIndex__: 2 }, + { id: 123, name: "John Doe", extra: "Extra1", __originalIndex__: 1 }, + ], + }; + expect(getTriggeredRow(input, moment, _)).toStrictEqual({ + id: 1234, + name: "Jim Doe", + extra: "", }); }); });