-
Notifications
You must be signed in to change notification settings - Fork 2
Update contingency list by filter form UI #769
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
Open
flomillot
wants to merge
6
commits into
main
Choose a base branch
from
change-contingency-filter-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+305
−191
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b55a4a6
Add `EquipmentTypesByFilters` component and improve layout in conting…
flomillot 7e7ead0
Move cell renderers to @gridsuite/commons-ui
flomillot 546af95
Improve accessibility and layout in filter-based contingency list com…
flomillot db39ae5
Merge branch 'main' into change-contingency-filter-ui
flomillot 55681b8
Fix ESlint
flomillot 7a30ba2
Fix Sonar
flomillot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,36 +6,27 @@ | |||||
| */ | ||||||
| import { | ||||||
| ArrayAction, | ||||||
| CONTINGENCY_LIST_EQUIPMENTS, | ||||||
| ContingencyListEquipment, | ||||||
| DescriptionField, | ||||||
| OverflowableChipWithHelperText, | ||||||
| DirectoryItemsInput, | ||||||
| ElementType, | ||||||
| EquipmentType, | ||||||
| FieldConstants, | ||||||
| MuiStyles, | ||||||
| OverflowableChipWithHelperText, | ||||||
| ResizeHandle, | ||||||
| UniqueNameInput, | ||||||
| } from '@gridsuite/commons-ui'; | ||||||
| import { | ||||||
| Checkbox, | ||||||
| Divider, | ||||||
| Grid, | ||||||
| Paper, | ||||||
| Table, | ||||||
| TableBody, | ||||||
| TableCell, | ||||||
| TableContainer, | ||||||
| TableHead, | ||||||
| TableRow, | ||||||
| } from '@mui/material'; | ||||||
| import { Grid } from '@mui/material'; | ||||||
| import { useSelector } from 'react-redux'; | ||||||
| import { FormattedMessage } from 'react-intl'; | ||||||
| import { useCallback, useState } from 'react'; | ||||||
| import { useCallback, useEffect, useRef, useState } from 'react'; | ||||||
| import { useFormContext, useWatch } from 'react-hook-form'; | ||||||
| import { ImperativePanelGroupHandle, Panel, PanelGroup } from 'react-resizable-panels'; | ||||||
| import { AppState } from '../../../../redux/types'; | ||||||
| import { ContingencyFieldConstants, FilterElement, FilterSubEquipments } from '../../../../utils/contingency-list.type'; | ||||||
| import { FilterBasedContingencyListVisualizationPanel } from './filter-based-contingency-list-visualization-panel'; | ||||||
| import { isSubstationOrVoltageLevelFilter } from '../contingency-list-utils'; | ||||||
| import { EquipmentTypesByFilters } from './equipment-types-by-filters'; | ||||||
|
|
||||||
| const equipmentTypes: string[] = [ | ||||||
| EquipmentType.SUBSTATION, | ||||||
|
|
@@ -52,61 +43,73 @@ const equipmentTypes: string[] = [ | |||||
| EquipmentType.DANGLING_LINE, | ||||||
| ]; | ||||||
|
|
||||||
| export default function ContingencyListFilterBasedForm() { | ||||||
| const styles = { | ||||||
| handle: (theme) => ({ | ||||||
| backgroundColor: 'inherit', | ||||||
| width: 15, | ||||||
| marginLeft: 8, | ||||||
| marginRight: 8, | ||||||
| }), | ||||||
| } as const satisfies MuiStyles; | ||||||
|
|
||||||
| // sizes in percent | ||||||
| const LEFT_PANEL_MIN_SIZE = 25; | ||||||
| const LEFT_PANEL_DEFAULT_SIZE = 33; | ||||||
| const RIGHT_PANEL_MIN_SIZE = 25; | ||||||
|
|
||||||
| interface ContingencyListFilterBasedFormProps { | ||||||
| isSubOrVlFilterIncluded: boolean; | ||||||
| setIsSubOrVlFilterIncluded: (value: boolean) => void; | ||||||
| } | ||||||
|
|
||||||
| export default function ContingencyListFilterBasedForm({ | ||||||
| isSubOrVlFilterIncluded, | ||||||
| setIsSubOrVlFilterIncluded, | ||||||
| }: Readonly<ContingencyListFilterBasedFormProps>) { | ||||||
| const { setValue, getValues } = useFormContext(); | ||||||
| const activeDirectory = useSelector((state: AppState) => state.activeDirectory); | ||||||
| const [selectedFilterId, setSelectedFilterId] = useState<string | null>(null); | ||||||
| const [isDataOutdated, setIsDataOutdated] = useState<boolean>(false); | ||||||
|
|
||||||
| const filters: FilterElement[] = useWatch({ name: FieldConstants.FILTERS }) as unknown as FilterElement[]; | ||||||
| const filters: FilterElement[] = useWatch({ | ||||||
| name: FieldConstants.FILTERS, | ||||||
| }) as unknown as FilterElement[]; | ||||||
| const substationAndVLFilters = filters.filter(isSubstationOrVoltageLevelFilter); | ||||||
| const filtersSubEquipments: FilterSubEquipments[] = useWatch({ | ||||||
| name: ContingencyFieldConstants.SUB_EQUIPMENT_TYPES_BY_FILTER, | ||||||
| }) as unknown as FilterSubEquipments[]; | ||||||
|
|
||||||
| const handleFilterRowClick = useCallback((clickedFilterId: string, currentFilterId: string | null) => { | ||||||
| if (clickedFilterId !== currentFilterId) { | ||||||
| setSelectedFilterId(clickedFilterId); | ||||||
| } | ||||||
| }, []); | ||||||
|
|
||||||
| const filterEquipmentTypes = | ||||||
| selectedFilterId && | ||||||
| filtersSubEquipments?.find((value) => value[ContingencyFieldConstants.FILTER_ID] === selectedFilterId)?.[ | ||||||
| ContingencyFieldConstants.SUB_EQUIPMENT_TYPES | ||||||
| ]; | ||||||
| const panelGroupRef = useRef<ImperativePanelGroupHandle>(null); | ||||||
|
|
||||||
| const handleEquipmentRowClick = useCallback( | ||||||
| (equipmentType: string, isEquipmentSelected: boolean, selectedFilterIdP: string | null) => { | ||||||
| const currentSubEquipmentsByFilters: FilterSubEquipments[] = getValues( | ||||||
| ContingencyFieldConstants.SUB_EQUIPMENT_TYPES_BY_FILTER | ||||||
| ); | ||||||
| setValue( | ||||||
| ContingencyFieldConstants.SUB_EQUIPMENT_TYPES_BY_FILTER, | ||||||
| currentSubEquipmentsByFilters.map((value) => { | ||||||
| if (value[ContingencyFieldConstants.FILTER_ID] === selectedFilterIdP) { | ||||||
| // we either add or remove the clicked equipment from the list of subEquipments | ||||||
| // depending on if the equipment is already selected or not | ||||||
| const updatedSubEquipments = isEquipmentSelected | ||||||
| ? value[ContingencyFieldConstants.SUB_EQUIPMENT_TYPES].filter( | ||||||
| (subEquipment: string) => subEquipment !== equipmentType | ||||||
| ) | ||||||
| : [...value[ContingencyFieldConstants.SUB_EQUIPMENT_TYPES], equipmentType]; | ||||||
| useEffect(() => { | ||||||
| const panelGroup = panelGroupRef.current; | ||||||
| if (substationAndVLFilters.length > 0 && !isSubOrVlFilterIncluded) { | ||||||
| setIsSubOrVlFilterIncluded(true); | ||||||
| if (panelGroup) { | ||||||
| panelGroup.setLayout([60, 40]); | ||||||
| } | ||||||
| } else if (substationAndVLFilters.length === 0 && isSubOrVlFilterIncluded) { | ||||||
| setIsSubOrVlFilterIncluded(false); | ||||||
| if (panelGroup) { | ||||||
| panelGroup.setLayout([33, 67]); | ||||||
| } | ||||||
| } | ||||||
| }, [substationAndVLFilters, setIsSubOrVlFilterIncluded, isSubOrVlFilterIncluded]); | ||||||
|
|
||||||
| return { | ||||||
| ...value, | ||||||
| [ContingencyFieldConstants.SUB_EQUIPMENT_TYPES]: updatedSubEquipments, | ||||||
| }; | ||||||
| } | ||||||
| // for the other filters, we just return the value as is | ||||||
| return value; | ||||||
| }), | ||||||
| { shouldDirty: true } | ||||||
| ); | ||||||
| setIsDataOutdated(true); | ||||||
| }, | ||||||
| [setValue, getValues] | ||||||
| ); | ||||||
| // TODO : uncomment when useEffectEvent will be available | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| // const theme = useTheme(); | ||||||
| // const isMdDown = useMediaQuery(theme.breakpoints.down('md')); | ||||||
| // const resizePanelsOnBreakpoint = useEffectEvent(isMdDown => { | ||||||
| // const panelGroup = panelGroupRef.current; | ||||||
| // if (panelGroup) { | ||||||
| // if (isMdDown) { | ||||||
| // panelGroup.setLayout([50, 50]); | ||||||
| // } else if (isSubOrVlFilterIncluded) { | ||||||
| // panelGroup.setLayout([33, 67]); | ||||||
| // } else { | ||||||
| // panelGroup.setLayout([60, 40]); | ||||||
| // } | ||||||
| // } | ||||||
| // }); | ||||||
| // useEffect(() => { | ||||||
| // onMdDown(isMdDown); | ||||||
| // }, [isMdDown]); | ||||||
|
|
||||||
| const handleFilterOnChange = useCallback( | ||||||
| (_currentFilters: any, action?: ArrayAction, filter?: FilterElement) => { | ||||||
|
|
@@ -142,120 +145,62 @@ export default function ContingencyListFilterBasedForm() { | |||||
| ); | ||||||
|
|
||||||
| return ( | ||||||
| <Grid container spacing={2} sx={{ height: '100%' }}> | ||||||
| <Grid item container direction="column" xs={8} spacing={1}> | ||||||
| <Grid item> | ||||||
| <UniqueNameInput | ||||||
| name={FieldConstants.NAME} | ||||||
| label="nameProperty" | ||||||
| elementType={ElementType.CONTINGENCY_LIST} | ||||||
| activeDirectory={activeDirectory} | ||||||
| /> | ||||||
| </Grid> | ||||||
| <Grid item> | ||||||
| <DescriptionField /> | ||||||
| </Grid> | ||||||
| <Grid item> | ||||||
| <FormattedMessage id="Filters" /> | ||||||
| </Grid> | ||||||
| <Grid item> | ||||||
| <DirectoryItemsInput | ||||||
| titleId="FiltersListsSelection" | ||||||
| label="" | ||||||
| name={FieldConstants.FILTERS} | ||||||
| elementType={ElementType.FILTER} | ||||||
| equipmentTypes={equipmentTypes} | ||||||
| onChange={handleFilterOnChange} | ||||||
| ChipComponent={OverflowableChipWithHelperText} | ||||||
| chipProps={{ variant: 'outlined' }} | ||||||
| /> | ||||||
| </Grid> | ||||||
| {substationAndVLFilters.length > 0 && ( | ||||||
| <> | ||||||
| <PanelGroup direction="horizontal" ref={panelGroupRef}> | ||||||
| <Panel defaultSize={LEFT_PANEL_DEFAULT_SIZE} minSize={LEFT_PANEL_MIN_SIZE}> | ||||||
| <Grid | ||||||
| container | ||||||
| columnSpacing={1.5} | ||||||
| sx={(theme) => ({ | ||||||
| height: '100%', | ||||||
| [theme.breakpoints.up('md')]: { | ||||||
| flexWrap: 'nowrap', | ||||||
| }, | ||||||
| })} | ||||||
| > | ||||||
| <Grid item container direction="column" rowSpacing={0.5} xs> | ||||||
| <Grid item> | ||||||
| <UniqueNameInput | ||||||
| name={FieldConstants.NAME} | ||||||
| label="nameProperty" | ||||||
| elementType={ElementType.CONTINGENCY_LIST} | ||||||
| activeDirectory={activeDirectory} | ||||||
| /> | ||||||
| </Grid> | ||||||
| <Grid item> | ||||||
| <FormattedMessage id="equipmentTypesByFilters" /> | ||||||
| <DescriptionField /> | ||||||
| </Grid> | ||||||
| <Grid item component="h4"> | ||||||
| <FormattedMessage id="Filters" /> | ||||||
| </Grid> | ||||||
| <Grid item container xs> | ||||||
| <Grid item xs={6} marginRight={-0.08}> | ||||||
| <TableContainer component={Paper} sx={{ height: '100%', border: 0.5 }}> | ||||||
| <Table> | ||||||
| <TableHead> | ||||||
| <TableRow> | ||||||
| <TableCell> | ||||||
| <FormattedMessage id="contingencyList.filterBased.filtersTableColumn" /> | ||||||
| </TableCell> | ||||||
| </TableRow> | ||||||
| </TableHead> | ||||||
| <TableBody> | ||||||
| {substationAndVLFilters.map((filterRow) => ( | ||||||
| <TableRow | ||||||
| key={filterRow.id} | ||||||
| hover | ||||||
| onClick={() => handleFilterRowClick(filterRow.id, selectedFilterId)} | ||||||
| selected={filterRow.id === selectedFilterId} | ||||||
| > | ||||||
| <TableCell component="th" scope="row"> | ||||||
| {filterRow.name} | ||||||
| </TableCell> | ||||||
| </TableRow> | ||||||
| ))} | ||||||
| </TableBody> | ||||||
| </Table> | ||||||
| </TableContainer> | ||||||
| </Grid> | ||||||
| <Grid item xs={6} marginLeft={-0.08}> | ||||||
| <TableContainer component={Paper} sx={{ height: '100%', border: 0.5 }}> | ||||||
| <Table> | ||||||
| <TableHead> | ||||||
| <TableRow> | ||||||
| <TableCell> | ||||||
| <FormattedMessage id="contingencyList.filterBased.subEquipmentsTableColumn" /> | ||||||
| </TableCell> | ||||||
| </TableRow> | ||||||
| </TableHead> | ||||||
| <TableBody> | ||||||
| {filterEquipmentTypes && | ||||||
| Object.values(CONTINGENCY_LIST_EQUIPMENTS).map( | ||||||
| (equipmentRow: ContingencyListEquipment) => { | ||||||
| const isEquipmentSelected = filterEquipmentTypes.includes( | ||||||
| equipmentRow.id | ||||||
| ); | ||||||
| return ( | ||||||
| <TableRow | ||||||
| key={equipmentRow.id} | ||||||
| hover | ||||||
| onClick={() => | ||||||
| handleEquipmentRowClick( | ||||||
| equipmentRow.id, | ||||||
| isEquipmentSelected, | ||||||
| selectedFilterId | ||||||
| ) | ||||||
| } | ||||||
| selected={isEquipmentSelected} | ||||||
| > | ||||||
| <TableCell padding="checkbox"> | ||||||
| <Checkbox checked={isEquipmentSelected} /> | ||||||
| <FormattedMessage id={equipmentRow.label} /> | ||||||
| </TableCell> | ||||||
| </TableRow> | ||||||
| ); | ||||||
| } | ||||||
| )} | ||||||
| </TableBody> | ||||||
| </Table> | ||||||
| </TableContainer> | ||||||
| </Grid> | ||||||
| <Grid item xs> | ||||||
| <DirectoryItemsInput | ||||||
| titleId="FiltersListsSelection" | ||||||
| label="" | ||||||
| name={FieldConstants.FILTERS} | ||||||
| elementType={ElementType.FILTER} | ||||||
| equipmentTypes={equipmentTypes} | ||||||
| onChange={handleFilterOnChange} | ||||||
| ChipComponent={OverflowableChipWithHelperText} | ||||||
| chipProps={{ variant: 'outlined' }} | ||||||
| fullHeight | ||||||
| /> | ||||||
| </Grid> | ||||||
| </> | ||||||
| )} | ||||||
| </Grid> | ||||||
| <Grid item> | ||||||
| <Divider orientation="vertical" /> | ||||||
| </Grid> | ||||||
| <FilterBasedContingencyListVisualizationPanel | ||||||
| isDataOutdated={isDataOutdated} | ||||||
| setIsDataOutdated={setIsDataOutdated} | ||||||
| /> | ||||||
| </Grid> | ||||||
| </Grid> | ||||||
| {isSubOrVlFilterIncluded && ( | ||||||
| <EquipmentTypesByFilters | ||||||
| substationAndVLFilters={substationAndVLFilters} | ||||||
| setIsDataOutdated={setIsDataOutdated} | ||||||
| /> | ||||||
| )} | ||||||
| </Grid> | ||||||
| </Panel> | ||||||
| <ResizeHandle style={styles.handle} /> | ||||||
| <Panel minSize={RIGHT_PANEL_MIN_SIZE}> | ||||||
| <FilterBasedContingencyListVisualizationPanel | ||||||
| isDataOutdated={isDataOutdated} | ||||||
| setIsDataOutdated={setIsDataOutdated} | ||||||
| /> | ||||||
| </Panel> | ||||||
| </PanelGroup> | ||||||
| ); | ||||||
| } | ||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use import default
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no I cant there is an eslint errorOk works with the code above