-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
100 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
webapp/components/survey/NodeDefsSelector/AttributesSelector/AttributesList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import './AttributesList.scss' | ||
|
||
import React, { useMemo } from 'react' | ||
import * as PropTypes from 'prop-types' | ||
|
||
import * as ObjectUtils from '@core/objectUtils' | ||
import * as Survey from '@core/survey/survey' | ||
import * as NodeDef from '@core/survey/nodeDef' | ||
|
||
import { useSurvey, useSurveyPreferredLang } from '@webapp/store/survey' | ||
|
||
import AttributeSelector from './AttributeSelector' | ||
|
||
export const AttributesList = (props) => { | ||
const { | ||
canSelectAttributes, | ||
nodeDefContext, | ||
nodeDefLabelType, | ||
nodeDefUuidsAttributes, | ||
onToggleAttribute, | ||
showAncestorsLabel, | ||
attributeDefs, | ||
} = props | ||
|
||
const survey = useSurvey() | ||
const lang = useSurveyPreferredLang() | ||
const childDefsByParentUuid = useMemo( | ||
() => ObjectUtils.groupByProp(NodeDef.keys.parentUuid)(attributeDefs), | ||
[attributeDefs] | ||
) | ||
|
||
return Object.entries(childDefsByParentUuid).map(([parentDefUuid, childDefs]) => { | ||
const childDefParentDef = Survey.getNodeDefByUuid(parentDefUuid)(survey) | ||
|
||
return childDefs.map((childDef, index) => { | ||
const parentHeadingVisible = index === 0 && childDefParentDef !== nodeDefContext | ||
return ( | ||
<div key={NodeDef.getUuid(childDef)} className="attribute-selector-wrapper"> | ||
{parentHeadingVisible && ( | ||
<span className="attribute-selector-parent-entity-heading"> | ||
{NodeDef.getLabelWithType({ nodeDef: childDefParentDef, lang, type: nodeDefLabelType })} | ||
</span> | ||
)} | ||
<AttributeSelector | ||
canSelectAttributes={canSelectAttributes} | ||
nodeDef={childDef} | ||
nodeDefUuidsAttributes={nodeDefUuidsAttributes} | ||
onToggleAttribute={onToggleAttribute} | ||
showNodeDefPath={!showAncestorsLabel} | ||
nodeDefLabelType={nodeDefLabelType} | ||
/> | ||
</div> | ||
) | ||
}) | ||
}) | ||
} | ||
|
||
AttributesList.propTypes = { | ||
attributeDefs: PropTypes.array.isRequired, | ||
canSelectAttributes: PropTypes.bool, | ||
nodeDefContext: PropTypes.object.isRequired, | ||
nodeDefLabelType: PropTypes.string, | ||
nodeDefUuidsAttributes: PropTypes.array, | ||
onToggleAttribute: PropTypes.func, | ||
showAncestorsLabel: PropTypes.bool, | ||
} |
10 changes: 10 additions & 0 deletions
10
webapp/components/survey/NodeDefsSelector/AttributesSelector/AttributesList.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.attribute-selector-wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
margin: 0 0.2rem; | ||
|
||
.attribute-selector-parent-entity-heading { | ||
font-style: italic; | ||
font-size: small; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ | |
display: grid; | ||
align-content: start; | ||
grid-row-gap: 0.3rem; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters