Skip to content

Commit 6b7a444

Browse files
Shelob9sc0ttkclark
authored andcommitted
#6898 make new validation state work with reducer/init state
1 parent 10a8b8c commit 6b7a444

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

ui/js/dfv/src/pods-dfv.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,11 @@ window.PodsDFV = {
796796
} else if (window.podsDFVConfig) {
797797
return initPodStore(
798798
window.podsDFVConfig,
799-
initialStoresWithValues[storeKey],
799+
{
800+
...initialStoresWithValues[ storeKey ],
801+
validationMessages: [],
802+
needsValidation: false,
803+
},
800804
storeKey,
801805
);
802806
}

ui/js/dfv/src/store/actions.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,16 @@ export const deleteField = ( fieldID, name ) => {
335335
};
336336

337337
//Set the validation messages
338-
export const setValidationMessages = (messages) => {
338+
export const setValidationMessages = ( validationMessages ) => {
339339
return {
340340
type: CURRENT_POD_ACTIONS.SET_VALIDATION_MESSAGES,
341-
messages,
341+
validationMessages,
342342
};
343-
}
343+
};
344344

345-
//Triggers validation of the pod
346-
export const setNeedsValidating = () => {
345+
//Toggle if needs validation of the pod
346+
export const toggleNeedsValidating = () => {
347347
return {
348-
type: CURRENT_POD_ACTIONS.SET_NEEDS_VALIDATING,
349-
needsValidating: true,
348+
type: CURRENT_POD_ACTIONS.TOGGLE_NEEDS_VALIDATING,
350349
};
351-
}
350+
};

ui/js/dfv/src/store/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const CURRENT_POD_ACTIONS = {
5555
//Validation
5656
//@see https://github.com/pods-framework/pods/pull/7064
5757
SET_VALIDATION_MESSAGES: 'CURRENT_POD/SET_VALIDATION_MESSAGES',
58-
SET_NEEDS_VALIDATION: 'CURRENT_POD/SET_NEEDS_VALIDATION',
58+
TOGGLE_NEEDS_VALIDATING: 'CURRENT_POD/TOGGLE_NEEDS_VALIDATING',
5959
};
6060

6161
export const INITIAL_UI_STATE = {

ui/js/dfv/src/store/reducer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,18 @@ export const currentPod = ( state = {}, action = {} ) => {
351351
groups,
352352
};
353353
}
354+
case CURRENT_POD_ACTIONS.SET_VALIDATION_MESSAGES: {
355+
return {
356+
...state,
357+
validationMessages: action.validationMessages,
358+
};
359+
}
360+
case CURRENT_POD_ACTIONS.TOGGLE_NEEDS_VALIDATING: {
361+
return {
362+
...state,
363+
needsValidating: ! state.needsValidating,
364+
};
365+
}
354366

355367
default: {
356368
return state;

ui/js/dfv/src/store/store.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,18 @@ import apiMiddleware from './api-middleware';
2727
* @param {int} formCounter Form index. (Optional.)
2828
* @param {string} prefix Prefix. (Optional.)
2929
*/
30-
export const createStoreKey = ( pod, itemId, formCounter = 0, prefix = '' ) => {
31-
return prefix.length ?
32-
`${ prefix }-${ pod }-${ itemId }-${ formCounter }`
30+
export const createStoreKey = ( pod, itemId, formCounter = 0, prefix = '' ) => {
31+
return prefix.length
32+
? `${ prefix }-${ pod }-${ itemId }-${ formCounter }`
3333
: `${ pod }-${ itemId }-${ formCounter }`;
3434
};
3535

36-
const initStore = (initialState, storeKey) => {
37-
const reduxStore = configureStore({
36+
const initStore = ( initialState, storeKey ) => {
37+
const reduxStore = configureStore( {
3838
reducer,
39-
middleware: [apiMiddleware],
40-
preloadedState: {
41-
validationMessages: [],
42-
needsValidating: false,
43-
...initialState
44-
},
45-
});
39+
middleware: [ apiMiddleware ],
40+
preloadedState: initialState,
41+
} );
4642

4743
const mappedSelectors = Object.keys( selectors ).reduce( ( acc, selectorKey ) => {
4844
acc[ selectorKey ] = ( ...args ) =>

0 commit comments

Comments
 (0)