Skip to content

Commit

Permalink
fixed survey hierarchy items not shown in order (#3572)
Browse files Browse the repository at this point in the history
* fixed survey hierarchy items not shown in order

* fixing tests

---------

Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 20, 2024
1 parent 321acc5 commit bdc8663
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
15 changes: 8 additions & 7 deletions core/survey/_survey/surveyNodeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,17 @@ export const getNodeDefPath =
}

export const getHierarchy =
(filterFn = NodeDef.isEntity) =>
(filterFn = NodeDef.isEntity, cycle = undefined) =>
(survey) => {
let length = 1
const h = (array, nodeDef) => {
const childDefs = [
...(NodeDef.isEntity(nodeDef) && !NodeDef.isVirtual(nodeDef)
? R.pipe(getNodeDefChildren(nodeDef), R.filter(filterFn))(survey)
: []),
]

const childDefs = []
if (NodeDef.isEntity(nodeDef) && !NodeDef.isVirtual(nodeDef)) {
const childDefsNotFiltered = cycle
? getNodeDefChildrenSorted({ nodeDef, cycle })(survey)
: getNodeDefChildren(nodeDef)(survey)
childDefs.push(...childDefsNotFiltered.filter(filterFn))
}
length += childDefs.length
const item = { ...nodeDef, children: childDefs.reduce(h, []) }
array.push(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, { useEffect, useState, useRef } from 'react'
import * as Survey from '@core/survey/survey'
import * as NodeDef from '@core/survey/nodeDef'

import { useSurvey, useSurveyPreferredLang } from '@webapp/store/survey'
import { useSurvey, useSurveyCycleKey, useSurveyPreferredLang } from '@webapp/store/survey'
import { useI18n } from '@webapp/store/system'

import { NodeDefsSelector } from '@webapp/components/survey/NodeDefsSelector'
Expand All @@ -17,10 +17,11 @@ import Tree from './Tree'
const SurveyHierarchy = () => {
const survey = useSurvey()
const lang = useSurveyPreferredLang()
const cycle = useSurveyCycleKey()
const i18n = useI18n()
const { nodeDefLabelType, toggleLabelFunction } = useNodeDefLabelSwitch()

const hierarchy = Survey.getHierarchy(NodeDef.isEntity)(survey)
const hierarchy = Survey.getHierarchy(NodeDef.isEntity, cycle)(survey)

const [selectedNodeDefUuid, setSelectedNodeDefUuid] = useState(null)
const [tree, setTree] = useState(null)
Expand Down

0 comments on commit bdc8663

Please sign in to comment.