Skip to content

Commit

Permalink
Merge branch 'main' into mutualize-unit-conversion-into-one-file
Browse files Browse the repository at this point in the history
  • Loading branch information
ghazwarhili authored Jan 8, 2025
2 parents fb9096f + e4c4711 commit 3252356
Show file tree
Hide file tree
Showing 32 changed files with 498 additions and 409 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@gridsuite/commons-ui": "0.75.0",
"@gridsuite/commons-ui": "0.76.2",
"@hookform/resolvers": "^3.3.4",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ChangeEvent, useMemo } from 'react';
import { useSnackMessage } from '@gridsuite/commons-ui';
import { SelectChangeEvent } from '@mui/material/Select/SelectInput';
import { computeTolerance } from '../../../hooks/use-aggrid-local-row-filter';
import { countDecimalPlaces } from '../../../utils/rounding';
import { countDecimalPlacesFromString } from '../../../utils/rounding';
import { useCustomAggridFilter } from './use-custom-aggrid-filter';
import { FilterParams } from '../custom-aggrid-header.type';

Expand Down Expand Up @@ -43,7 +43,7 @@ export const useCustomAggridComparatorFilter = (field: string, filterParams: Fil

const decimalAfterDot = useMemo(() => {
if (isNumberInput) {
let decimalAfterDot = countDecimalPlaces(Number(selectedFilterData));
let decimalAfterDot: number = countDecimalPlacesFromString(String(selectedFilterData));
if (decimalAfterDot >= 13) {
snackWarning({
headerId: 'filter.warnRounding',
Expand Down
123 changes: 72 additions & 51 deletions src/components/diagrams/diagram-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const useDisplayView = (studyUuid: UUID, currentNode: CurrentTreeNode) => {
return useCallback(
(diagramState: Partial<DiagramView>) => {
if (!studyUuid || !currentNode) {
return Promise.reject();
return Promise.reject(new Error('useDisplayView error: currentNode not build or studyUuid undefined'));
}

function createSubstationDiagramView(id: UUID, state: ViewState | undefined) {
Expand Down Expand Up @@ -329,6 +329,7 @@ type DiagramView = {
};

export function DiagramPane({ studyUuid, currentNode, showInSpreadsheet, visible }: DiagramPaneProps) {
const { snackError } = useSnackMessage();
const dispatch = useDispatch();
const intl = useIntl();
const studyUpdatedForce = useSelector((state: AppState) => state.studyUpdated);
Expand Down Expand Up @@ -405,26 +406,32 @@ export function DiagramPane({ studyUuid, currentNode, showInSpreadsheet, visible

// Then we add the data when the fetch is finished
diagramsToAdd.forEach((diagramState) => {
createView(diagramState)?.then((singleLineDiagramView) => {
setViews((views) => {
const diagramViewId = views.findIndex(
(view) =>
view.svgType !== DiagramType.NETWORK_AREA_DIAGRAM && view.id === diagramState.id
);
const updatedViews = views.slice();
// we update the SLD with the fetched data
updatedViews[diagramViewId] = {
...updatedViews[diagramViewId],
...singleLineDiagramView,
loadingState: false,
} as unknown as DiagramView;
return updatedViews;
createView(diagramState)
?.then((singleLineDiagramView) => {
setViews((views) => {
const diagramViewId = views.findIndex(
(view) =>
view.svgType !== DiagramType.NETWORK_AREA_DIAGRAM && view.id === diagramState.id
);
const updatedViews = views.slice();
// we update the SLD with the fetched data
updatedViews[diagramViewId] = {
...updatedViews[diagramViewId],
...singleLineDiagramView,
loadingState: false,
} as unknown as DiagramView;
return updatedViews;
});
})
.catch((error) => {
snackError({
messageTxt: error.message,
});
});
});
});
}
},
[createView, intl]
[createView, intl, snackError]
);

// Check if we need to remove old SLDs from the 'views' and remove them if necessary
Expand Down Expand Up @@ -499,25 +506,31 @@ export function DiagramPane({ studyUuid, currentNode, showInSpreadsheet, visible
state: networkAreaViewState,
svgType: DiagramType.NETWORK_AREA_DIAGRAM,
depth: networkAreaDiagramDepth,
})?.then((networkAreaDiagramView) => {
setViews((views) => {
const updatedViews = views.slice();
const nadViewId = views.findIndex((view) => view.svgType === DiagramType.NETWORK_AREA_DIAGRAM);
updatedViews[nadViewId] = {
...updatedViews[nadViewId],
...networkAreaDiagramView,
loadingState: false,
} as unknown as DiagramView;
dispatch(
setNetworkAreaDiagramNbVoltageLevels(
networkAreaDiagramView.additionalMetadata?.nbVoltageLevels ?? 0
)
);
return updatedViews;
})
?.then((networkAreaDiagramView) => {
setViews((views) => {
const updatedViews = views.slice();
const nadViewId = views.findIndex((view) => view.svgType === DiagramType.NETWORK_AREA_DIAGRAM);
updatedViews[nadViewId] = {
...updatedViews[nadViewId],
...networkAreaDiagramView,
loadingState: false,
} as unknown as DiagramView;
dispatch(
setNetworkAreaDiagramNbVoltageLevels(
networkAreaDiagramView.additionalMetadata?.nbVoltageLevels ?? 0
)
);
return updatedViews;
});
})
.catch((error) => {
snackError({
messageTxt: error.message,
});
});
});
},
[createView, intl, dispatch]
[createView, intl, dispatch, snackError]
);

const removeNAD = useCallback(() => {
Expand Down Expand Up @@ -729,28 +742,36 @@ export function DiagramPane({ studyUuid, currentNode, showInSpreadsheet, visible
} else {
updatedDiagramPromise = currentView.fetchSvg?.();
}
updatedDiagramPromise?.then((svg) => {
setViews((views) => {
const updatedViews = views.slice();
const data: DiagramView = {
...updatedViews[i],
...svg,
loadingState: false,
} as unknown as DiagramView;
updatedViews[i] = data;
if (fromScratch && svg.svgType === DiagramType.NETWORK_AREA_DIAGRAM) {
dispatch(
setNetworkAreaDiagramNbVoltageLevels(svg.additionalMetadata?.nbVoltageLevels)
);
}
return updatedViews;
updatedDiagramPromise
?.then((svg) => {
setViews((views) => {
const updatedViews = views.slice();
const data: DiagramView = {
...updatedViews[i],
...svg,
loadingState: false,
} as unknown as DiagramView;
updatedViews[i] = data;
if (fromScratch && svg.svgType === DiagramType.NETWORK_AREA_DIAGRAM) {
dispatch(
setNetworkAreaDiagramNbVoltageLevels(
svg.additionalMetadata?.nbVoltageLevels
)
);
}
return updatedViews;
});
})
.catch((error) => {
snackError({
messageTxt: error.message,
});
});
});
}
}
}
},
[createView, dispatch]
[createView, dispatch, snackError]
);

// Updates particular diagrams from the current node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PARAM_SA_LOW_VOLTAGE_PROPORTIONAL_THRESHOLD,
} from 'utils/config-params';
import yup from '../../../../utils/yup-config';
import { NumberSchema } from 'yup';

export const LIMIT_REDUCTIONS_FORM = 'limitReductionsForm';
export const VOLTAGE_LEVELS_FORM = 'voltageLevelsForm';
Expand Down Expand Up @@ -64,20 +65,39 @@ export const TAB_INFO = [
export interface IColumnsDef {
label: string;
dataKey: string;
tooltip: string;
width?: string;
}

export const COLUMNS_DEFINITIONS_LIMIT_REDUCTIONS = [
export const COLUMNS_DEFINITIONS_LIMIT_REDUCTIONS: IColumnsDef[] = [
{
label: 'VoltageLevels',
label: 'voltageRange',
dataKey: VOLTAGE_LEVELS_FORM,
tooltip: 'voltageRange',
},
{
label: 'IST',
dataKey: IST_FORM,
tooltip: 'IST',
},
];

//TODO: a cleaner solution can be done by using yup.array()
// Instead of creating a schema for each limit duration individually,
// we can use yup.array() to define an array of limit durations directly.
const getLimitDurationsFormSchema = (nbLimits: number) => {
let limitDurationsFormSchema: Record<string, NumberSchema> = {};
for (let i = 0; i < nbLimits; i++) {
limitDurationsFormSchema[LIMIT_DURATION_FORM + i] = yup
.number()
.min(0, 'RealPercentage')
.max(1, 'RealPercentage')
.nullable()
.required();
}
return limitDurationsFormSchema;
};

export const getLimitReductionsFormSchema = (nbTemporaryLimits: number) => {
return yup
.object()
Expand All @@ -86,11 +106,7 @@ export const getLimitReductionsFormSchema = (nbTemporaryLimits: number) => {
yup.object().shape({
[VOLTAGE_LEVELS_FORM]: yup.string(),
[IST_FORM]: yup.number().min(0, 'RealPercentage').max(1, 'RealPercentage').nullable().required(),
[LIMIT_DURATION_FORM]: yup
.array()
.length(nbTemporaryLimits)
.of(yup.number().min(0, 'RealPercentage').max(1, 'RealPercentage').nullable().required())
.required(),
...getLimitDurationsFormSchema(nbTemporaryLimits),
})
),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,33 @@ import {
import { useIntl } from 'react-intl';
import LimitReductionsTable from './limit-reductions-table';

const getLabelColumn = (limit: ITemporaryLimitReduction) => {
const lowBound = `${Math.trunc(limit.limitDuration.lowBound / 60)} min`;
const highBoundValue = Math.trunc(limit.limitDuration.highBound / 60);
const highBound = highBoundValue === 0 ? '∞' : `${Math.trunc(limit.limitDuration.highBound / 60)} min`;
const lowerBoundClosed = limit.limitDuration.lowClosed ? '[' : ']';
const highBoundClosed = limit.limitDuration.highClosed || null ? ']' : '[';
return `${lowerBoundClosed}${lowBound}, ${highBound}${highBoundClosed}`;
};

const LimitReductionsTableForm: FunctionComponent<{
limits: ILimitReductionsByVoltageLevel[];
}> = ({ limits }) => {
const intl = useIntl();

const getLabelColumn = useCallback(
const getToolTipColumn = useCallback(
(limit: ITemporaryLimitReduction) => {
const lowBound = Math.trunc(limit.limitDuration.lowBound / 60);
const highBound = Math.trunc(limit.limitDuration.highBound / 60);
if (lowBound === 0) {
return intl.formatMessage({ id: 'LimitDurationAfterIST' }, { value: highBound });
}

return intl.formatMessage(
{ id: 'LimitDuration' },
{ id: 'LimitDurationInterval' },
{
sign: limit.limitDuration.lowClosed ? '>=' : '>',
value: Math.trunc(limit.limitDuration.lowBound / 60),
lowBound: `IT${lowBound}`,
highBound: highBound === 0 ? 'IST' : `IT${highBound}`,
}
);
},
Expand All @@ -36,21 +51,23 @@ const LimitReductionsTableForm: FunctionComponent<{
let columnsDefinition = COLUMNS_DEFINITIONS_LIMIT_REDUCTIONS.map((column) => ({
...column,
label: intl.formatMessage({ id: column.label }),
tooltip: intl.formatMessage({ id: column.tooltip }),
}));

if (limits !== null && limits.length > 0) {
limits[0].temporaryLimitReductions.forEach((tlimit, index) => {
columnsDefinition.push({
label: getLabelColumn(tlimit),
dataKey: LIMIT_DURATION_FORM + index,
tooltip: getToolTipColumn(tlimit),
});
});
}

return columnsDefinition;
}, [intl, limits, getLabelColumn]);
}, [intl, limits, getToolTipColumn]);

return <LimitReductionsTable columnsDefinition={columnsDefinition} tableHeight={600} />;
return <LimitReductionsTable columnsDefinition={columnsDefinition} tableHeight={450} />;
};

export default LimitReductionsTableForm;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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, Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@mui/material';
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@mui/material';
import { FunctionComponent } from 'react';
import { IColumnsDef, LIMIT_REDUCTIONS_FORM } from './columns-definitions';
import { useFieldArray } from 'react-hook-form';
Expand Down Expand Up @@ -37,8 +37,9 @@ const LimitReductionsTable: FunctionComponent<LimitReductionsTableProps> = ({ co
sx={{
textAlign: 'center',
}}
title={column.tooltip}
>
<Box>{column.label}</Box>
{column.label}
</TableCell>
))}
</TableRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ const MappingParameters: FunctionComponent<MappingParametersProps> = ({ mapping,
const { mappings } = mapping ?? {};

const mappingOptions = useMemo(() => {
return (
mappings?.map((elem) => ({
id: elem.name,
label: elem.name,
})) ?? []
);
return mappings?.map((elem) => elem.name) ?? [];
}, [mappings]);

const defParams: Record<string, DefParam> = {
Expand Down
Loading

0 comments on commit 3252356

Please sign in to comment.