Feature/download template redesign#342
Conversation
- add sections in download template page - collapsible orgunit section instead of a checkbox - rearrange advanced options
|
Task linked: CU-8694wfy5f Redesign download template page |
| iconPos = "right", | ||
| classProps = {}, | ||
| arrowStyle = "upDown", | ||
| }: SectionProps) => { |
There was a problem hiding this comment.
That's not wrong at all, but typically we prefer to write props: SectionProps here and unpack in the first line of the component, so the signature stays single-line and more readable (subjective!).
| arrowStyle?: arrowStyle; | ||
| } | ||
|
|
||
| export const Section = ({ |
There was a problem hiding this comment.
I see you preferred to define children explicitly in the props instead of using React.FC. We typically use FC, BUT since it adds always children (that's why some people don't like FC), we lose some control, so let's go with this. Eventually, we can decide on creating our own "FCWithProps" or whatever, but no need to to it here.
| return ( | ||
| <Paper elevation={elevation} className={`${classes.paper} ${classProps.section}`}> | ||
| <div | ||
| className={`${classes.header} ${leftIcon} ${classProps.header} ${isOpen ? "" : classes.noBorder}`} |
There was a problem hiding this comment.
If I am not mistaken, when leftIcon is null, it will appear "null" in the class list. There are packages for that (classnames), but you can also do this: _.compact([name1, name2, name3]).join(" ")
| {title} | ||
| {collapsible && !leftIcon && <CollapsibleToggle isOpen={isOpen} arrowStyle={arrowStyle} />} | ||
| </div> | ||
| <div className={`${classProps.content}`} style={{ display: isOpen ? "" : "none" }}> |
There was a problem hiding this comment.
Whenever possible, we strive for immutable props (memoized components will benefit from that).
| arrowStyle: "upDown" | "rightLeft"; | ||
| } | ||
|
|
||
| export const CollapsibleToggle = ({ isOpen, arrowStyle }: CollapsibleToggleProps) => { |
There was a problem hiding this comment.
It's not used externally, right? we can remove the export.
| showLanguage: false, | ||
| } | ||
| ); | ||
| const [showAdvancedOptions, setShowAdvancedOptions] = useState<boolean>(true); |
There was a problem hiding this comment.
Not wrong, but we don't typically pass a type if TS can infer it.
| // const isCustomProgram = state.templateType === "custom" && state.type !== "dataSets"; | ||
| // const populate = isCustomProgram && filterOrgUnits; | ||
| // setState(state => ({ ...state, populate })); | ||
| // clearPopulateDates(); |
There was a problem hiding this comment.
Typically, commented code should be simply removed, we can use git to go back (We may do this for some temporal/testing code, but not in general)
| {models.length > 1 && ( | ||
| <Section | ||
| title={<h3 className={classes.title}>{i18n.t("Template")}</h3>} | ||
| classProps={{ section: classes.section }} |
There was a problem hiding this comment.
[immutable props] I think we can simply pass "classes" here (unless we really don't want to pass the other keys that Section uses (header?). If that's the case, we can use useMemo to build the object. We would be using useMemo not because it's a costly operation, but to keep the value/prop immutable.
| label={i18n.t("Split data entry tabs by section")} | ||
| /> | ||
| )} | ||
|
|
There was a problem hiding this comment.
[not to change] The return JSX expression of this component is huuuge (608-294 lines). That's not your fault, you are just moving already existing parts. So this is a note for the future: whenever a component grows too much, let's abstract conceptual units and create new components. But again, it does not make sense to do it now (it's more fitting for a general refactoring/polishing task)
| elevation = 1, | ||
| iconPos = "right", | ||
| classProps = {}, | ||
| arrowStyle = "upDown", |
There was a problem hiding this comment.
About the expand/collapse styles, I checked what DHIS2 does, and... it depends:
orgUnits tree (icon: left the name): right/down
maps (icon: top-right): up/down
https://play.im.dhis2.org/stable-2-40-6/dhis-web-maps/#/GlCLRPPLsWF
I have no strong opinion on this, so PM to decide.
- update section classProps to more specific classNames - update arrowStyle. Add down_right
…om/EyeSeeTea/Bulk-Load into feature/download-template-redesign
tokland
left a comment
There was a problem hiding this comment.
All good! Just added a commit for some useMemo and a comment about i18.
| msgstr "<Sin valor>" | ||
| #, fuzzy | ||
| msgid "Populate" | ||
| msgstr "Plantilla" |
There was a problem hiding this comment.
We typically check fuzzy tags in PO files (gettext adds them, meaning: "I think this is the translation for a new literal I found, which is very similar to another existing, but I am not sure"). We review if correct and the remove the line "#, fuzzy".
BUT, as all the po files already contain fuzzy tags (a lot), you may leave this task to another "cleaning" PR, not in this feature. Confirm with your PM.
| const selected = state.id && state.templateId ? getOptionValue({ id: state.id, templateId: state.templateId }) : ""; | ||
|
|
||
| const subSectionClasses = useMemo(() => ({ sectionHeader: classes.subSectionHeader, sectionPaper: classes.subSection }), [classes]); | ||
| const subSectionClasses = { sectionHeader: classes.subSectionHeader, sectionPaper: classes.subSection }; |
There was a problem hiding this comment.
[ALREADY COMMITED] But here we do need useMemo to keep it immutable, as it's an object directly passed as a prop (string, numbers, booleans, null, undefined are directly comparable, array/objects/pretty much everything else, not)
tokland
left a comment
There was a problem hiding this comment.
I got the re-review but I think there is nothing new from my previous approval. Approving again. Let me know if there's something specific I should look at.
# Conflicts: # i18n/en.pot # i18n/es.po # i18n/fr.po # i18n/pt.po # i18n/ru.po # src/webapp/components/template-selector/TemplateSelector.tsx
BundleMonNo change in files bundle size Groups updated (1)
Final result: ✅ View report in BundleMon website ➡️ |
📌 References
📝 Implementation
filterOrgUnitslogic. Remove clearing of populate, populate dates, and selectedOrgUnits (more notes in reviewers section)🔥 Notes for the reviewer
📹 Screenshots/Screen capture
📑 Others