Skip to content

Commit 16e12fc

Browse files
committed
try to improve fetch limitInfo
Signed-off-by: basseche <bassel.el-cheikh_externe@rte-france.com>
1 parent 77e3d2e commit 16e12fc

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

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

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,30 @@ export const LineTypeSegmentForm = ({ editData }: Readonly<LineTypeSegmentFormPr
181181
);
182182

183183
const updateSegmentsLimits = useCallback(
184-
(id: string, area: string | null, temperature: string | null, shapeFactor: number | null, distance: number) => {
185-
getLineTypeWithLimits(id, area, temperature, shapeFactor).then((lineTypeWithLimits) => {
184+
(segment: LineSegmentInfos) => {
185+
getLineTypeWithLimits(
186+
segment[SEGMENT_TYPE_ID],
187+
segment[AREA],
188+
segment[TEMPERATURE],
189+
segment[SHAPE_FACTOR]
190+
).then((lineTypeWithLimits) => {
186191
const newResistance = roundToDefaultPrecision(
187-
calculateResistance(distance, lineTypeWithLimits?.linearResistance ?? 0)
192+
calculateResistance(segment[SEGMENT_DISTANCE_VALUE], lineTypeWithLimits?.linearResistance ?? 0)
188193
);
189194
const newReactance = roundToDefaultPrecision(
190-
calculateReactance(distance, lineTypeWithLimits?.linearReactance ?? 0)
195+
calculateReactance(segment[SEGMENT_DISTANCE_VALUE], lineTypeWithLimits?.linearReactance ?? 0)
191196
);
192197
const newSusceptance = roundToDefaultPrecision(
193-
calculateSusceptance(distance, lineTypeWithLimits?.linearCapacity ?? 0)
198+
calculateSusceptance(segment[SEGMENT_DISTANCE_VALUE], lineTypeWithLimits?.linearCapacity ?? 0)
194199
);
195200
arrayRef?.current?.appendItem({
196201
...emptyLineSegment,
197-
[SEGMENT_TYPE_ID]: id,
202+
[SEGMENT_TYPE_ID]: segment[SEGMENT_TYPE_ID],
198203
[SEGMENT_TYPE_VALUE]: lineTypeWithLimits?.type ?? '',
199-
[AREA]: area,
200-
[TEMPERATURE]: temperature,
201-
[SHAPE_FACTOR]: shapeFactor,
202-
[SEGMENT_DISTANCE_VALUE]: distance,
204+
[AREA]: segment[AREA],
205+
[TEMPERATURE]: segment[TEMPERATURE],
206+
[SHAPE_FACTOR]: segment[SHAPE_FACTOR],
207+
[SEGMENT_DISTANCE_VALUE]: segment[SEGMENT_DISTANCE_VALUE],
203208
[SEGMENT_RESISTANCE]: newResistance,
204209
[SEGMENT_REACTANCE]: newReactance,
205210
[SEGMENT_SUSCEPTANCE]: newSusceptance,
@@ -213,21 +218,13 @@ export const LineTypeSegmentForm = ({ editData }: Readonly<LineTypeSegmentFormPr
213218
);
214219

215220
const loadEditDataSegments = useCallback(
216-
(catalog: LineTypeInfo[]) => {
217-
if (!editData || catalog.length === 0) {
218-
return;
219-
}
220-
arrayRef.current?.replaceItems([]);
221-
for (const [index] of editData?.entries() || []) {
222-
const distance = editData[index][SEGMENT_DISTANCE_VALUE];
223-
updateSegmentsLimits(
224-
editData[index][SEGMENT_TYPE_ID],
225-
editData[index][AREA],
226-
editData[index][TEMPERATURE],
227-
editData[index][SHAPE_FACTOR],
228-
distance
229-
);
230-
}
221+
async (catalog: LineTypeInfo[]) => {
222+
if (!editData || editData.length === 0 || catalog.length === 0) return;
223+
224+
const promises = editData.map((segment) => {
225+
return updateSegmentsLimits(segment);
226+
});
227+
await Promise.all(promises);
231228
},
232229
[editData, updateSegmentsLimits]
233230
);

0 commit comments

Comments
 (0)