Skip to content

Commit 9c6ea34

Browse files
authored
Move sensi parameters to commons ui (#798)
Signed-off-by: Hugo Marcellin <[email protected]>
1 parent 5a8f4be commit 9c6ea34

38 files changed

+2705
-51
lines changed

src/components/inputs/reactHookForm/provider/CustomFormProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { createContext, PropsWithChildren, useMemo } from 'react';
99
import { type FieldValues, FormProvider, type UseFormReturn } from 'react-hook-form';
1010
import * as yup from 'yup';
1111
import { type ObjectSchema } from 'yup';
12-
import { getSystemLanguage } from '../../../../hooks';
12+
import { getSystemLanguage } from '../../../../hooks/useLocalizedCountries';
1313

1414
type CustomFormContextProps<TFieldValues extends FieldValues = FieldValues> = {
1515
removeOptional?: boolean;

src/components/inputs/reactHookForm/provider/useCustomFormContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { useFormContext } from 'react-hook-form';
99
import { useContext } from 'react';
10-
import { CustomFormContext, MergedFormContextProps } from './CustomFormProvider';
10+
import { CustomFormContext, type MergedFormContextProps } from './CustomFormProvider';
1111

1212
// TODO found how to manage generic type
1313
export const useCustomFormContext = (): MergedFormContextProps => {

src/components/inputs/reactHookForm/text/DescriptionField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { FormattedMessage } from 'react-intl';
1010
import { Box, Button, SxProps, Theme } from '@mui/material';
1111
import { ControlPoint as AddIcon, Delete as DeleteIcon } from '@mui/icons-material';
1212
import { useFormContext } from 'react-hook-form';
13-
import { FieldConstants } from '../../../../utils';
13+
import { FieldConstants } from '../../../../utils/constants/fieldConstants';
1414
import { ExpandingTextField } from './ExpandingTextField';
1515

1616
export interface DescriptionFieldProps {

src/components/parameters/common/limitreductions/columns-definitions.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
PARAM_SA_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD,
1717
PARAM_SA_PROVIDER,
1818
} from '../constant';
19-
import { getDialogParametersFormSchema } from '../parameters-edition-dialog-props';
19+
import { getNameElementEditorSchema } from '../name-element-editor';
2020

2121
export const LIMIT_REDUCTIONS_FORM = 'limitReductionsForm';
2222
export const VOLTAGE_LEVELS_FORM = 'voltageLevelsForm';
@@ -68,14 +68,14 @@ export const TAB_INFO = [
6868
{ label: TabValues[TabValues.LimitReductions], developerModeOnly: false },
6969
];
7070

71-
export interface IColumnsDef {
71+
export interface LimitReductionIColumnsDef {
7272
label: string;
7373
dataKey: string;
7474
tooltip: string;
7575
width?: string;
7676
}
7777

78-
export const COLUMNS_DEFINITIONS_LIMIT_REDUCTIONS: IColumnsDef[] = [
78+
export const COLUMNS_DEFINITIONS_LIMIT_REDUCTIONS: LimitReductionIColumnsDef[] = [
7979
{
8080
label: 'voltageRange',
8181
dataKey: VOLTAGE_LEVELS_FORM,
@@ -148,10 +148,12 @@ export const getSAParametersFromSchema = (name: string | null, limitReductions?:
148148
[PARAM_SA_HIGH_VOLTAGE_ABSOLUTE_THRESHOLD]: yup.number().required(),
149149
});
150150

151-
return yup.object().shape({
152-
...getDialogParametersFormSchema(name),
153-
...providerSchema.fields,
154-
...limitReductionsSchema.fields,
155-
...thresholdsSchema.fields,
156-
});
151+
return yup
152+
.object()
153+
.shape({
154+
...providerSchema.fields,
155+
...limitReductionsSchema.fields,
156+
...thresholdsSchema.fields,
157+
})
158+
.concat(getNameElementEditorSchema(name));
157159
};

src/components/parameters/common/limitreductions/limit-reduction-table-cell.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
*/
77

88
import { TableCell } from '@mui/material';
9-
import { IColumnsDef, LIMIT_REDUCTIONS_FORM, VOLTAGE_LEVELS_FORM } from './columns-definitions';
9+
import { LimitReductionIColumnsDef, LIMIT_REDUCTIONS_FORM, VOLTAGE_LEVELS_FORM } from './columns-definitions';
1010
import { FloatInput, RawReadOnlyInput } from '../../../inputs';
1111

12-
export function LimitReductionTableCell({ rowIndex, column }: Readonly<{ rowIndex: number; column: IColumnsDef }>) {
12+
export function LimitReductionTableCell({
13+
rowIndex,
14+
column,
15+
}: Readonly<{
16+
rowIndex: number;
17+
column: LimitReductionIColumnsDef;
18+
}>) {
1319
return (
1420
<TableCell sx={{ fontWeight: 'bold' }}>
1521
{column.dataKey === VOLTAGE_LEVELS_FORM ? (

src/components/parameters/common/limitreductions/limit-reduction-table-row.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
import { TableRow } from '@mui/material';
99
import { LimitReductionTableCell } from './limit-reduction-table-cell';
10-
import { IColumnsDef } from './columns-definitions';
10+
import { LimitReductionIColumnsDef } from './columns-definitions';
1111

1212
interface TableRowComponentProps {
13-
columnsDefinition: IColumnsDef[];
13+
columnsDefinition: LimitReductionIColumnsDef[];
1414
index: number;
1515
}
1616

1717
export function LimitReductionTableRow({ columnsDefinition, index }: Readonly<TableRowComponentProps>) {
1818
return (
1919
<TableRow>
20-
{columnsDefinition.map((column: IColumnsDef) => (
20+
{columnsDefinition.map((column: LimitReductionIColumnsDef) => (
2121
<LimitReductionTableCell key={`${column.dataKey}`} rowIndex={index} column={column} />
2222
))}
2323
</TableRow>

src/components/parameters/common/name-element-editor/name-element-editor-form.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import { UUID } from 'crypto';
99
import { Grid } from '@mui/material';
10-
import { DescriptionField, UniqueNameInput } from '../../../inputs';
10+
import { DescriptionField } from '../../../inputs/reactHookForm/text/DescriptionField';
11+
import { UniqueNameInput } from '../../../inputs/reactHookForm/text/UniqueNameInput';
1112
import { ElementType, FieldConstants } from '../../../../utils';
1213
import { filterStyles } from '../../../filter/HeaderFilterForm';
1314

@@ -23,7 +24,7 @@ export function NameElementEditorForm({
2324
elementType,
2425
}: Readonly<NameElementEditorFormProps>) {
2526
return (
26-
<Grid item sx={{ height: '100%' }}>
27+
<Grid item>
2728
<Grid container spacing={2} direction="column" marginBottom="8px">
2829
<Grid item>
2930
<UniqueNameInput

src/components/parameters/common/name-element-editor/name-element-editor-utils.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ export function getNameElementEditorEmptyFormData(
1919

2020
export function getNameElementEditorSchema(initialElementName: string | null) {
2121
return yup.object().shape({
22-
[NAME]: yup.string().when('nameRequiredWhenInitialNameIsSet', {
23-
is: () => initialElementName !== null,
24-
then: () => yup.string().required(),
25-
otherwise: () => yup.string(),
26-
}),
27-
[DESCRIPTION]: yup.string(),
22+
[NAME]: yup
23+
.string()
24+
.nullable()
25+
.when('nameRequiredWhenInitialNameIsSet', {
26+
is: () => initialElementName !== null,
27+
then: () => yup.string().required(),
28+
otherwise: () => yup.string(),
29+
}),
30+
[DESCRIPTION]: yup.string().nullable(),
2831
});
2932
}

src/components/parameters/common/parameters-edition-dialog-props.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import { UUID } from 'crypto';
99
import { User } from 'oidc-client';
10-
import yup from '../../../utils/yupConfig';
11-
import { DESCRIPTION, NAME } from '../../inputs/reactHookForm/constants';
1210

1311
export interface ParametersEditionDialogProps {
1412
id: UUID;
@@ -22,12 +20,3 @@ export interface ParametersEditionDialogProps {
2220
user: User | null;
2321
enableDeveloperMode?: boolean;
2422
}
25-
26-
export const getDialogParametersFormSchema = (name: string | null) => {
27-
const shape: { [key: string]: yup.AnySchema } = {};
28-
if (name) {
29-
shape[NAME] = yup.string().required();
30-
shape[DESCRIPTION] = yup.string();
31-
}
32-
return shape;
33-
};

src/components/parameters/common/voltage-level-table/custom-voltage-level-table-cell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77
import { TableCell } from '@mui/material';
8-
import { IColumnsDef } from '../limitreductions/columns-definitions';
8+
import { LimitReductionIColumnsDef } from '../limitreductions/columns-definitions';
99
import { VOLTAGE_LEVEL } from '../constant';
1010
import { FloatInput, RawReadOnlyInput } from '../../../inputs';
1111

@@ -16,7 +16,7 @@ export function CustomVoltageLevelTableCell({
1616
}: Readonly<{
1717
formName: string;
1818
rowIndex: number;
19-
column: IColumnsDef;
19+
column: LimitReductionIColumnsDef;
2020
}>) {
2121
return (
2222
<TableCell sx={{ fontWeight: 'bold' }}>

0 commit comments

Comments
 (0)