diff --git a/core/survey/nodeDefLayout.js b/core/survey/nodeDefLayout.js index c3fdaa6f58..7607fd8556 100644 --- a/core/survey/nodeDefLayout.js +++ b/core/survey/nodeDefLayout.js @@ -92,9 +92,11 @@ export const getLayoutChildrenCompressed = : // item in another row, can have the same x of the previous one Math.min(itemPrev.x, xOriginal) + const prevYDiff = itemPrev.yOriginal - itemPrev.y + const y = sameRowOfPreviousItem ? // item can have the same y of the previous one - Math.min(itemPrev.y, yOriginal) + yOriginal - prevYDiff : // item in another row, move it yPrev + hPrev Math.min(itemPrev.y + itemPrev.h, yOriginal) diff --git a/core/survey/survey.js b/core/survey/survey.js index 526e4c9283..495884225d 100644 --- a/core/survey/survey.js +++ b/core/survey/survey.js @@ -149,6 +149,7 @@ export const { getNodeDefChildren, getNodeDefChildrenInOwnPage, hasNodeDefChildrenEntities, + getNodeDefChildrenSorted, getNodeDefChildByName, getNodeDefSiblingByName, getNodeDefByName, diff --git a/server/modules/nodeDef/repository/nodeDefRepository.js b/server/modules/nodeDef/repository/nodeDefRepository.js index c571aea7a8..78791da969 100644 --- a/server/modules/nodeDef/repository/nodeDefRepository.js +++ b/server/modules/nodeDef/repository/nodeDefRepository.js @@ -71,13 +71,12 @@ export const insertNodeDef = async (surveyId, nodeDef, client = DB) => (row) => dbTransformCallback({ row, draft: true, advanced: true }) // Always loading draft when creating or updating a nodeDef ) -export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false }, client = DB) => - client.tx(async (tx) => { - const schema = getSurveyDBSchema(surveyId) - await tx.batch([ - nodeDefs.map((nodeDef) => - tx.none( - ` +export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false }, client = DB) => { + const schema = getSurveyDBSchema(surveyId) + return client.batch([ + nodeDefs.map((nodeDef) => + client.none( + ` INSERT INTO ${schema}.node_def ( parent_uuid, uuid, @@ -93,22 +92,22 @@ export const insertNodeDefsBatch = async ({ surveyId, nodeDefs, backup = false } $4::jsonb, $5::jsonb, $6::jsonb, $7::jsonb, $8,$9,$10)`, - [ - NodeDef.getParentUuid(nodeDef), - nodeDef.uuid, - NodeDef.getType(nodeDef), - backup ? NodeDef.getProps(nodeDef) : {}, - backup ? NodeDef.getPropsDraft(nodeDef) : NodeDef.getProps(nodeDef), - backup ? NodeDef.getPropsAdvanced(nodeDef) : {}, - backup ? NodeDef.getPropsAdvancedDraft(nodeDef) : NodeDef.getPropsAdvanced(nodeDef), - NodeDef.getMeta(nodeDef), - NodeDef.isAnalysis(nodeDef), - NodeDef.isVirtual(nodeDef), - ] - ) - ), - ]) - }) + [ + NodeDef.getParentUuid(nodeDef), + nodeDef.uuid, + NodeDef.getType(nodeDef), + backup ? NodeDef.getProps(nodeDef) : {}, + backup ? NodeDef.getPropsDraft(nodeDef) : NodeDef.getProps(nodeDef), + backup ? NodeDef.getPropsAdvanced(nodeDef) : {}, + backup ? NodeDef.getPropsAdvancedDraft(nodeDef) : NodeDef.getPropsAdvanced(nodeDef), + NodeDef.getMeta(nodeDef), + NodeDef.isAnalysis(nodeDef), + NodeDef.isVirtual(nodeDef), + ] + ) + ), + ]) +} // ============== READ diff --git a/webapp/components/survey/SurveyForm/nodeDefs/components/types/nodeDefEntitySwitch.js b/webapp/components/survey/SurveyForm/nodeDefs/components/types/nodeDefEntitySwitch.js index 914a1eefb5..517360796a 100644 --- a/webapp/components/survey/SurveyForm/nodeDefs/components/types/nodeDefEntitySwitch.js +++ b/webapp/components/survey/SurveyForm/nodeDefs/components/types/nodeDefEntitySwitch.js @@ -2,7 +2,6 @@ import './nodeDefEntitySwitch.scss' import React from 'react' -import * as A from '@core/arena' import * as Survey from '@core/survey/survey' import * as NodeDef from '@core/survey/nodeDef' import * as NodeDefLayout from '@core/survey/nodeDefLayout' @@ -20,20 +19,20 @@ const componentsByRenderType = { const NodeDefEntitySwitch = (props) => { const { surveyCycleKey, nodeDef } = props + const survey = useSurvey() + const renderType = NodeDefLayout.getRenderType(surveyCycleKey)(nodeDef) if (!renderType) { // node def not in current cycle return null } - const survey = useSurvey() - const includeAnalysis = false - const childDefs = Survey.getNodeDefChildren(props.nodeDef, includeAnalysis)(survey) + const childDefs = Survey.getNodeDefChildrenSorted({ nodeDef, includeAnalysis, cycle: surveyCycleKey })(survey) const nodeDefName = NodeDef.getName(nodeDef) const childUuids = NodeDefLayout.getLayoutChildrenUuids(surveyCycleKey)(nodeDef) - const childNames = childUuids.map((childUuid) => A.pipe(Survey.getNodeDefByUuid(childUuid), NodeDef.getName)(survey)) + const childNames = Survey.getNodeDefsByUuids(childUuids)(survey).map(NodeDef.getName) return (