Skip to content

Commit b2a013e

Browse files
add limits in lines catalog (#3074)
Signed-off-by: Etienne LESOT <[email protected]> Co-authored-by: Rehili Ghazwa <[email protected]>
1 parent ec46074 commit b2a013e

15 files changed

+792
-306
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
import { AgGridReact } from 'ag-grid-react';
8+
import { CATEGORIES_TABS, LineTypeInfo } from './line-catalog.type';
9+
import { ColDef } from 'ag-grid-community';
10+
import { RefObject, useMemo } from 'react';
11+
import { CustomAGGrid } from '@gridsuite/commons-ui';
12+
import { AGGRID_LOCALES } from '../../../translations/not-intl/aggrid-locales';
13+
import { suppressEventsToPreventEditMode } from '../commons/utils';
14+
15+
const defaultColDef: ColDef = {
16+
filter: true,
17+
sortable: true,
18+
resizable: false,
19+
lockPinned: true,
20+
wrapHeaderText: true,
21+
autoHeaderHeight: true,
22+
suppressKeyboardEvent: suppressEventsToPreventEditMode,
23+
};
24+
25+
interface LimitsCustomAgGridProps {
26+
gridRef: RefObject<AgGridReact>;
27+
currentTab: number;
28+
aerialRowData: LineTypeInfo[];
29+
undergroundRowData: LineTypeInfo[];
30+
aerialColumnDefs: ColDef[];
31+
undergroundColumnDefs: ColDef[];
32+
onSelectionChanged: () => void;
33+
onGridReady: () => void;
34+
}
35+
36+
export default function LimitCustomAgGrid({
37+
gridRef,
38+
currentTab,
39+
aerialRowData,
40+
undergroundRowData,
41+
aerialColumnDefs,
42+
undergroundColumnDefs,
43+
onSelectionChanged,
44+
onGridReady,
45+
}: Readonly<LimitsCustomAgGridProps>) {
46+
const { rowData, columnDefs } = useMemo(() => {
47+
if (currentTab === CATEGORIES_TABS.AERIAL.id) {
48+
return { rowData: aerialRowData, columnDefs: aerialColumnDefs };
49+
}
50+
return { rowData: undergroundRowData, columnDefs: undergroundColumnDefs };
51+
}, [currentTab, aerialRowData, undergroundRowData, aerialColumnDefs, undergroundColumnDefs]);
52+
53+
return (
54+
<CustomAGGrid
55+
ref={gridRef}
56+
rowData={rowData}
57+
defaultColDef={defaultColDef}
58+
columnDefs={columnDefs}
59+
rowSelection="single"
60+
onSelectionChanged={onSelectionChanged}
61+
onGridReady={onGridReady}
62+
overrideLocales={AGGRID_LOCALES}
63+
/>
64+
);
65+
}

src/components/dialogs/line-types-catalog/line-catalog.type.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export type LineTypeInfo = {
2525
linearResistance: number;
2626
linearReactance: number;
2727
linearCapacity: number;
28+
limitsForLineType: CurrentLimitsInfo[];
29+
shapeFactors: number[];
2830
} & (AerialLineTypeInfo | UndergroundLineTypeInfo);
2931

3032
// Interface with Line creation/modification
@@ -33,3 +35,18 @@ export type ComputedLineCharacteristics = {
3335
totalReactance: number;
3436
totalSusceptance: number;
3537
};
38+
39+
export type CurrentLimitsInfo = {
40+
limitSetName: string;
41+
permanentLimit: number;
42+
temporaryLimitValue: number;
43+
temporaryLimitAcceptableDuration: number;
44+
temporaryLimitName: string;
45+
area: string;
46+
temperature: string;
47+
};
48+
49+
export const CATEGORIES_TABS = {
50+
AERIAL: { id: 0, name: 'AERIAL' },
51+
UNDERGROUND: { id: 1, name: 'UNDERGROUND' },
52+
} as const;

src/components/dialogs/line-types-catalog/line-type-segment-creation.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { FunctionComponent, useCallback, useEffect } from 'react';
8+
import { useCallback, useEffect } from 'react';
99
import { useWatch } from 'react-hook-form';
1010
import { KilometerAdornment } from '../dialog-utils';
1111
import EditIcon from '@mui/icons-material/Edit';
1212
import { FloatInput } from '@gridsuite/commons-ui';
1313
import { IconButton } from '@mui/material';
1414
import {
1515
SEGMENT_DISTANCE_VALUE,
16-
SEGMENT_TYPE_VALUE,
17-
SEGMENT_RESISTANCE,
1816
SEGMENT_REACTANCE,
17+
SEGMENT_RESISTANCE,
1918
SEGMENT_SUSCEPTANCE,
19+
SEGMENT_TYPE_VALUE,
2020
} from '../../utils/field-constants';
2121
import { ReadOnlyInput } from '../../utils/rhf-inputs/read-only/read-only-input';
2222
import { ButtonReadOnlyInput } from '../../utils/rhf-inputs/read-only/button-read-only-input';
@@ -29,12 +29,12 @@ export interface LineTypeSegmentCreationProps {
2929
onSegmentDistanceChange: (index: number) => void;
3030
}
3131

32-
const LineTypeSegmentCreation: FunctionComponent<LineTypeSegmentCreationProps> = ({
32+
export default function LineTypeSegmentCreation({
3333
name,
3434
index,
3535
onEditButtonClick,
3636
onSegmentDistanceChange,
37-
}) => {
37+
}: Readonly<LineTypeSegmentCreationProps>) {
3838
const watchDistance = useWatch({
3939
name: `${name}.${index}.${SEGMENT_DISTANCE_VALUE}`,
4040
});
@@ -79,6 +79,4 @@ const LineTypeSegmentCreation: FunctionComponent<LineTypeSegmentCreationProps> =
7979
<GridItem size={2}>{segmentSusceptanceField}</GridItem>
8080
</>
8181
);
82-
};
83-
84-
export default LineTypeSegmentCreation;
82+
}

