From 3031a13ca1a72f64a0e4c160d3f47d90f3223141 Mon Sep 17 00:00:00 2001 From: Ana Garcia Date: Thu, 4 Jul 2024 15:29:45 +0200 Subject: [PATCH] Separate components at same level for more redeability and avoid re-render because inputProps object --- src/webapp/components/avatar-card/AvatarCard.tsx | 1 + src/webapp/components/checkbox/Checkbox.tsx | 8 ++++++-- src/webapp/components/date-picker/DatePicker.tsx | 1 + src/webapp/components/form/FormLayout.tsx | 4 ++++ src/webapp/components/form/FormSection.tsx | 3 +++ src/webapp/components/layout/Layout.tsx | 1 + .../components/layout/header-bar/HeaderBar.tsx | 4 ++++ .../layout/main-content/MainContent.tsx | 3 +++ src/webapp/components/notice-box/NoticeBox.tsx | 1 + .../components/profile-modal/ProfileModal.tsx | 3 +++ .../radio-buttons-group/RadioButtonsGroup.tsx | 2 ++ .../components/search-input/SearchInput.tsx | 15 +++++++++------ src/webapp/components/section/Section.tsx | 4 ++++ .../components/selector/MultipleSelector.tsx | 2 ++ src/webapp/components/selector/Selector.tsx | 2 ++ src/webapp/components/stats-card/StatsCard.tsx | 3 +++ src/webapp/components/text-input/TextArea.tsx | 2 ++ src/webapp/components/text-input/TextInput.tsx | 1 + 18 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/webapp/components/avatar-card/AvatarCard.tsx b/src/webapp/components/avatar-card/AvatarCard.tsx index c3996df6..b2e61747 100644 --- a/src/webapp/components/avatar-card/AvatarCard.tsx +++ b/src/webapp/components/avatar-card/AvatarCard.tsx @@ -16,6 +16,7 @@ export const AvatarCard: React.FC = React.memo( + {children} ); diff --git a/src/webapp/components/checkbox/Checkbox.tsx b/src/webapp/components/checkbox/Checkbox.tsx index 811615d3..47634f61 100644 --- a/src/webapp/components/checkbox/Checkbox.tsx +++ b/src/webapp/components/checkbox/Checkbox.tsx @@ -1,4 +1,4 @@ -import React, { useCallback } from "react"; +import React, { useCallback, useMemo } from "react"; import { Checkbox as MUICheckbox, InputLabel, FormHelperText } from "@material-ui/core"; import styled from "styled-components"; @@ -32,6 +32,8 @@ export const Checkbox: React.FC = React.memo( [onChange] ); + const inputProps = useMemo(() => ({ "aria-label": label || `${id}-label` }), [id, label]); + return ( @@ -42,12 +44,14 @@ export const Checkbox: React.FC = React.memo( onChange={handleChange} disabled={disabled} size="small" - inputProps={{ "aria-label": label || `${id}-label` }} + inputProps={inputProps} /> + + {helperText} ); diff --git a/src/webapp/components/date-picker/DatePicker.tsx b/src/webapp/components/date-picker/DatePicker.tsx index 7942ab72..d91eb55f 100644 --- a/src/webapp/components/date-picker/DatePicker.tsx +++ b/src/webapp/components/date-picker/DatePicker.tsx @@ -37,6 +37,7 @@ export const DatePicker: React.FC = React.memo( {label} )} + = React.memo( {title && {title}} {subtitle && {subtitle}} + {i18n.t("Indicates required")} + {children} +
+ {onCancel && ( diff --git a/src/webapp/components/form/FormSection.tsx b/src/webapp/components/form/FormSection.tsx index cc28e8a0..f5e7fae0 100644 --- a/src/webapp/components/form/FormSection.tsx +++ b/src/webapp/components/form/FormSection.tsx @@ -26,17 +26,20 @@ export const FormSection: React.FC = React.memo( return ( {hasSeparator && } + {title && ( {title} + {onClickInfo && ( } onClick={onClickInfo} /> )} )} + {children} diff --git a/src/webapp/components/layout/Layout.tsx b/src/webapp/components/layout/Layout.tsx index 0ce3f570..a46edc49 100644 --- a/src/webapp/components/layout/Layout.tsx +++ b/src/webapp/components/layout/Layout.tsx @@ -33,6 +33,7 @@ export const Layout: React.FC = React.memo(
diff --git a/src/webapp/components/radio-buttons-group/RadioButtonsGroup.tsx b/src/webapp/components/radio-buttons-group/RadioButtonsGroup.tsx index a9d1e3f6..da9c44a8 100644 --- a/src/webapp/components/radio-buttons-group/RadioButtonsGroup.tsx +++ b/src/webapp/components/radio-buttons-group/RadioButtonsGroup.tsx @@ -38,6 +38,7 @@ export function RadioButtonsGroup({ {label} )} + ({ /> ))} + {error && !!errorText ? errorText : helperText} diff --git a/src/webapp/components/search-input/SearchInput.tsx b/src/webapp/components/search-input/SearchInput.tsx index d8820949..1ee7e43a 100644 --- a/src/webapp/components/search-input/SearchInput.tsx +++ b/src/webapp/components/search-input/SearchInput.tsx @@ -12,17 +12,19 @@ type SearchInputProps = { disabled?: boolean; }; +const INPUT_PROPS = { "aria-label": "search" }; + export const SearchInput: React.FC = React.memo( ({ value, onChange, placeholder = "", disabled = false }) => { const [stateValue, updateStateValue] = useState(value); useEffect(() => updateStateValue(value), [value]); - // eslint-disable-next-line react-hooks/exhaustive-deps - const onChangeDebounced = useCallback( - debounce((value: string) => { - if (onChange) onChange(value); - }, 400), + const onChangeDebounced = React.useMemo( + () => + debounce((value: string) => { + if (onChange) onChange(value); + }, 400), [onChange] ); @@ -44,6 +46,7 @@ export const SearchInput: React.FC = React.memo( + = React.memo( onKeyDown={handleKeydown} disabled={disabled} variant="outlined" - inputProps={{ "aria-label": "search" }} + inputProps={INPUT_PROPS} /> ); diff --git a/src/webapp/components/section/Section.tsx b/src/webapp/components/section/Section.tsx index 2d3b9637..3c830442 100644 --- a/src/webapp/components/section/Section.tsx +++ b/src/webapp/components/section/Section.tsx @@ -25,9 +25,11 @@ export const Section: React.FC = React.memo( return ( {hasSeparator && } +
{title ? {title} : null} + {lastUpdated ? ( @@ -37,8 +39,10 @@ export const Section: React.FC = React.memo( ) : null} + {headerButtom ?
{headerButtom}
: null}
+ {children}
); diff --git a/src/webapp/components/selector/MultipleSelector.tsx b/src/webapp/components/selector/MultipleSelector.tsx index fc0ff41b..12ae7c00 100644 --- a/src/webapp/components/selector/MultipleSelector.tsx +++ b/src/webapp/components/selector/MultipleSelector.tsx @@ -60,6 +60,7 @@ export function MultipleSelector({ {label} )} + ({ ))} + {error && !!errorText ? errorText : helperText} diff --git a/src/webapp/components/selector/Selector.tsx b/src/webapp/components/selector/Selector.tsx index cb2914f4..e2aedd36 100644 --- a/src/webapp/components/selector/Selector.tsx +++ b/src/webapp/components/selector/Selector.tsx @@ -52,6 +52,7 @@ export function Selector({ {label} )} + ({ ))} + {error && !!errorText ? errorText : helperText} diff --git a/src/webapp/components/stats-card/StatsCard.tsx b/src/webapp/components/stats-card/StatsCard.tsx index b265db9c..de706cc8 100644 --- a/src/webapp/components/stats-card/StatsCard.tsx +++ b/src/webapp/components/stats-card/StatsCard.tsx @@ -26,8 +26,11 @@ export const StatsCard: React.FC = React.memo( {`${stat}${isPercentage ? " %" : ""}`} + {pretitle} + {title} + {subtitle} diff --git a/src/webapp/components/text-input/TextArea.tsx b/src/webapp/components/text-input/TextArea.tsx index d6f3302b..576ebaa5 100644 --- a/src/webapp/components/text-input/TextArea.tsx +++ b/src/webapp/components/text-input/TextArea.tsx @@ -40,6 +40,7 @@ export const TextArea: React.FC = React.memo( {label} )} + = React.memo( disabled={disabled} $hasError={error} /> + {error && !!errorText ? errorText : helperText} diff --git a/src/webapp/components/text-input/TextInput.tsx b/src/webapp/components/text-input/TextInput.tsx index 367244bf..5e4e0c44 100644 --- a/src/webapp/components/text-input/TextInput.tsx +++ b/src/webapp/components/text-input/TextInput.tsx @@ -33,6 +33,7 @@ export const TextInput: React.FC = React.memo( {label} )} +