mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 06:48:21 +00:00
Upon saving the edited changes in the table, it is not mutating query object (#5784)
* bug fixed: Table edit and save changing the referenced data * bug fixed : upon changing the data to the Table, component still persists previous data if it has been updated before * when table is edited, and its reference data is changed, it does not show new data rather persists updated data * removing unused code * code refactor * bug fixed: upon click on save changes,updatedData exposed var is getting reset
This commit is contained in:
parent
c2434d216b
commit
2b5a748682
1 changed files with 12 additions and 4 deletions
|
|
@ -103,6 +103,8 @@ export function Table({
|
|||
hideColumnSelectorButton,
|
||||
} = loadPropertiesAndStyles(properties, styles, darkMode, component);
|
||||
|
||||
const updatedDataReference = useRef([]);
|
||||
|
||||
const getItemStyle = ({ isDragging, isDropAnimating }, draggableStyle) => ({
|
||||
...draggableStyle,
|
||||
userSelect: 'none',
|
||||
|
|
@ -298,11 +300,13 @@ export function Table({
|
|||
}
|
||||
|
||||
function handleChangesSaved() {
|
||||
const clonedTableData = _.cloneDeep(tableData);
|
||||
Object.keys(changeSet).forEach((key) => {
|
||||
tableData[key] = {
|
||||
..._.merge(tableData[key], changeSet[key]),
|
||||
clonedTableData[key] = {
|
||||
..._.merge(clonedTableData[key], changeSet[key]),
|
||||
};
|
||||
});
|
||||
updatedDataReference.current = _.cloneDeep(clonedTableData);
|
||||
|
||||
setExposedVariables({
|
||||
changeSet: {},
|
||||
|
|
@ -427,6 +431,7 @@ export function Table({
|
|||
|
||||
const data = useMemo(() => {
|
||||
if (!_.isEqual(properties.data, prevDataFromProps.current)) {
|
||||
if (!_.isEmpty(updatedDataReference.current)) updatedDataReference.current = [];
|
||||
if (
|
||||
!_.isEmpty(exposedVariables.newRows) ||
|
||||
!_.isEmpty(tableDetails.addNewRowsDetails.newRowsDataUpdates) ||
|
||||
|
|
@ -437,7 +442,7 @@ export function Table({
|
|||
});
|
||||
}
|
||||
}
|
||||
return tableData;
|
||||
return _.isEmpty(updatedDataReference.current) ? tableData : updatedDataReference.current;
|
||||
}, [
|
||||
tableData.length,
|
||||
tableDetails.changeSet,
|
||||
|
|
@ -703,7 +708,10 @@ export function Table({
|
|||
};
|
||||
useEffect(() => {
|
||||
if (_.isEmpty(changeSet)) {
|
||||
setExposedVariable('updatedData', tableData);
|
||||
setExposedVariable(
|
||||
'updatedData',
|
||||
_.isEmpty(updatedDataReference.current) ? tableData : updatedDataReference.current
|
||||
);
|
||||
}
|
||||
}, [JSON.stringify(changeSet)]);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue