Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed survey hierarchy items not shown in order #3572

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading