-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1456 from rszwajko/groupBySection
Preserve the order and group options by section
- Loading branch information
Showing
5 changed files
with
119 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import style from './style.css' | ||
|
||
const ChangesList = ({ changes = [], translatedLabels = [] }) => { | ||
// start with translated labels to preserve the order of sections/fields | ||
const filteredSectionTree = translatedLabels | ||
.filter(({ fieldName }) => changes.find(changeName => changeName === fieldName)) | ||
// group fields by section (keep the order of sections) | ||
// output { "some section": ["field A", "field B", ...], ...} | ||
.reduce((acc, { fieldTitle, sectionTitle }) => { | ||
if (acc[sectionTitle]) { | ||
acc[sectionTitle].push(fieldTitle) | ||
} else { | ||
acc[sectionTitle] = [fieldTitle] | ||
} | ||
return acc | ||
}, {}) | ||
|
||
return ( | ||
<ul className={style['section-list']}> | ||
{ | ||
Object.entries(filteredSectionTree) | ||
.map(([sectionTitle, fields]) => ( | ||
<li key={sectionTitle}> | ||
{sectionTitle} | ||
<ul className={style['field-list']}> | ||
{ fields.map(fieldTitle => <li key={fieldTitle}>{fieldTitle}</li>)} | ||
</ul> | ||
</li> | ||
)) | ||
} | ||
</ul> | ||
) | ||
} | ||
|
||
ChangesList.propTypes = { | ||
changes: PropTypes.array, | ||
translatedLabels: PropTypes.array.isRequired, | ||
} | ||
|
||
export default ChangesList |
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
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