Skip to content

Commit bf60a98

Browse files
committed
Fixed action MODIFY_DATA with payload clear: true
1 parent 720a039 commit bf60a98

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

demo/src/schema/basic.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { MODIFY_DATA } from '../../../src/actions';
23

34
export default {
45
name: 'posts',
@@ -149,7 +150,7 @@ export default {
149150
name: 'delete',
150151
label: 'Delete',
151152
indexField: '@id',
152-
thunk: ( payload ) => ( dispatch, getState ) => {
153+
thunk: ( config ) => ( dispatch, getState ) => {
153154
// Get current table state.
154155
const tableState = getState()[payload.reducerName][payload.name];
155156
confirm('Are your sure you want to delete the selected items?')
@@ -172,7 +173,7 @@ export default {
172173
label: 'Simple Button',
173174
visible: true,
174175
state: false,
175-
thunk: ( payload ) => ( dispatch, getState ) => {
176+
thunk: ( config ) => ( dispatch, getState ) => {
176177
console.log('toolbar button click', payload);
177178
}
178179
}, {
@@ -199,9 +200,10 @@ export default {
199200
hide: 'Hide editable',
200201
save: 'Save',
201202
},
202-
save: ( payload ) => ( dispatch, getState ) => {
203-
const tableState = getState()[payload.reducerName][payload.name];
204-
console.log('toolbar save click with modified data', payload, tableState.modified);
203+
save: ( config ) => ( dispatch, getState ) => {
204+
const tableState = getState()[config.reducerName][config.name];
205+
console.log('toolbar save click with modified data', config, tableState.modified);
206+
config.payload.action(MODIFY_DATA)({ clear: true });
205207
// Dispatch MODIFY_DATA action with clear: true, to reset the modified data
206208
// Dispatch REQUEST_DATA action "payload.action(REQUEST_DATA)" to refresh data.
207209
}
@@ -278,7 +280,7 @@ export default {
278280
params: {
279281
id: '@id',
280282
},
281-
thunk: ( payload ) => ( dispatch, getState ) => {
283+
thunk: ( config ) => ( dispatch, getState ) => {
282284
console.log('edit', payload, getState());
283285
}
284286
}, {
@@ -289,7 +291,7 @@ export default {
289291
params: {
290292
id: '@id'
291293
},
292-
thunk: ( payload ) => ( dispatch, getState ) => {
294+
thunk: ( config ) => ( dispatch, getState ) => {
293295
confirm('Are your sure you want to delete this page?')
294296
? console.log('delete', getState())
295297
: console.log(false);

src/reducer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export default function reducer(state = {}, action) {
134134
},
135135
[actions.MODIFY_DATA]: () => {
136136
var modifiedData = {};
137-
if (!payload.clear) {
137+
if (payload.clear !== true) {
138138
modifiedData = {
139139
...tableState.modified,
140140
[payload.key]: {
@@ -149,7 +149,6 @@ export default function reducer(state = {}, action) {
149149
[name]: {
150150
...tableState,
151151
modified: {
152-
...tableState.modified,
153152
...modifiedData
154153
}
155154
}

0 commit comments

Comments
 (0)