diff --git a/core/survey/_survey/surveyNodeDefs.js b/core/survey/_survey/surveyNodeDefs.js index 5bbe23fc64..12ec6dcf90 100644 --- a/core/survey/_survey/surveyNodeDefs.js +++ b/core/survey/_survey/surveyNodeDefs.js @@ -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) diff --git a/webapp/views/App/views/Designer/SurveyHierarchy/SurveyHierarchy.js b/webapp/views/App/views/Designer/SurveyHierarchy/SurveyHierarchy.js index 7cf65eee8d..8b74141c98 100644 --- a/webapp/views/App/views/Designer/SurveyHierarchy/SurveyHierarchy.js +++ b/webapp/views/App/views/Designer/SurveyHierarchy/SurveyHierarchy.js @@ -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' @@ -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)