Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance description field in filter form proposed #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/components/ExpendableGroup/expendable-group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import {
Accordion,
AccordionDetails,
AccordionSummary,
Theme,
Typography,
} from '@mui/material';
import React, { PropsWithChildren, ReactNode, useState } from 'react';
import { ExpandCircleDown, ExpandMore } from '@mui/icons-material';
import { FormattedMessage } from 'react-intl';

export const styles = {
accordion: (theme: Theme) => ({
'&:before': {
display: 'none',
},
background: 'none',
}),
accordionSummary: (theme: Theme) => ({
flexDirection: 'row-reverse', // place icon at the left
padding: 0, // reset default left right space in summary
'.MuiAccordionSummary-content': {
paddingLeft: 1, // align text label
},
'&:not(.Mui-expanded)': {
// show a fake divider at the bottom of summary
borderBottom: '1px solid',
borderColor: theme.palette.divider,
},

'& .MuiAccordionSummary-expandIconWrapper': {
transform: 'rotate(-90deg)',
},
'& .MuiAccordionSummary-expandIconWrapper.Mui-expanded': {
transform: 'rotate(0deg)',
},
}),
accordionDetails: (theme: Theme) => ({
padding: 0, // reset default left right space in details
}),
};
Comment on lines +18 to +47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize the styling definitions.

The styling uses theme-based customization, which is good for maintaining consistency across different themes. Consider extracting these styles to a separate file if they grow complex or are reused in other components to enhance maintainability.


interface ExpandableGroupProps extends PropsWithChildren {
renderHeader: ReactNode;
}

const ExpendableGroup = ({ renderHeader, children }: ExpandableGroupProps) => {
const [mouseHover, setMouseHover] = useState(false);

return (
<Accordion sx={styles.accordion} disableGutters elevation={0}>
<AccordionSummary
sx={styles.accordionSummary}
expandIcon={mouseHover ? <ExpandCircleDown /> : <ExpandMore />}
onMouseEnter={(event) => setMouseHover(true)}
onMouseLeave={(event) => setMouseHover(false)}
>
{typeof renderHeader === 'string' ? (
<Typography>
<FormattedMessage id={renderHeader} />
</Typography>
) : (
renderHeader
)}
</AccordionSummary>
<AccordionDetails sx={styles.accordionDetails}>
{children}
</AccordionDetails>
</Accordion>
);
};

export default ExpendableGroup;
Comment on lines +53 to +79
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper accessibility and interaction handling in the component.

The component handles hover states to change the expand icon, which enhances user interaction. However, consider adding accessibility features such as aria-labels for better screen reader support.

8 changes: 8 additions & 0 deletions src/components/ExpendableGroup/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

export { default } from './expendable-group';
12 changes: 6 additions & 6 deletions src/components/filter/filter-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import ExplicitNamingFilterForm from './explicit-naming/explicit-naming-filter-f
import React, { FunctionComponent, useEffect } from 'react';
import { useFormContext, useWatch } from 'react-hook-form';
import ExpertFilterForm from './expert/expert-filter-form';
import { Box, Grid } from '@mui/material';
import RadioInput from '../inputs/react-hook-form/radio-input';
import { Grid } from '@mui/material';
import { ElementType } from '../../utils/ElementType';
import { UUID } from 'crypto';
import { elementExistsType } from './criteria-based/criteria-based-filter-edition-dialog';
import ExpandingTextField from '../inputs/react-hook-form/ExpandingTextField';
import { FilterType } from './constants/filter-constants';
import ExpendableGroup from '../ExpendableGroup';
import RadioInput from '../inputs/react-hook-form/radio-input';
import ExpandingTextField from '../inputs/react-hook-form/ExpandingTextField';

interface FilterFormProps {
creation?: boolean;
Expand Down Expand Up @@ -64,14 +65,13 @@ export const FilterForm: FunctionComponent<FilterFormProps> = (props) => {
{props.creation && (
<>
<Grid item xs={12}>
<Box>
<ExpendableGroup renderHeader={'Description'}>
<ExpandingTextField
name={FieldConstants.DESCRIPTION}
label={'descriptionProperty'}
minRows={3}
rows={5}
/>
</Box>
</ExpendableGroup>
</Grid>
{!props.sourceFilterForExplicitNamingConversion && (
<Grid item>
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export { default as ReportViewerDialog } from './components/ReportViewerDialog';
export { default as OverflowableText } from './components/OverflowableText';
export { default as ElementSearchDialog } from './components/ElementSearchDialog';
export { default as FlatParameters } from './components/FlatParameters';
export { default as ExpandableGroup } from './components/ExpendableGroup';
export { default as MultipleSelectionDialog } from './components/MultipleSelectionDialog';
export { default as CustomMuiDialog } from './components/dialogs/custom-mui-dialog';
export { default as DescriptionModificationDialog } from './components/dialogs/description-modification-dialog';
Expand Down