-
Notifications
You must be signed in to change notification settings - Fork 6
Parameters new design #4040
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
Parameters new design #4040
Changes from all commits
e234dbb
81a3060
c86e337
3f4ffda
3e18245
1fc80b6
7d67690
50fcfaf
822d8ee
a32dbe6
320b2aa
6d04217
4476ba1
3bf6178
e177486
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /** | ||
| * Copyright (c) 2025, 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 { SyntheticEvent } from 'react'; | ||
| import { TabPanel } from '@gridsuite/commons-ui'; | ||
| import { Grid2 as Grid, Stack, Tab, Tabs } from '@mui/material'; | ||
| import { FormattedMessage } from 'react-intl'; | ||
| import { TabValue } from './state-estimation-parameters-utils'; | ||
| import { StateEstimationGeneralParameters } from './state-estimation-general-parameters'; | ||
| import { StateEstimationWeightsParameters } from './state-estimation-weights-parameters'; | ||
| import { StateEstimationQualityParameters } from './state-estimation-quality-parameters'; | ||
| import { StateEstimationLoadboundsParameters } from './state-estimation-loadbounds-parameters'; | ||
| import { getTabStyle } from '../../../utils/tab-utils'; | ||
|
|
||
| interface StateEstimationParametersFormProps { | ||
| tabValue: TabValue; | ||
| handleTabChange: (event: SyntheticEvent, newValue: TabValue) => void; | ||
| tabIndexesWithError: TabValue[]; | ||
| } | ||
|
|
||
| export const StateEstimationParametersForm = ({ | ||
| tabValue, | ||
| handleTabChange, | ||
| tabIndexesWithError, | ||
| }: StateEstimationParametersFormProps) => { | ||
| return ( | ||
| <Stack> | ||
| <Tabs | ||
| value={tabValue} | ||
| variant="scrollable" | ||
| onChange={handleTabChange} | ||
| sx={{ borderBottom: 1, borderColor: 'divider' }} | ||
| > | ||
| <Tab | ||
| label={<FormattedMessage id="StateEstimationParametersGeneralTabLabel" />} | ||
| value={TabValue.GENERAL} | ||
| sx={getTabStyle(tabIndexesWithError, TabValue.GENERAL)} | ||
| /> | ||
| <Tab | ||
| label={<FormattedMessage id="StateEstimationParametersWeightsTabLabel" />} | ||
| value={TabValue.WEIGHTS} | ||
| sx={getTabStyle(tabIndexesWithError, TabValue.WEIGHTS)} | ||
| /> | ||
| <Tab | ||
| label={<FormattedMessage id="StateEstimationParametersQualityTabLabel" />} | ||
| value={TabValue.QUALITY} | ||
| sx={getTabStyle(tabIndexesWithError, TabValue.QUALITY)} | ||
| /> | ||
| <Tab | ||
| label={<FormattedMessage id="StateEstimationParametersLoadboundsTabLabel" />} | ||
| value={TabValue.LOADBOUNDS} | ||
| sx={getTabStyle(tabIndexesWithError, TabValue.LOADBOUNDS)} | ||
| /> | ||
| </Tabs> | ||
| <Grid container sx={{ paddingTop: 2 }}> | ||
| <TabPanel value={tabValue} index={TabValue.GENERAL}> | ||
| <StateEstimationGeneralParameters /> | ||
| </TabPanel> | ||
| <TabPanel value={tabValue} index={TabValue.WEIGHTS}> | ||
| <StateEstimationWeightsParameters /> | ||
| </TabPanel> | ||
| <TabPanel value={tabValue} index={TabValue.QUALITY}> | ||
| <StateEstimationQualityParameters /> | ||
| </TabPanel> | ||
| <TabPanel value={tabValue} index={TabValue.LOADBOUNDS}> | ||
| <StateEstimationLoadboundsParameters /> | ||
| </TabPanel> | ||
| </Grid> | ||
| </Stack> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,36 +5,28 @@ | |
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| import { SyntheticEvent, useCallback, useEffect, useMemo, useState } from 'react'; | ||
|
|
||
| import { | ||
| CustomFormProvider, | ||
| mergeSx, | ||
| PopupConfirmationDialog, | ||
| snackWithFallback, | ||
| SubmitButton, | ||
| TabPanel, | ||
| useSnackMessage, | ||
| ParameterLayout, | ||
| ElementType, | ||
| } from '@gridsuite/commons-ui'; | ||
| import { Button, DialogActions, Grid2 as Grid, Stack, Tab, Tabs } from '@mui/material'; | ||
| import { getTabIndicatorStyle, getTabStyle } from '../../../utils/tab-utils'; | ||
| import { FormattedMessage } from 'react-intl'; | ||
| import { useForm } from 'react-hook-form'; | ||
| import { yupResolver } from '@hookform/resolvers/yup'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { AppState } from '../../../../redux/reducer.type'; | ||
| import { | ||
| fromStateEstimationParametersFormToParamValues, | ||
| fromStateEstimationParametersParamToFormValues, | ||
| StateEstimationParametersForm, | ||
| StateEstimationParametersForm as StateEstimationFormType, | ||
| stateEstimationParametersFormSchema, | ||
| TabValue, | ||
| } from './state-estimation-parameters-utils'; | ||
| import { StateEstimationGeneralParameters } from './state-estimation-general-parameters'; | ||
| import { StateEstimationWeightsParameters } from './state-estimation-weights-parameters'; | ||
| import { StateEstimationQualityParameters } from './state-estimation-quality-parameters'; | ||
| import { StateEstimationLoadboundsParameters } from './state-estimation-loadbounds-parameters'; | ||
| import { StateEstimationParametersForm } from './state-estimation-parameters-form'; | ||
| import { updateStateEstimationParameters } from '../../../../services/study/state-estimation'; | ||
| import { UseGetStateEstimationParametersProps } from './use-get-state-estimation-parameters'; | ||
| import { parametersStyles } from '../util/styles'; | ||
|
|
||
| export const StateEstimationParameters = ({ | ||
| useStateEstimationParameters, | ||
|
|
@@ -45,7 +37,6 @@ export const StateEstimationParameters = ({ | |
| }) => { | ||
| const studyUuid = useSelector((state: AppState) => state.studyUuid); | ||
| const [stateEstimationParams, setStateEstimationParams] = useStateEstimationParameters; | ||
| const [openResetConfirmation, setOpenResetConfirmation] = useState(false); | ||
|
|
||
| const initialFormValues = useMemo( | ||
| () => | ||
|
|
@@ -55,7 +46,7 @@ export const StateEstimationParameters = ({ | |
| [stateEstimationParams] | ||
| ); | ||
|
|
||
| const formMethods = useForm<StateEstimationParametersForm>({ | ||
| const formMethods = useForm<StateEstimationFormType>({ | ||
| defaultValues: initialFormValues, | ||
| resolver: yupResolver(stateEstimationParametersFormSchema), | ||
| }); | ||
|
|
@@ -98,19 +89,10 @@ export const StateEstimationParameters = ({ | |
| const clear = useCallback(() => { | ||
| resetStateEstimationParameters(); | ||
| onValidationError(); | ||
| setOpenResetConfirmation(false); | ||
| }, [resetStateEstimationParameters, onValidationError]); | ||
|
Comment on lines
89
to
92
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. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Reset no longer clears the form state.
Also applies to: 124-125 🤖 Prompt for AI Agents |
||
|
|
||
| const handleResetClick = useCallback(() => { | ||
| setOpenResetConfirmation(true); | ||
| }, []); | ||
|
|
||
| const handleCancelReset = useCallback(() => { | ||
| setOpenResetConfirmation(false); | ||
| }, []); | ||
|
|
||
| const onSubmit = useCallback( | ||
| (newParams: StateEstimationParametersForm) => { | ||
| (newParams: StateEstimationFormType) => { | ||
| updateStateEstimationParameters(studyUuid, fromStateEstimationParametersFormToParamValues(newParams)) | ||
| .then(() => { | ||
| setStateEstimationParams(fromStateEstimationParametersFormToParamValues(newParams)); | ||
|
|
@@ -135,92 +117,19 @@ export const StateEstimationParameters = ({ | |
|
|
||
| return ( | ||
| <CustomFormProvider validationSchema={stateEstimationParametersFormSchema} {...formMethods}> | ||
| <Grid | ||
| size={{ xl: [TabValue.GENERAL, TabValue.LOADBOUNDS].includes(tabValue) ? 6 : 12 }} | ||
| sx={{ height: '100%' }} | ||
| <ParameterLayout | ||
| title="StateEstimation" | ||
| parameterType={ElementType.STATE_ESTIMATION_PARAMETERS} | ||
| isLoading={stateEstimationParams !== null} | ||
| resetHandler={clear} | ||
| validateHandler={handleSubmit(onSubmit, onValidationError)} | ||
| > | ||
| <Stack sx={{ height: '100%' }} justifyContent="space-between"> | ||
| <Grid | ||
| container | ||
| key="stateEstimationParameters" | ||
| sx={mergeSx(parametersStyles.scrollableGrid, { | ||
| paddingTop: 0, | ||
| width: '100%', | ||
| display: 'unset', | ||
| })} | ||
| > | ||
| <Tabs | ||
| value={tabValue} | ||
| variant="scrollable" | ||
| onChange={handleTabChange} | ||
| TabIndicatorProps={{ | ||
| sx: getTabIndicatorStyle(tabIndexesWithError, tabValue), | ||
| }} | ||
| > | ||
| <Tab | ||
| label={<FormattedMessage id="StateEstimationParametersGeneralTabLabel" />} | ||
| value={TabValue.GENERAL} | ||
| sx={getTabStyle(tabIndexesWithError, TabValue.GENERAL)} | ||
| /> | ||
| <Tab | ||
| label={<FormattedMessage id="StateEstimationParametersWeightsTabLabel" />} | ||
| value={TabValue.WEIGHTS} | ||
| sx={getTabStyle(tabIndexesWithError, TabValue.WEIGHTS)} | ||
| /> | ||
| <Tab | ||
| label={<FormattedMessage id="StateEstimationParametersQualityTabLabel" />} | ||
| value={TabValue.QUALITY} | ||
| sx={getTabStyle(tabIndexesWithError, TabValue.QUALITY)} | ||
| /> | ||
| <Tab | ||
| label={<FormattedMessage id="StateEstimationParametersLoadboundsTabLabel" />} | ||
| value={TabValue.LOADBOUNDS} | ||
| sx={getTabStyle(tabIndexesWithError, TabValue.LOADBOUNDS)} | ||
| /> | ||
| </Tabs> | ||
| <Grid container> | ||
| <TabPanel value={tabValue} index={TabValue.GENERAL}> | ||
| <StateEstimationGeneralParameters /> | ||
| </TabPanel> | ||
| <TabPanel value={tabValue} index={TabValue.WEIGHTS}> | ||
| <StateEstimationWeightsParameters /> | ||
| </TabPanel> | ||
| <TabPanel value={tabValue} index={TabValue.QUALITY}> | ||
| <StateEstimationQualityParameters /> | ||
| </TabPanel> | ||
| <TabPanel value={tabValue} index={TabValue.LOADBOUNDS}> | ||
| <StateEstimationLoadboundsParameters /> | ||
| </TabPanel> | ||
| </Grid> | ||
| </Grid> | ||
|
|
||
| <Grid container> | ||
| <DialogActions | ||
| sx={mergeSx(parametersStyles.controlParametersItem, { | ||
| paddingTop: 4, | ||
| paddingBottom: 2, | ||
| paddingLeft: 0, | ||
| })} | ||
| > | ||
| <Button onClick={handleResetClick}> | ||
| <FormattedMessage id="resetToDefault" /> | ||
| </Button> | ||
| <SubmitButton variant="outlined" onClick={handleSubmit(onSubmit, onValidationError)} /> | ||
| </DialogActions> | ||
| </Grid> | ||
| </Stack> | ||
| </Grid> | ||
|
|
||
| {/* Reset Confirmation Dialog */} | ||
| {openResetConfirmation && ( | ||
| <PopupConfirmationDialog | ||
| message="resetParamsConfirmation" | ||
| validateButtonLabel="validate" | ||
| openConfirmationPopup={openResetConfirmation} | ||
| setOpenConfirmationPopup={handleCancelReset} | ||
| handlePopupConfirmation={clear} | ||
| <StateEstimationParametersForm | ||
| tabValue={tabValue} | ||
| handleTabChange={handleTabChange} | ||
| tabIndexesWithError={tabIndexesWithError} | ||
| /> | ||
| )} | ||
| </ParameterLayout> | ||
| </CustomFormProvider> | ||
| ); | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.