Skip to content

Commit

Permalink
Merge branch 'master' into fix/records-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 18, 2023
2 parents 8be94d8 + 43d814e commit 14c3ef6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
4 changes: 3 additions & 1 deletion core/survey/nodeDefLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions core/survey/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const {
getNodeDefChildren,
getNodeDefChildrenInOwnPage,
hasNodeDefChildrenEntities,
getNodeDefChildrenSorted,
getNodeDefChildByName,
getNodeDefSiblingByName,
getNodeDefByName,
Expand Down
45 changes: 22 additions & 23 deletions server/modules/nodeDef/repository/nodeDefRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 (
<div
Expand Down

0 comments on commit 14c3ef6

Please sign in to comment.