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

Improve filter IHM (by using box with flex system) #615

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5829a2b
draft refacto improve filter ihm
Mathieu-Deharbe Sep 11, 2024
e36d844
Merge branch 'main' into improve-filter-ihm
Mathieu-Deharbe Sep 18, 2024
e6a882f
new FilterForm file
Mathieu-Deharbe Sep 18, 2024
4f53a68
corrects errors
Mathieu-Deharbe Sep 18, 2024
7950a93
fixed window height
Mathieu-Deharbe Sep 19, 2024
e262283
draft scrolling update
Mathieu-Deharbe Sep 24, 2024
41113ef
Merge branch 'main' into improve-filter-ihm
Mathieu-Deharbe Sep 24, 2024
1591f18
much better scrolling
Mathieu-Deharbe Sep 24, 2024
3139240
read only prop
Mathieu-Deharbe Sep 24, 2024
706cb2b
Merge branch 'main' into improve-filter-ihm
Mathieu-Deharbe Sep 26, 2024
dedbbd0
95vh
Mathieu-Deharbe Oct 1, 2024
d665e3e
Merge remote-tracking branch 'origin/improve-filter-ihm' into improve…
Mathieu-Deharbe Oct 1, 2024
713bbce
Merge branch 'main' into improve-filter-ihm
Mathieu-Deharbe Oct 1, 2024
51d29a1
unscrollableFullHeight props parameter
Mathieu-Deharbe Oct 1, 2024
51a45a2
padding
Mathieu-Deharbe Oct 1, 2024
5e3374f
draft scroll for exmplicit naming filters
Mathieu-Deharbe Oct 1, 2024
355ae33
Merge branch 'main' into improve-filter-ihm
Mathieu-Deharbe Oct 1, 2024
8e6a88b
expert filters scroll
Mathieu-Deharbe Oct 1, 2024
405efb0
Merge remote-tracking branch 'origin/improve-filter-ihm' into improve…
Mathieu-Deharbe Oct 1, 2024
e8e8f8c
reset CriteriaForm to make it usable with aleas
Mathieu-Deharbe Oct 2, 2024
1b3d7d2
min height
Mathieu-Deharbe Oct 2, 2024
3353523
Merge branch 'main' into improve-filter-ihm
Mathieu-Deharbe Oct 4, 2024
c90f1ee
Merge branch 'main' into improve-filter-ihm
Mathieu-Deharbe Oct 11, 2024
aadba6a
adds a Readonly
Mathieu-Deharbe Oct 11, 2024
04cb687
Merge branch 'main' into improve-filter-ihm
thangqp Oct 15, 2024
6930ffb
Improve filter IHM (by using box with flex system)
thangqp Oct 16, 2024
fda5dbd
Remove a wrapper box and set padding to 1 for all box
thangqp Oct 16, 2024
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
25 changes: 23 additions & 2 deletions src/components/dialogs/customMuiDialog/CustomMuiDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface CustomMuiDialogProps {
isDataFetching?: boolean;
language?: string;
confirmationMessageKey?: string;
unscrollableFullHeight?: boolean;
}

const styles = {
Expand All @@ -40,6 +41,20 @@ const styles = {
margin: 'auto',
},
},
dialogPaperFullHeight: {
'.MuiDialog-paper': {
width: 'auto',
minWidth: '1000px',
margin: 'auto',
height: '95vh',
overflowY: 'hidden',
},
},
unscrollable: {
display: 'flex',
flexDirection: 'column',
overflowY: 'hidden',
},
};

