import { jsonParser } from '.' ; import StepUtils from './StepUtils' ; param result param basicImgInfo export const composeResultWithBasicImgInfo = ( result , basicImgInfo ) => { const newResult = JSON . stringify ( { ... jsonParser ( result ) , ... basicImgInfo } ) ; return newResult ; } ; export const composeResult = ( result , pos , newData ) => { const { step , stepList } = pos ; const { rect , basicRectID } = newData ; try { const data = jsonParser ( result ) ; const currentStepInfo = StepUtils . getCurrentStepInfo ( step , stepList ) ; const { dataSourceStep } = currentStepInfo ; const stepName = `step_${ currentStepInfo . step }` ; if ( data [ stepName ] ) { const info = data [ stepName ] ; if ( info . result ) { if ( JSON . stringify ( info . result ) === JSON . stringify ( rect ) ) { return JSON . stringify ( data ) ; } if ( basicRectID ) { info . result = [ ... info . result . filter ( ( v ) => ! ( v . sourceID && v . sourceID === basicRectID ) ) , ... rect . filter ( ( v ) => v . sourceID && v . sourceID === basicRectID ) , ] ; } else { info . result = rect ; } return JSON . stringify ( data ) ; } return JSON . stringify ( { ... data , [ stepName ] : { ... data [ stepName ] , result : rect , } , } ) ; } return JSON . stringify ( { ... data , [ stepName ] : { dataSourceStep , toolName : stepList [ step - 1 ] . tool , result : rect , } , } ) ; } catch ( e ) { return result ; } } ;