Skip to content

Commit

Permalink
initialize validation state for pods editor #6898
Browse files Browse the repository at this point in the history
  • Loading branch information
Shelob9 committed Apr 25, 2023
1 parent b44d327 commit f651e06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
21 changes: 14 additions & 7 deletions ui/js/dfv/src/pods-dfv.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,25 +811,32 @@ window.PodsDFV = {
// Create stores for each of the individual keys we found (the keys of
// the initialStoresWithValues object).
const initialStoreKeys = Object.keys( initialStoresWithValues );

const storeKeys = initialStoreKeys.map( ( storeKey ) => {
//Validation state
const validation = {
validationMessages: Object.keys( initialStoresWithValues[ storeKey ] ).reduce( ( acc, key ) => {
acc[ key ] = [];
return acc;
}, {} ),
needsValidation: false,
};
// The Edit Pod screen gets a different store set up than
// other contexts.
if ( isEditPodScreen() ) {
return initEditPodStore(
window.podsAdminConfig,
{
...window.podsAdminConfig,
...validation,
},
storeKey
);
} else if ( window.podsDFVConfig ) {
const validationMessages = Object.keys( initialStoresWithValues[ storeKey ] ).reduce( ( acc, key ) => {
acc[ key ] = [];
return acc;
}, {} );
return initPodStore(
window.podsDFVConfig,
{
...initialStoresWithValues[ storeKey ],
validationMessages,
needsValidation: false,
...validation,
},
storeKey,
);
Expand Down
3 changes: 2 additions & 1 deletion ui/js/dfv/src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const initEditPodStore = ( config, storeKey = '' ) => {
},
...omit( config, [ 'fieldTypes', 'relatedObjects' ] ),
};

console.log({initEditPodStore:initialState});
return initStore( initialState, storeKey );
};

Expand All @@ -97,6 +97,7 @@ export const initPodStore = ( config = {}, initialValues = {}, storeKey = '' ) =
...omit( config, [ 'fieldTypes', 'relatedObjects' ] ),
currentPod: initialValues,
};
console.log({initPodStore:initialState});

return initStore( initialState, storeKey );
};

0 comments on commit f651e06

Please sign in to comment.