import { FbFormModelField , FieldIdType , FieldLayoutPositionType } from "../../../../../types" ; import getFieldPosition from "./getFieldPosition" ; param data const cleanupEmptyRows = data => { data . layout = data . layout . filter ( row => row . length > 0 ) ; } ; const moveField = ( { field , position , data } ) => { const { row , index } = position ; const fieldId = typeof field === "string" ? field : field . _id ; const existingPosition = getFieldPosition ( { field : fieldId , data } ) ; if ( existingPosition ) { data . layout [ existingPosition . row ] . splice ( existingPosition . index , 1 ) ; } if ( ! data . layout [ row ] ) { data . layout [ row ] = [ fieldId ] ; return ; } if ( index === null ) { data . layout . splice ( row , 0 , [ fieldId ] ) ; return ; } data . layout [ row ] . splice ( index , 0 , fieldId ) ; } ; export default ( params ) => { moveField ( params ) ; cleanupEmptyRows ( params . data ) ; } ;