1- import { isEqual } from 'lodash' ;
21// For now just moving postprocess logic here,
32// if needed we might move more from AposEditorMixin.js
43
54// Perform any postprocessing required by direct or nested schema fields
65// before the object can be saved
7- export async function _postprocess ( schema , data , widgetOptions , oldData ) {
6+ export async function _postprocess ( schema , data , widgetOptions /* , oldData */ ) {
87 // Relationship fields may have postprocessors (e.g. autocropping)
9- const [ relationships , oldRelationships ] = findRelationships ( schema , data , oldData ) ;
8+ const relationships = findRelationships ( schema , data ) ;
109
11- for ( const [ i , relationship ] of relationships . entries ( ) ) {
12- const oldRelationship = oldRelationships [ i ] ;
10+ for ( const relationship of relationships ) {
1311 if ( ! ( relationship . value && relationship . field . postprocessor ) ) {
1412 continue ;
1513 }
16- if ( checkSameRelationships ( relationship . value , oldRelationship ) ) {
17- continue ;
18- }
1914 const withType = relationship . field . withType ;
2015 const mod = apos . modules [ withType ] ;
2116 const response = await apos . http . post ( `${ mod . action } /${ relationship . field . postprocessor } ` , {
@@ -31,6 +26,7 @@ export async function _postprocess(schema, data, widgetOptions, oldData) {
3126 } ,
3227 busy : true
3328 } ) ;
29+ console . log ( 'response.relationship' , response . relationship ) ;
3430 relationship . context [ relationship . field . name ] = response . relationship ;
3531 }
3632}
@@ -45,9 +41,6 @@ function findRelationships(schema, object, oldObject) {
4541 field,
4642 value : object [ field . name ]
4743 } ) ;
48- if ( oldObject ) {
49- oldRelationships . push ( oldObject [ field . name ] ) ;
50- }
5144 } else if ( field . type === 'array' ) {
5245 for ( const value of ( object [ field . name ] || [ ] ) ) {
5346 relationships = [
@@ -64,18 +57,3 @@ function findRelationships(schema, object, oldObject) {
6457 }
6558 return [ relationships , oldRelationships ] ;
6659}
67-
68- function checkSameRelationships ( relationship , oldRelationship ) {
69- for ( const piece of relationship ) {
70- const oldPiece = oldRelationship . find ( ( p ) => p . _id === piece . _id ) ;
71- console . log ( 'piece' , piece ) ;
72- console . log ( 'oldPiece' , oldPiece ) ;
73- if ( ! oldPiece ) {
74- return false ;
75- }
76- if ( ! isEqual ( piece . _fields , oldPiece . _fields ) ) {
77- return false ;
78- }
79- }
80- return true ;
81- }
0 commit comments