Skip to content

Refactor UUID typing for study, node, and rootnetwork #2600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,14 @@ function SingleLineDiagramContent(props: SingleLineDiagramContentProps) {
const handleBreakerClick: OnBreakerCallbackType = useCallback(
// switchElement should be SVGElement, this will be fixed once https://github.com/powsybl/powsybl-network-viewer/pull/106/ is merged
(breakerId, newSwitchState, switchElement: any) => {
if (!currentNode) {
return;
}
if (!modificationInProgress) {
setModificationInProgress(true);
setLocallySwitchedBreaker(switchElement?.id);

updateSwitchState(studyUuid, currentNode?.id, breakerId, newSwitchState).catch((error) => {
updateSwitchState(studyUuid, currentNode.id, breakerId, newSwitchState).catch((error) => {
console.error(error.message);
setErrorMessage(error.message);
});
Expand Down Expand Up @@ -285,6 +288,9 @@ function SingleLineDiagramContent(props: SingleLineDiagramContentProps) {

const removeEquipment = useCallback(
(equipmentType: string, equipmentId: string) => {
if (!currentNode?.id) {
return;
}
deleteEquipment(studyUuid, currentNode?.id, equipmentType, equipmentId, undefined).catch((error) => {
snackError({
messageTxt: error.message,
Expand All @@ -298,10 +304,13 @@ function SingleLineDiagramContent(props: SingleLineDiagramContentProps) {

const handleRunShortcircuitAnalysis = useCallback(
(busId: string) => {
if (!currentNode?.id || !currentRootNetworkUuid) {
return;
}
dispatch(setComputingStatus(ComputingType.SHORT_CIRCUIT_ONE_BUS, RunningStatus.RUNNING));
displayOneBusShortcircuitAnalysisLoader();
dispatch(setComputationStarting(true));
startShortCircuitAnalysis(studyUuid, currentNode?.id, currentRootNetworkUuid, busId)
startShortCircuitAnalysis(studyUuid, currentNode.id, currentRootNetworkUuid, busId)
.catch((error) => {
snackError({
messageTxt: error.message,
Expand All @@ -317,11 +326,11 @@ function SingleLineDiagramContent(props: SingleLineDiagramContentProps) {
});
},
[
currentNode?.id,
currentRootNetworkUuid,
dispatch,
displayOneBusShortcircuitAnalysisLoader,
studyUuid,
currentNode?.id,
currentRootNetworkUuid,
snackError,
resetOneBusShortcircuitAnalysisLoader,
]
Expand All @@ -344,6 +353,9 @@ function SingleLineDiagramContent(props: SingleLineDiagramContentProps) {

const handleDeleteEquipment = useCallback(
(equipmentType: EquipmentType | null, equipmentId: string) => {
if (!currentNode?.id || !currentRootNetworkUuid) {
return;
}
const equipmentEnumType = EQUIPMENT_TYPES[equipmentType as keyof typeof EQUIPMENT_TYPES];
if (equipmentEnumType !== EQUIPMENT_TYPES.HVDC_LINE) {
removeEquipment(equipmentEnumType, equipmentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { UUID } from 'crypto';
import { EQUIPMENT_TYPES } from '../../../../utils/equipment-types';
import { Filter } from '../commons/by-filter.type';

Expand All @@ -20,8 +21,8 @@ export interface ByFilterDeletionFormData {
}

export interface ByFilterDeletionDialogProps {
studyUuid: string;
currentNode: { id: string };
studyUuid: UUID;
currentNode: { id: UUID };
editData: ByFilterDeletionEditData;
isUpdate: boolean;
editDataFetchStatus: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ const ModelFilter = forwardRef<GetSelectedVariablesHandle, ModelFilterProps>(

// fetch all associated models and variables for study
useEffect(() => {
if (!studyUuid) {
return;
}
fetchDynamicSimulationModels(studyUuid).then((models: DynamicSimulationModelBack[]) => {
setAllModels(
models.map((model) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ export const NonEvacuatedEnergyParameters: FunctionComponent<NonEvacuatedEnergyP
const [nonEvacuatedEnergyParams, setNonEvacuatedEnergyParams] = useNonEvacuatedEnergyParameters;

const resetNonEvacuatedEnergyParameters = useCallback(() => {
if (!studyUuid) {
return;
}
setNonEvacuatedEnergyParameters(studyUuid, emptyFormData).catch((error) => {
snackError({
messageTxt: error.message,
Expand Down Expand Up @@ -250,6 +253,9 @@ export const NonEvacuatedEnergyParameters: FunctionComponent<NonEvacuatedEnergyP

const onSubmit = useCallback(
(newParams: NonEvacuatedEnergyParametersForm) => {
if (!studyUuid) {
return;
}
setNonEvacuatedEnergyParameters(studyUuid, formatNewParams(newParams, true))
.then(() => {
setNonEvacuatedEnergyParams(formatNewParams(newParams, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export const SensitivityAnalysisParameters: FunctionComponent<SensitivityAnalysi
const [sensitivityAnalysisParams, setSensitivityAnalysisParams] = useState(params);

const resetSensitivityAnalysisParameters = useCallback(() => {
if (!studyUuid) {
return;
}
setSensitivityAnalysisParameters(studyUuid, null).catch((error) => {
snackError({
messageTxt: error.message,
Expand Down Expand Up @@ -225,7 +228,7 @@ export const SensitivityAnalysisParameters: FunctionComponent<SensitivityAnalysi
(row: any, arrayFormName: SubTabsValues, index: number) => {
// TODO: not easy to fix any here since values[SubTabsValues] have each time different type which causes problems with "filter"
// "none of those signatures are compatible with each other
if (!currentNode || !currentRootNetworkUuid) {
if (!studyUuid || !currentNode?.id || !currentRootNetworkUuid) {
return;
}
setLaunchLoader(true);
Expand All @@ -250,7 +253,7 @@ export const SensitivityAnalysisParameters: FunctionComponent<SensitivityAnalysi
});
});
},
[snackError, studyUuid, currentRootNetworkUuid, formatFilteredParams, setValue, getResultCount, currentNode]
[snackError, studyUuid, currentRootNetworkUuid, formatFilteredParams, setValue, getResultCount, currentNode?.id]
);

const fromSensitivityAnalysisParamsDataToFormValues = useCallback(
Expand Down Expand Up @@ -442,6 +445,9 @@ export const SensitivityAnalysisParameters: FunctionComponent<SensitivityAnalysi
}, [onChangeParams, getValues]);
const onSubmit = useCallback(
(newParams: SensitivityAnalysisParametersFormSchema) => {
if (!studyUuid) {
return;
}
setIsSubmitAction(true);
setSensitivityAnalysisParameters(studyUuid, formatNewParams(newParams))
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ export const ShortCircuitParameters: FunctionComponent<ShortCircuitParametersPro
// submit the new parameters
const onSubmit = useCallback(
(newParams: ShortCircuitParametersFormProps) => {
if (!studyUuid) {
return;
}
const oldParams = shortCircuitParams;
setShortCircuitParameters(studyUuid, {
...prepareDataToSend(shortCircuitParams, newParams),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export const VoltageInitParameters = ({
}, []);

const resetVoltageInitParameters = useCallback(() => {
if (!studyUuid) {
return;
}
updateVoltageInitParameters(studyUuid, {
applyModifications: DEFAULT_GENERAL_APPLY_MODIFICATIONS,
computationParameters: null,
Expand Down Expand Up @@ -105,6 +108,9 @@ export const VoltageInitParameters = ({

const onSubmit = useCallback(
(newParams: VoltageInitParametersForm) => {
if (!studyUuid) {
return;
}
updateVoltageInitParameters(studyUuid, fromVoltageInitParametersFormToParamValues(newParams))
.then(() => {
setVoltageInitParams(fromVoltageInitParametersFormToParamValues(newParams));
Expand Down
22 changes: 14 additions & 8 deletions src/components/dialogs/restore-modification-dialog.tsx
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 { useEffect, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import {
Button,
Expand Down Expand Up @@ -73,24 +73,30 @@ const RestoreModificationDialog = ({ open, onClose, modifToRestore }: RestoreMod

const { computeLabel } = useModificationLabelComputer();

const handleClose = () => {
const handleClose = useCallback(() => {
setSelectedItems([]);
onClose();
};
}, [onClose]);

const handleDelete = () => {
const handleDelete = useCallback(() => {
if (!studyUuid || !currentNode?.id) {
return;
}
const selectedModificationsUuidsToDelete = selectedItems.map((item) => item.uuid);
setOpenDeleteConfirmationPopup(false);
deleteModifications(studyUuid, currentNode?.id, selectedModificationsUuidsToDelete);
handleClose();
};
}, [currentNode?.id, handleClose, selectedItems, studyUuid]);

const handleRestore = () => {
const handleRestore = useCallback(() => {
if (!studyUuid || !currentNode?.id) {
return;
}
const selectedModificationsUuidToRestore = selectedItems.map((item) => item.uuid);

restoreModifications(studyUuid, currentNode?.id, selectedModificationsUuidToRestore);
restoreModifications(studyUuid, currentNode.id, selectedModificationsUuidToRestore);
handleClose();
};
}, [currentNode?.id, handleClose, selectedItems, studyUuid]);

useEffect(() => {
setStashedModifications(modifToRestore);
Expand Down
11 changes: 7 additions & 4 deletions src/components/graph/menus/network-modification-node-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ const NetworkModificationNodeEditor = () => {
);

const dofetchNetworkModificationsToRestore = useCallback(() => {
if (currentNode?.type !== 'NETWORK_MODIFICATION') {
if (!studyUuid || currentNode?.type !== 'NETWORK_MODIFICATION') {
return;
}
setLaunchLoader(true);
Expand Down Expand Up @@ -559,7 +559,7 @@ const NetworkModificationNodeEditor = () => {

const dofetchNetworkModifications = useCallback(() => {
// Do not fetch modifications on the root node
if (currentNode?.type !== 'NETWORK_MODIFICATION') {
if (!studyUuid || currentNode?.type !== 'NETWORK_MODIFICATION') {
return;
}
setLaunchLoader(true);
Expand Down Expand Up @@ -691,8 +691,11 @@ const NetworkModificationNodeEditor = () => {
}, []);

const doDeleteModification = useCallback(() => {
if (!studyUuid || !currentNode?.id) {
return;
}
const selectedModificationsUuid = selectedItems.map((item) => item.uuid);
stashModifications(studyUuid, currentNode?.id, selectedModificationsUuid)
stashModifications(studyUuid, currentNode.id, selectedModificationsUuid)
.then(() => {
//if one of the deleted element was in the clipboard we invalidate the clipboard
if (
Expand Down Expand Up @@ -843,7 +846,7 @@ const NetworkModificationNodeEditor = () => {
const commit = useCallback(
({ source, destination }: DropResult) => {
setIsDragging(false);
if (!currentNode?.id || !destination || source.index === destination.index) {
if (!studyUuid || !currentNode?.id || !destination || source.index === destination.index) {
return;
}
const res = [...modifications];
Expand Down
29 changes: 18 additions & 11 deletions src/components/graph/menus/node-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { updateTreeNode } from '../../../services/study/tree-subtree';
import { Box } from '@mui/material';
import { AppState } from '../../../redux/reducer';
import { Theme } from '@mui/material/styles';
import { useCallback } from 'react';

const styles = {
paper: (theme: Theme) => ({
Expand All @@ -40,18 +41,24 @@ const NodeEditor = () => {
dispatch(setModificationsDrawerOpen(false));
};

const changeNodeName = (newName: string) => {
updateTreeNode(studyUuid, {
id: currentTreeNode?.id,
type: currentTreeNode?.type,
name: newName,
}).catch((error) => {
snackError({
messageTxt: error.message,
headerId: 'NodeUpdateError',
const changeNodeName = useCallback(
(newName: string) => {
if (!studyUuid || !currentTreeNode?.id) {
return;
}
updateTreeNode(studyUuid, {
id: currentTreeNode?.id,
type: currentTreeNode?.type,
name: newName,
}).catch((error) => {
snackError({
messageTxt: error.message,
headerId: 'NodeUpdateError',
});
});
});
};
},
[currentTreeNode?.id, currentTreeNode?.type, snackError, studyUuid]
);

return (
<Box sx={styles.paper}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export const SwitchNetworkModificationActive = (props: SwitchNetworkModification

const updateModification = useCallback(
(activated: boolean) => {
setModificationActivated(studyUuid, currentNode?.id, modificationUuid, activated)
if (!studyUuid || !currentNode?.id) {
return;
}
setModificationActivated(studyUuid, currentNode.id, modificationUuid, activated)
.catch((err) => {
snackError({ messageTxt: err.message, messageId: 'networkModificationActivationError' });
})
Expand Down
8 changes: 7 additions & 1 deletion src/components/menus/bus-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export const BusMenu: FunctionComponent<BusMenuProps> = ({
);

useEffect(() => {
if (!studyUuid || !currentNode?.id || !currentRootNetworkUuid) {
return;
}
fetchNetworkElementInfos(
studyUuid,
currentNode?.id,
Expand Down Expand Up @@ -121,12 +124,15 @@ export const BusMenu: FunctionComponent<BusMenuProps> = ({
);

const handleClickTrip = useCallback(() => {
if (!studyUuid || !currentNode?.id) {
return;
}
onClose();
if (setModificationInProgress !== undefined) {
setModificationInProgress(true);
}
const equipmentInfos = { id: busId };
tripEquipment(studyUuid, currentNode?.id, equipmentInfos).catch((error) => {
tripEquipment(studyUuid, currentNode.id, equipmentInfos).catch((error) => {
snackError({
messageTxt: error.message,
headerId: 'UnableToTripBusbarSection',
Expand Down
Loading
Loading