src/components/dialogs/line-types-catalog/line-type-segment-dialog.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,42 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { FunctionComponent, useCallback } from 'react';
9-
import { SEGMENTS, TOTAL_REACTANCE, TOTAL_RESISTANCE, TOTAL_SUSCEPTANCE } from '../../utils/field-constants';
8+
import { useCallback } from 'react';
109
import { yupResolver } from '@hookform/resolvers/yup';
1110
import yup from 'components/utils/yup-config';
1211
import { ModificationDialog } from '../commons/modificationDialog';
1312
import { useForm } from 'react-hook-form';
1413
import { LineTypeSegmentForm } from './line-type-segment-form';
1514
import { CustomFormProvider } from '@gridsuite/commons-ui';
1615
import { ComputedLineCharacteristics } from './line-catalog.type';
17-
import { emptyLineSegment, SegmentSchema } from './segment-utils';
16+
import { SegmentSchema } from './segment-utils';
17+
import {
18+
FINAL_CURRENT_LIMITS,
19+
SEGMENTS,
20+
TOTAL_REACTANCE,
21+
TOTAL_RESISTANCE,
22+
TOTAL_SUSCEPTANCE,
23+
} from '../../utils/field-constants';
24+
import { InferType } from 'yup';
25+
import { DeepNullable } from '../../utils/ts-utils';
1826

1927
const LineTypeSegmentSchema = yup
2028
.object()
2129
.shape({
2230
[TOTAL_RESISTANCE]: yup.number().required(),
2331
[TOTAL_REACTANCE]: yup.number().required(),
2432
[TOTAL_SUSCEPTANCE]: yup.number().required(),
33+
[FINAL_CURRENT_LIMITS]: yup.array(),
2534
[SEGMENTS]: yup.array().of(SegmentSchema).required().min(1, 'AtLeastOneSegmentNeeded'),
2635
})
2736
.required();
2837

29-
export type LineTypeSegmentFormData = yup.InferType<typeof LineTypeSegmentSchema>;
30-
31-
const emptyFormData: LineTypeSegmentFormData = {
38+
const emptyFormData = {
3239
[TOTAL_RESISTANCE]: 0.0,
3340
[TOTAL_REACTANCE]: 0.0,
3441
[TOTAL_SUSCEPTANCE]: 0.0,
35-
[SEGMENTS]: [emptyLineSegment],
42+
[FINAL_CURRENT_LIMITS]: [],
43+
[SEGMENTS]: [],
3644
};
3745

3846
export interface LineTypeSegmentDialogProps {
@@ -41,10 +49,12 @@ export interface LineTypeSegmentDialogProps {
4149
onSave: (data: ComputedLineCharacteristics) => void;
4250
}
4351

44-
const LineTypeSegmentDialog: FunctionComponent<LineTypeSegmentDialogProps> = ({ open, onSave, onClose }) => {
45-
const formMethods = useForm<LineTypeSegmentFormData>({
52+
export type LineTypeSegmentDialogSchemaForm = InferType<typeof LineTypeSegmentSchema>;
53+
54+
export default function LineTypeSegmentDialog({ open, onSave, onClose }: Readonly<LineTypeSegmentDialogProps>) {
55+
const formMethods = useForm<DeepNullable<LineTypeSegmentDialogSchemaForm>>({
4656
defaultValues: emptyFormData,
47-
resolver: yupResolver<LineTypeSegmentFormData>(LineTypeSegmentSchema),
57+
resolver: yupResolver<DeepNullable<LineTypeSegmentDialogSchemaForm>>(LineTypeSegmentSchema),
4858
});
4959

5060
const { reset } = formMethods;
@@ -53,9 +63,6 @@ const LineTypeSegmentDialog: FunctionComponent<LineTypeSegmentDialogProps> = ({
5363
reset(emptyFormData);
5464
}, [reset]);
5565

56-
/**
57-
* RENDER
58-
*/
5966
return (
6067
<CustomFormProvider validationSchema={LineTypeSegmentSchema} {...formMethods}>
6168
<ModificationDialog
@@ -71,6 +78,4 @@ const LineTypeSegmentDialog: FunctionComponent<LineTypeSegmentDialogProps> = ({
7178
</ModificationDialog>
7279
</CustomFormProvider>
7380
);
74-
};
75-
76-
export default LineTypeSegmentDialog;
81+
}

0 commit comments

Comments
 (0)