Skip to content

Commit cee118b

Browse files
authored
make limits parameter optional (#854)
* make limits parameter optional * remove optional argument * fix
1 parent f36161a commit cee118b

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function LimitReductionTableCell({
2424
column: LimitReductionIColumnsDef;
2525
limits: ILimitReductionsByVoltageLevel[];
2626
}>) {
27-
return column.dataKey === VOLTAGE_LEVELS_FORM ? (
27+
return column.dataKey === VOLTAGE_LEVELS_FORM && limits[rowIndex] ? (
2828
<Tooltip
2929
title={
3030
<FormattedMessage
@@ -42,7 +42,11 @@ export function LimitReductionTableCell({
4242
</Tooltip>
4343
) : (
4444
<TableCell sx={{ fontWeight: 'bold' }}>
45-
<FloatInput name={`${LIMIT_REDUCTIONS_FORM}[${rowIndex}].${column.dataKey}`} />
45+
{column.dataKey === VOLTAGE_LEVELS_FORM ? (
46+
<RawReadOnlyInput name={`${LIMIT_REDUCTIONS_FORM}[${rowIndex}].${column.dataKey}`} />
47+
) : (
48+
<FloatInput name={`${LIMIT_REDUCTIONS_FORM}[${rowIndex}].${column.dataKey}`} />
49+
)}
4650
</TableCell>
4751
);
4852
}

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Tooltip } from '@mui/material';
8-
import { useMemo } from 'react';
98
import { useFieldArray } from 'react-hook-form';
109
import {
1110
LimitReductionIColumnsDef,
@@ -19,7 +18,7 @@ interface LimitReductionsTableProps {
1918
columnsDefinition: LimitReductionIColumnsDef[];
2019
tableHeight: number;
2120
formName: string;
22-
limits: ILimitReductionsByVoltageLevel[];
21+
limits?: ILimitReductionsByVoltageLevel[];
2322
}
2423

2524
export function CustomVoltageLevelTable({
@@ -32,11 +31,6 @@ export function CustomVoltageLevelTable({
3231
name: formName,
3332
});
3433

35-
const TableRowComponent = useMemo(
36-
() => (formName === LIMIT_REDUCTIONS_FORM ? LimitReductionTableRow : CustomVoltageLevelTableRow),
37-
[formName]
38-
);
39-
4034
return (
4135
<TableContainer
4236
sx={{
@@ -63,15 +57,23 @@ export function CustomVoltageLevelTable({
6357
</TableRow>
6458
</TableHead>
6559
<TableBody>
66-
{rows.map((row, index) => (
67-
<TableRowComponent
68-
key={`${row.id}`}
69-
columnsDefinition={columnsDefinition}
70-
index={index}
71-
formName={formName}
72-
limits={limits}
73-
/>
74-
))}
60+
{rows.map((row, index) =>
61+
formName === LIMIT_REDUCTIONS_FORM && limits ? (
62+
<LimitReductionTableRow
63+
key={`${row.id}`}
64+
columnsDefinition={columnsDefinition}
65+
index={index}
66+
limits={limits}
67+
/>
68+
) : (
69+
<CustomVoltageLevelTableRow
70+
key={`${row.id}`}
71+
columnsDefinition={columnsDefinition}
72+
index={index}
73+
formName={formName}
74+
/>
75+
)
76+
)}
7577
</TableBody>
7678
</Table>
7779
</TableContainer>

0 commit comments

Comments
 (0)