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:
Manish Kushare 2023-05-10 14:53:56 +05:30 committed by GitHub
parent c2434d216b
commit 2b5a748682
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -103,6 +103,8 @@ export function Table({
hideColumnSelectorButton, hideColumnSelectorButton,
} = loadPropertiesAndStyles(properties, styles, darkMode, component); } = loadPropertiesAndStyles(properties, styles, darkMode, component);
const updatedDataReference = useRef([]);
const getItemStyle = ({ isDragging, isDropAnimating }, draggableStyle) => ({ const getItemStyle = ({ isDragging, isDropAnimating }, draggableStyle) => ({
...draggableStyle, ...draggableStyle,
userSelect: 'none', userSelect: 'none',
@ -298,11 +300,13 @@ export function Table({
} }
function handleChangesSaved() { function handleChangesSaved() {
const clonedTableData = _.cloneDeep(tableData);
Object.keys(changeSet).forEach((key) => { Object.keys(changeSet).forEach((key) => {
tableData[key] = { clonedTableData[key] = {
..._.merge(tableData[key], changeSet[key]), ..._.merge(clonedTableData[key], changeSet[key]),
}; };
}); });
updatedDataReference.current = _.cloneDeep(clonedTableData);
setExposedVariables({ setExposedVariables({
changeSet: {}, changeSet: {},
@ -427,6 +431,7 @@ export function Table({
const data = useMemo(() => { const data = useMemo(() => {
if (!_.isEqual(properties.data, prevDataFromProps.current)) { if (!_.isEqual(properties.data, prevDataFromProps.current)) {
if (!_.isEmpty(updatedDataReference.current)) updatedDataReference.current = [];
if ( if (
!_.isEmpty(exposedVariables.newRows) || !_.isEmpty(exposedVariables.newRows) ||
!_.isEmpty(tableDetails.addNewRowsDetails.newRowsDataUpdates) || !_.isEmpty(tableDetails.addNewRowsDetails.newRowsDataUpdates) ||
@ -437,7 +442,7 @@ export function Table({
}); });
} }
} }
return tableData; return _.isEmpty(updatedDataReference.current) ? tableData : updatedDataReference.current;
}, [ }, [
tableData.length, tableData.length,
tableDetails.changeSet, tableDetails.changeSet,
@ -703,7 +708,10 @@ export function Table({
}; };
useEffect(() => { useEffect(() => {
if (_.isEmpty(changeSet)) { if (_.isEmpty(changeSet)) {
setExposedVariable('updatedData', tableData); setExposedVariable(
'updatedData',
_.isEmpty(updatedDataReference.current) ? tableData : updatedDataReference.current
);
} }
}, [JSON.stringify(changeSet)]); }, [JSON.stringify(changeSet)]);