export function CustomMuiDialog({
Expand All @@ -57,6 +72,7 @@ export function CustomMuiDialog({
children,
language,
confirmationMessageKey,
unscrollableFullHeight = false,
}: Readonly<CustomMuiDialogProps>) {
const [openConfirmationPopup, setOpenConfirmationPopup] = useState(false);
const [validatedData, setValidatedData] = useState(undefined);
Expand Down Expand Up @@ -113,14 +129,19 @@ export function CustomMuiDialog({
removeOptional={removeOptional}
language={language}
>
<Dialog sx={styles.dialogPaper} open={open} onClose={handleClose} fullWidth>
<Dialog
sx={unscrollableFullHeight ? styles.dialogPaperFullHeight : styles.dialogPaper}
open={open}
onClose={handleClose}
fullWidth
>
{isDataFetching && <LinearProgress />}
<DialogTitle>
<Grid item xs={11}>
<FormattedMessage id={titleId} />
</Grid>
</DialogTitle>
<DialogContent>{children}</DialogContent>
<DialogContent sx={unscrollableFullHeight ? styles.unscrollable : null}>{children}</DialogContent>
<DialogActions>
<CancelButton onClick={handleCancel} />
<SubmitButton
Expand Down
1 change: 1 addition & 0 deletions src/components/filter/FilterCreationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export function FilterCreationDialog({
removeOptional
disabledSave={!!nameError || !!isValidating}
language={language}
unscrollableFullHeight
>
<FilterForm
creation
Expand Down
79 changes: 21 additions & 58 deletions src/components/filter/FilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,45 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import React, { useEffect } from 'react';
import { useFormContext, useWatch } from 'react-hook-form';
import { Grid } from '@mui/material';
import { UUID } from 'crypto';
import { Box } from '@mui/material';
import { useWatch } from 'react-hook-form';
import { FilterFormProps, HeaderFilterForm } from './HeaderFilterForm';
import { FieldConstants } from '../../utils/constants/fieldConstants';
import { CriteriaBasedFilterForm } from './criteriaBased/CriteriaBasedFilterForm';
import { ExplicitNamingFilterForm } from './explicitNaming/ExplicitNamingFilterForm';
import { ExpertFilterForm } from './expert/ExpertFilterForm';
import { FilterType } from './constants/FilterConstants';
import { RadioInput } from '../inputs/reactHookForm/booleans/RadioInput';
import { ElementExistsType, ElementType } from '../../utils/types/elementType';
import { UniqueNameInput } from '../inputs/reactHookForm/text/UniqueNameInput';
import { DescriptionField } from '../inputs/reactHookForm/text/DescriptionField';

export interface FilterFormProps {
creation?: boolean;
activeDirectory?: UUID;
elementExists?: ElementExistsType;
sourceFilterForExplicitNamingConversion?: {
id: UUID;
equipmentType: string;
};
}

export function FilterForm(props: FilterFormProps) {
const { sourceFilterForExplicitNamingConversion, creation, activeDirectory, elementExists } = props;
const { setValue } = useFormContext();

export function FilterForm({
sourceFilterForExplicitNamingConversion,
creation,
activeDirectory,
elementExists,
}: Readonly<FilterFormProps>) {
const filterType = useWatch({ name: FieldConstants.FILTER_TYPE });

// We do this because setValue don't set the field dirty
const handleChange = (_event: React.ChangeEvent<HTMLInputElement>, value: string) => {
setValue(FieldConstants.FILTER_TYPE, value);
};

useEffect(() => {
if (sourceFilterForExplicitNamingConversion) {
setValue(FieldConstants.FILTER_TYPE, FilterType.EXPLICIT_NAMING.id);
}
}, [sourceFilterForExplicitNamingConversion, setValue]);

return (
<Grid container spacing={2}>
<Grid item xs={12}>
<UniqueNameInput
name={FieldConstants.NAME}
label="nameProperty"
elementType={ElementType.FILTER}
autoFocus={creation}
<>
<Box
sx={{
flex: 'none',
padding: 1,
}}
>
<HeaderFilterForm
creation={creation}
activeDirectory={activeDirectory}
elementExists={elementExists}
sourceFilterForExplicitNamingConversion={sourceFilterForExplicitNamingConversion}
/>
</Grid>
{creation && (
<>
<Grid item xs={12}>
<DescriptionField />
</Grid>
{!sourceFilterForExplicitNamingConversion && (
<Grid item>
<RadioInput
name={FieldConstants.FILTER_TYPE}
options={Object.values(FilterType)}
formProps={{ onChange: handleChange }} // need to override this in order to do not activate the validate button when changing the filter type
/>
</Grid>
)}
</>
)}
</Box>
{filterType === FilterType.CRITERIA_BASED.id && <CriteriaBasedFilterForm />}
{filterType === FilterType.EXPLICIT_NAMING.id && (
<ExplicitNamingFilterForm
sourceFilterForExplicitNamingConversion={sourceFilterForExplicitNamingConversion}
/>
)}
{filterType === FilterType.EXPERT.id && <ExpertFilterForm />}
</Grid>
</>
);
}
78 changes: 78 additions & 0 deletions src/components/filter/HeaderFilterForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* 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 { useFormContext } from 'react-hook-form';
import React, { useEffect } from 'react';
import { Grid } from '@mui/material';
import { UUID } from 'crypto';
import { FieldConstants } from '../../utils/constants/fieldConstants';
import { FilterType } from './constants/FilterConstants';
import { UniqueNameInput } from '../inputs/reactHookForm/text/UniqueNameInput';
import { ElementExistsType, ElementType } from '../../utils/types/elementType';
import { DescriptionField } from '../inputs/reactHookForm/text/DescriptionField';
import { RadioInput } from '../inputs/reactHookForm/booleans/RadioInput';

export interface FilterFormProps {
creation?: boolean;
activeDirectory?: UUID;
elementExists?: ElementExistsType;
sourceFilterForExplicitNamingConversion?: {
id: UUID;
equipmentType: string;
};
}

export function HeaderFilterForm({
sourceFilterForExplicitNamingConversion,
creation,
activeDirectory,
elementExists,
}: Readonly<FilterFormProps>) {
const { setValue } = useFormContext();

useEffect(() => {
if (sourceFilterForExplicitNamingConversion) {
setValue(FieldConstants.FILTER_TYPE, FilterType.EXPLICIT_NAMING.id);
}
}, [sourceFilterForExplicitNamingConversion, setValue]);

// We do this because setValue don't set the field dirty
const handleChange = (_event: React.ChangeEvent<HTMLInputElement>, value: string) => {
setValue(FieldConstants.FILTER_TYPE, value);
};

return (
<Grid container spacing={2}>
<Grid item xs={12}>
<UniqueNameInput
name={FieldConstants.NAME}
label="nameProperty"
elementType={ElementType.FILTER}
autoFocus={creation}
activeDirectory={activeDirectory}
elementExists={elementExists}
/>
</Grid>
{creation && (
<>
<Grid item xs={12}>
<DescriptionField />
</Grid>
{!sourceFilterForExplicitNamingConversion && (
<Grid item>
<RadioInput
name={FieldConstants.FILTER_TYPE}
options={Object.values(FilterType)}
formProps={{ onChange: handleChange }} // need to override this in order to do not activate the validate button when changing the filter type
/>
</Grid>
)}
</>
)}
</Grid>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export function CriteriaBasedFilterEditionDialog({
disabledSave={!!nameError || !!isValidating}
isDataFetching={dataFetchStatus === FetchStatus.FETCHING}
language={language}
unscrollableFullHeight
>
{isDataReady && <FilterForm activeDirectory={activeDirectory} elementExists={elementExists} />}
</CustomMuiDialog>
Expand Down
12 changes: 5 additions & 7 deletions src/components/filter/criteriaBased/CriteriaBasedFilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 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 Grid from '@mui/material/Grid';
import { FilterProperties, filterPropertiesYupSchema } from './FilterProperties';
import { FieldConstants } from '../../../utils/constants/fieldConstants';
import yup from '../../../utils/yupConfig';
Expand All @@ -26,12 +25,11 @@ export const criteriaBasedFilterEmptyFormData = getCriteriaBasedFormData(null, {

export function CriteriaBasedFilterForm() {
return (
<Grid container item spacing={1}>
<CriteriaBasedForm
equipments={FILTER_EQUIPMENTS}
defaultValues={criteriaBasedFilterEmptyFormData[FieldConstants.CRITERIA_BASED]}
/>
<CriteriaBasedForm
equipments={FILTER_EQUIPMENTS}
defaultValues={criteriaBasedFilterEmptyFormData[FieldConstants.CRITERIA_BASED]}
>
<FilterProperties />
</Grid>
</CriteriaBasedForm>
);
}
53 changes: 35 additions & 18 deletions src/components/filter/criteriaBased/CriteriaBasedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import { useFormContext, useWatch } from 'react-hook-form';
import { Grid } from '@mui/material';
import { useEffect } from 'react';
import { Box, Grid } from '@mui/material';
import { ReactElement, useEffect } from 'react';
import { FieldConstants } from '../../../utils/constants/fieldConstants';
import { SelectInput } from '../../inputs/reactHookForm/selectInputs/SelectInput';
import { InputWithPopupConfirmation } from '../../inputs/reactHookForm/selectInputs/InputWithPopupConfirmation';
Expand All @@ -17,9 +17,10 @@ import { useSnackMessage } from '../../../hooks/useSnackMessage';
export interface CriteriaBasedFormProps {
equipments: Record<string, FormEquipment>;
defaultValues: Record<string, any>;
children?: ReactElement;
}

export function CriteriaBasedForm({ equipments, defaultValues }: CriteriaBasedFormProps) {
export function CriteriaBasedForm({ equipments, defaultValues, children }: CriteriaBasedFormProps) {
const { getValues, setValue } = useFormContext();
const { snackError } = useSnackMessage();

Expand All @@ -46,8 +47,13 @@ export function CriteriaBasedForm({ equipments, defaultValues }: CriteriaBasedFo
};

return (
<Grid container item spacing={2}>
<Grid item xs={12}>
<>
<Box
sx={{
flex: 'none',
padding: 1,
}}
>
<InputWithPopupConfirmation
Input={SelectInput}
name={FieldConstants.EQUIPMENT_TYPE}
Expand All @@ -58,18 +64,29 @@ export function CriteriaBasedForm({ equipments, defaultValues }: CriteriaBasedFo
message="changeTypeMessage"
validateButtonLabel="button.changeType"
/>
</Grid>
{watchEquipmentType &&
equipments[watchEquipmentType] &&
equipments[watchEquipmentType].fields.map((equipment: any, index: number) => {
const EquipmentForm = equipment.renderer;
const uniqueKey = `${watchEquipmentType}-${index}`;
return (
<Grid item xs={12} key={uniqueKey} flexGrow={1}>
<EquipmentForm {...equipment.props} />
</Grid>
);
})}
</Grid>
</Box>
<Box
sx={{
flex: 'auto',
overflowY: 'auto',
padding: 1,
}}
>
<Grid container spacing={2}>
{watchEquipmentType &&
equipments[watchEquipmentType] &&
equipments[watchEquipmentType].fields.map((equipment: any, index: number) => {
const EquipmentForm = equipment.renderer;
const uniqueKey = `${watchEquipmentType}-${index}`;
return (
<Grid item xs={12} key={uniqueKey} flexGrow={1}>
<EquipmentForm {...equipment.props} />
</Grid>
);
})}
{children}
</Grid>
</Box>
</>
);
}
1 change: 1 addition & 0 deletions src/components/filter/expert/ExpertFilterEditionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export function ExpertFilterEditionDialog({
disabledSave={!!nameError || !!isValidating}
isDataFetching={dataFetchStatus === FetchStatus.FETCHING}
language={language}
unscrollableFullHeight
>
{isDataReady && <FilterForm activeDirectory={activeDirectory} elementExists={elementExists} />}
</CustomMuiDialog>
Expand Down
Loading
Loading