-
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.
Preserve the order and group options by section
Background: Confirmation dialog and error notification need to display the list of changed options. However a flat list is no longer suitable: 1. some options have the same translated name 2. option list has grown significantly 3. options are split into sub-screens (not all edited options are visible to the user) Changes: 1. display a list of changed sections 2. within each changed section display a list of changed options 3. preserve the same order of sections and options as in the UI
- 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