Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
inputValue: string;
};

export interface ElementSearchInputProps<T>
extends Pick<
AutocompleteProps<T, false, boolean, true>,
'sx' | 'size' | 'loadingText' | 'loading' | 'disableClearable' | 'getOptionDisabled' | 'PaperComponent'
> {
export interface ElementSearchInputProps<T> extends Pick<

Check warning on line 16 in src/components/elementSearch/elementSearchInput/ElementSearchInput.tsx

View workflow job for this annotation

GitHub Actions / build / build

Insert `⏎···`
AutocompleteProps<T, false, boolean, true>,

Check warning on line 17 in src/components/elementSearch/elementSearchInput/ElementSearchInput.tsx

View workflow job for this annotation

GitHub Actions / build / build

Insert `····`
'sx' | 'size' | 'loadingText' | 'loading' | 'disableClearable' | 'getOptionDisabled' | 'PaperComponent'

Check warning on line 18 in src/components/elementSearch/elementSearchInput/ElementSearchInput.tsx

View workflow job for this annotation

GitHub Actions / build / build

Insert `····`
> {

Check warning on line 19 in src/components/elementSearch/elementSearchInput/ElementSearchInput.tsx

View workflow job for this annotation

GitHub Actions / build / build

Insert `····`
searchTerm: string;
onSearchTermChange: (searchTerm: string) => void;
onSelectionChange: (selection: T) => void;
Expand Down
6 changes: 4 additions & 2 deletions src/components/inputs/SelectClearable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

type SelectOption = { id: string; label?: string };

export interface SelectClearableProps
extends Omit<AutocompleteProps<SelectOption, false, false, false>, 'value' | 'onChange' | 'renderInput'> {
export interface SelectClearableProps extends Omit<

Check warning on line 14 in src/components/inputs/SelectClearable.tsx

View workflow job for this annotation

GitHub Actions / build / build

Replace `·extends·Omit<⏎····AutocompleteProps<SelectOption,·false,·false,·false>,⏎····'value'·|·'onChange'·|·'renderInput'⏎` with `⏎····extends·Omit<AutocompleteProps<SelectOption,·false,·false,·false>,·'value'·|·'onChange'·|·'renderInput'`
AutocompleteProps<SelectOption, false, false, false>,
'value' | 'onChange' | 'renderInput'
> {
value: string | null;
onChange: (value: string | null) => void;
label?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

const isLastSelected = Boolean(
rowData?.length &&
gridApi?.api.getRowNode(rowData[rowData.length - 1][FieldConstants.AG_GRID_ROW_UUID])?.isSelected()
gridApi?.api.getRowNode(rowData[rowData.length - 1][FieldConstants.AG_GRID_ROW_UUID])?.isSelected()

Check warning on line 122 in src/components/inputs/reactHookForm/agGridTable/CustomAgGridTable.tsx

View workflow job for this annotation

GitHub Actions / build / build

Insert `····`
);

const noRowSelected = selectedRows.length === 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
import { useCustomFormContext } from '../provider';
import { Option } from '../../../../utils';

export interface AutocompleteInputProps
extends Omit<
AutocompleteProps<Option, boolean | undefined, boolean | undefined, boolean | undefined>,
// we already defined them in our custom Autocomplete
'value' | 'onChange' | 'renderInput'
> {
export interface AutocompleteInputProps extends Omit<

Check warning on line 15 in src/components/inputs/reactHookForm/autocompleteInputs/AutocompleteInput.tsx

View workflow job for this annotation

GitHub Actions / build / build

Insert `⏎···`
AutocompleteProps<Option, boolean | undefined, boolean | undefined, boolean | undefined>,

Check warning on line 16 in src/components/inputs/reactHookForm/autocompleteInputs/AutocompleteInput.tsx

View workflow job for this annotation

GitHub Actions / build / build

Insert `····`
// we already defined them in our custom Autocomplete

Check warning on line 17 in src/components/inputs/reactHookForm/autocompleteInputs/AutocompleteInput.tsx

View workflow job for this annotation

GitHub Actions / build / build

Replace `····` with `········`
'value' | 'onChange' | 'renderInput'

Check warning on line 18 in src/components/inputs/reactHookForm/autocompleteInputs/AutocompleteInput.tsx

View workflow job for this annotation

GitHub Actions / build / build

Insert `····`
> {
name: string;
options: Option[];
label?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import { useIntl } from 'react-intl';
import { AutocompleteInput, AutocompleteInputProps } from '../autocompleteInputs';
import { Option } from '../../../../utils';

export interface SelectInputProps
extends Omit<
AutocompleteInputProps,
'outputTransform' | 'inputTransform' | 'readOnly' | 'getOptionLabel' // already defined in SelectInput
> {
export interface SelectInputProps extends Omit<
AutocompleteInputProps,
'outputTransform' | 'inputTransform' | 'readOnly' | 'getOptionLabel' // already defined in SelectInput
> {
options: Option[];
onCheckNewValue?: (value: Option | null) => boolean; // if return false, do not apply the new value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ const styles = {
}),
} as const satisfies MuiStyles;

interface AutocompleteWithFavoritesProps<Value>
extends Omit<
AutocompleteProps<Value, boolean, false, boolean>,
'multiple' | 'renderInput' | 'renderGroup' | 'groupBy'
> {
interface AutocompleteWithFavoritesProps<Value> extends Omit<
AutocompleteProps<Value, boolean, false, boolean>,
'multiple' | 'renderInput' | 'renderGroup' | 'groupBy'
> {
favorites: Value[];
valid: boolean;
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/parameters/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
} from '../../../utils';
import { SPECIFIC_PARAMETERS } from './constant';
import yup from '../../../utils/yupConfig';
import { SHORT_CIRCUIT_IN_CALCULATION_CLUSTER_FILTERS } from '../short-circuit';

Check failure on line 16 in src/components/parameters/common/utils.ts

View workflow job for this annotation

GitHub Actions / build / build

Dependency cycle via "./short-circuit-parameters-inline:10=>./short-circuit-parameters-form:21=>./short-circuit-parameters-utils:16"

export const getSpecificParametersFormSchema = (specificParameters: SpecificParameterInfos[] | undefined) => {
const shape: { [key: string]: yup.AnySchema } = {};
Expand Down Expand Up @@ -97,7 +98,11 @@
): SpecificParametersValues => {
return Object.keys(formData[SPECIFIC_PARAMETERS]).reduce((acc: SpecificParametersValues, key: string) => {
if (_specificParametersValues[key].toString() !== formData[SPECIFIC_PARAMETERS][key].toString()) {
acc[key] = formData[SPECIFIC_PARAMETERS][key].toString();
if (key == SHORT_CIRCUIT_IN_CALCULATION_CLUSTER_FILTERS) {

Check failure on line 101 in src/components/parameters/common/utils.ts

View workflow job for this annotation

GitHub Actions / build / build

Expected '===' and instead saw '=='
acc[key] = formData[SPECIFIC_PARAMETERS][key];
} else {
acc[key] = formData[SPECIFIC_PARAMETERS][key].toString();
}
}
return acc;
}, {});
Expand Down
8 changes: 8 additions & 0 deletions src/components/parameters/short-circuit/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export const SHORT_CIRCUIT_VOLTAGE_RANGES = 'voltageRanges';

// specific parameters
export const SHORT_CIRCUIT_ONLY_STARTED_GENERATORS_IN_CALCULATION_CLUSTER = 'onlyStartedGeneratorsInCalculationCluster';
export const SHORT_CIRCUIT_ONLY_STARTED_GENERATORS_OUTSIDE_CALCULATION_CLUSTER =
'onlyStartedGeneratorsOutsideCalculationCluster';
export const SHORT_CIRCUIT_IN_CALCULATION_CLUSTER_FILTERS = 'inCalculationClusterFilters';
export const SHORT_CIRCUIT_MODEL_POWER_ELECTRONICS = 'modelPowerElectronics';
export const SHORT_CIRCUIT_POWER_ELECTRONICS_MATERIALS = 'powerElectronicsMaterials';

Expand Down Expand Up @@ -70,3 +73,8 @@ export const onlyStartedGeneratorsOptions = {
label: 'ShortCircuitStartedLabel',
},
};

export enum ShortCircuitTabValues {
'General' = 0,
'StudyArea' = 1,
}
72 changes: 2 additions & 70 deletions src/components/parameters/short-circuit/short-circuit-fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@ import { useEffect, useMemo, useState } from 'react';
import { Grid } from '@mui/material';
import { green, red } from '@mui/material/colors';
import { Lens } from '@mui/icons-material';
import { useFormContext, useWatch } from 'react-hook-form';
import { FormattedMessage } from 'react-intl';
import { useWatch } from 'react-hook-form';
import {
InitialVoltage,
intlInitialVoltageProfileMode,
intlPredefinedParametersOptions,
onlyStartedGeneratorsOptions,
PredefinedParameters,
SHORT_CIRCUIT_INITIAL_VOLTAGE_PROFILE_MODE,
SHORT_CIRCUIT_ONLY_STARTED_GENERATORS_IN_CALCULATION_CLUSTER,
SHORT_CIRCUIT_POWER_ELECTRONICS_MATERIALS,
SHORT_CIRCUIT_MODEL_POWER_ELECTRONICS,
SHORT_CIRCUIT_PREDEFINED_PARAMS,
SHORT_CIRCUIT_WITH_FEEDER_RESULT,
SHORT_CIRCUIT_WITH_LOADS,
Expand All @@ -34,8 +30,6 @@ import GridSection from '../../grid/grid-section';
import { CheckboxInput, FieldLabel, MuiSelectInput, RadioInput, SwitchInput } from '../../inputs';
import type { SxStyle } from '../../../utils/styles';
import { COMMON_PARAMETERS, SPECIFIC_PARAMETERS } from '../common';
import { ShortCircuitIccMaterialTable } from './short-circuit-icc-material-table';
import { COLUMNS_DEFINITIONS_ICC_MATERIALS } from './short-circuit-icc-material-table-columns-definition';

export interface ShortCircuitFieldsProps {
resetAll: (predefinedParams: PredefinedParameters) => void;
Expand All @@ -47,13 +41,7 @@ export enum Status {
ERROR = 'ERROR',
}

const columnsDef = COLUMNS_DEFINITIONS_ICC_MATERIALS.map((col) => ({
...col,
label: <FormattedMessage id={col.label as string} />,
tooltip: <FormattedMessage id={col.tooltip as string} />,
}));

export function ShortCircuitFields({ resetAll, isDeveloperMode = true }: Readonly<ShortCircuitFieldsProps>) {
export function ShortCircuitFields({ resetAll }: Readonly<ShortCircuitFieldsProps>) {
const [status, setStatus] = useState(Status.SUCCESS);
const watchInitialVoltageProfileMode = useWatch({
name: `${COMMON_PARAMETERS}.${SHORT_CIRCUIT_INITIAL_VOLTAGE_PROFILE_MODE}`,
Expand All @@ -73,14 +61,7 @@ export function ShortCircuitFields({ resetAll, isDeveloperMode = true }: Readonl
const watchNeutralPosition = useWatch({
name: `${COMMON_PARAMETERS}.${SHORT_CIRCUIT_WITH_NEUTRAL_POSITION}`,
});
const watchSpecificParameters = useWatch({
name: `${SPECIFIC_PARAMETERS}`,
});

const isThereSpecificParameters = useMemo(
() => Object.keys(watchSpecificParameters).length > 0 && watchSpecificParameters.constructor === Object,
[watchSpecificParameters]
);
// Courcirc specific parameters
const watchOnlyStartedGeneratorsInCalculationCluster = useWatch({
name: `${SPECIFIC_PARAMETERS}.${SHORT_CIRCUIT_ONLY_STARTED_GENERATORS_IN_CALCULATION_CLUSTER}`,
Expand Down Expand Up @@ -139,8 +120,6 @@ export function ShortCircuitFields({ resetAll, isDeveloperMode = true }: Readonl
resetAll(newPredefinedParameters);
};

const { setValue } = useFormContext();

// fields definition
const feederResult = (
<Grid container alignItems="center" spacing={2} direction="row">
Expand Down Expand Up @@ -187,32 +166,6 @@ export function ShortCircuitFields({ resetAll, isDeveloperMode = true }: Readonl
/>
);

// Forced to specificly manage this onlyStartedGeneratorsInCalculationCluster parameter because it's a boolean type, but we want to use a radio button here.
const onlyStartedGeneratorsInCalculationCluster = (
<RadioInput
name={`${SPECIFIC_PARAMETERS}.${SHORT_CIRCUIT_ONLY_STARTED_GENERATORS_IN_CALCULATION_CLUSTER}`}
options={Object.values(onlyStartedGeneratorsOptions)}
formProps={{
onChange: (_event, value) => {
setValue(
`${SPECIFIC_PARAMETERS}.${SHORT_CIRCUIT_ONLY_STARTED_GENERATORS_IN_CALCULATION_CLUSTER}`,
value === 'true',
{
shouldDirty: true,
}
);
},
}}
/>
);

const modelPowerElectronics = (
<CheckboxInput
name={`${SPECIFIC_PARAMETERS}.${SHORT_CIRCUIT_MODEL_POWER_ELECTRONICS}`}
label="ShortCircuitModelPowerElectronics"
/>
);

useEffect(() => {
// To show the right status, we need to check the predefinedParams and initial voltage profile mode values.
// Show success only if ICC_MAX_WITH_NOMINAL_VOLTAGE_MAP is associated with NOMINAL, or ICC_MAX_WITH_CEI909 with CEI909, or ICC_MIN_WITH_NOMINAL_VOLTAGE_MAP with NOMINAL
Expand Down Expand Up @@ -270,27 +223,6 @@ export function ShortCircuitFields({ resetAll, isDeveloperMode = true }: Readonl
<GridItem size={12}>{initialVoltageProfileModeField}</GridItem>
</Grid>
<VoltageTable voltageProfileMode={watchInitialVoltageProfileMode} />
{isThereSpecificParameters && (
<>
<GridSection title="ShortCircuitStartedGeneratorsMode" heading={4} />
<Grid container>
<GridItem size={12}>{onlyStartedGeneratorsInCalculationCluster}</GridItem>
</Grid>
{isDeveloperMode && (
<>
<GridSection title="ShortCircuitPowerElectronicsSection" heading={4} />
<Grid container>
<GridItem size={12}>{modelPowerElectronics}</GridItem>
</Grid>
<ShortCircuitIccMaterialTable
formName={`${SPECIFIC_PARAMETERS}.${SHORT_CIRCUIT_POWER_ELECTRONICS_MATERIALS}`}
tableHeight={300}
columnsDefinition={columnsDef}
/>
</>
)}
</>
)}
</Grid>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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 { Box, Grid } from '@mui/material';
import { ShortCircuitParametersTabValues } from './short-circuit-parameters-utils';

Check failure on line 9 in src/components/parameters/short-circuit/short-circuit-parameters-content.tsx

View workflow job for this annotation

GitHub Actions / build / build

Dependency cycle via "../common/utils:30=>../short-circuit:16=>./short-circuit-parameters-inline:10=>./short-circuit-parameters-form:21"
import { parametersStyles } from '../parameters-style';
import { TabPanel } from '../common/parameters';
import type { MuiStyles } from '../../../utils/styles';
import { PredefinedParameters } from './constants';
import { ShortCircuitFields } from './short-circuit-fields';
import { ShortCircuitSpecificFields } from './short-circuit-specific-fields';

type ShortCircuitParametersContentProps = {
isDeveloperMode: boolean;
resetAll: (predefinedParams: PredefinedParameters) => void;
selectedTab: ShortCircuitParametersTabValues;
};

const styles = {
container: {
...parametersStyles.scrollableGrid,
maxHeight: '100%',
},
maxWidth: {
width: '100%',
},
wrapper: {
flexGrow: 1,
overflow: 'auto',
paddingLeft: 1,
},
} as const satisfies MuiStyles;

function ShortCircuitParametersContent({
isDeveloperMode,
resetAll,
selectedTab,
}: Readonly<ShortCircuitParametersContentProps>) {
return (
<Box sx={styles.wrapper}>
<Grid container sx={styles.container}>
<Grid item sx={styles.maxWidth}>
<TabPanel value={selectedTab} index={ShortCircuitParametersTabValues.GENERAL}>
<ShortCircuitFields resetAll={resetAll} isDeveloperMode={isDeveloperMode} />
</TabPanel>
<TabPanel value={selectedTab} index={ShortCircuitParametersTabValues.STUDY_AREA}>
<ShortCircuitSpecificFields isDeveloperMode={isDeveloperMode} />
</TabPanel>
</Grid>
</Grid>
</Box>
);
}

export default ShortCircuitParametersContent;
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

import { Box, Grid, LinearProgress } from '@mui/material';
import { Box, Grid, LinearProgress, Tab, Tabs } from '@mui/material';
import { ReactNode } from 'react';
import { FormattedMessage } from 'react-intl';
import { CustomFormProvider } from '../../inputs';
import { parametersStyles } from '../parameters-style';
import { ShortCircuitFields } from './short-circuit-fields';
import { getTabStyle, parametersStyles } from '../parameters-style';
import { UseShortCircuitParametersFormReturn } from './use-short-circuit-parameters-form';

Check failure on line 13 in src/components/parameters/short-circuit/short-circuit-parameters-form.tsx

View workflow job for this annotation

GitHub Actions / build / build

Dependency cycle via "./short-circuit-parameters-utils:42=>../common/utils:30=>../short-circuit:16=>./short-circuit-parameters-inline:10"
import { MuiStyles } from '../../../utils';
import ShortCircuitParametersContent from './short-circuit-parameters-content';
import { ShortCircuitParametersTabValues } from './short-circuit-parameters-utils';

const styles = {
shortCircuitParameters: {
height: '100%',
display: 'flex',
position: 'relative',
flexDirection: 'column',
},
} as const satisfies MuiStyles;

interface ShortCircuitParametersFormProps {
shortCircuitMethods: UseShortCircuitParametersFormReturn;
Expand All @@ -25,25 +37,38 @@
renderActions,
isDeveloperMode,
}: Readonly<ShortCircuitParametersFormProps>) {
const { formMethods, formSchema, paramsLoaded, resetAll } = shortCircuitMethods;

const { formMethods, formSchema, paramsLoaded, resetAll, selectedTab, handleTabChange, tabIndexesWithError } =
shortCircuitMethods;
return (
<CustomFormProvider validationSchema={formSchema} {...formMethods} removeOptional>
<Box
sx={{
height: '100%',
display: 'flex',
position: 'relative',
flexDirection: 'column',
}}
>
<Box sx={styles.shortCircuitParameters}>
<Grid item container direction="column">
{renderTitleFields?.()}
</Grid>
{paramsLoaded ? (
<Grid sx={parametersStyles.scrollableGrid}>
<ShortCircuitFields isDeveloperMode={isDeveloperMode} resetAll={resetAll} />
</Grid>
<>
<Grid item sx={{ width: '100%' }}>
<Tabs value={selectedTab} onChange={handleTabChange}>
<Tab
label={<FormattedMessage id={ShortCircuitParametersTabValues.GENERAL} />}
value={ShortCircuitParametersTabValues.GENERAL}
sx={getTabStyle(tabIndexesWithError, ShortCircuitParametersTabValues.GENERAL)}
/>
<Tab
label={<FormattedMessage id={ShortCircuitParametersTabValues.STUDY_AREA} />}
value={ShortCircuitParametersTabValues.STUDY_AREA}
sx={getTabStyle(tabIndexesWithError, ShortCircuitParametersTabValues.STUDY_AREA)}
/>
</Tabs>
</Grid>
<Grid sx={parametersStyles.scrollableGrid}>
<ShortCircuitParametersContent
isDeveloperMode={isDeveloperMode}
resetAll={resetAll}
selectedTab={selectedTab}
/>
</Grid>
</>
) : (
<LinearProgress />
)}
Expand Down
Loading
Loading