diff --git a/src/components/diagrams/singleLineDiagram/single-line-diagram-content.tsx b/src/components/diagrams/singleLineDiagram/single-line-diagram-content.tsx index e2ff9e9479..913a1f0d96 100644 --- a/src/components/diagrams/singleLineDiagram/single-line-diagram-content.tsx +++ b/src/components/diagrams/singleLineDiagram/single-line-diagram-content.tsx @@ -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); }); @@ -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, @@ -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, @@ -317,11 +326,11 @@ function SingleLineDiagramContent(props: SingleLineDiagramContentProps) { }); }, [ + currentNode?.id, + currentRootNetworkUuid, dispatch, displayOneBusShortcircuitAnalysisLoader, studyUuid, - currentNode?.id, - currentRootNetworkUuid, snackError, resetOneBusShortcircuitAnalysisLoader, ] @@ -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); diff --git a/src/components/dialogs/network-modifications/by-filter/by-filter-deletion/by-filter-deletion.type.ts b/src/components/dialogs/network-modifications/by-filter/by-filter-deletion/by-filter-deletion.type.ts index e3baf51fb5..006ce4b0d5 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-filter-deletion/by-filter-deletion.type.ts +++ b/src/components/dialogs/network-modifications/by-filter/by-filter-deletion/by-filter-deletion.type.ts @@ -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'; @@ -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; diff --git a/src/components/dialogs/parameters/dynamicsimulation/curve/dialog/model-filter.tsx b/src/components/dialogs/parameters/dynamicsimulation/curve/dialog/model-filter.tsx index d905f469ba..9f7cfaba7d 100644 --- a/src/components/dialogs/parameters/dynamicsimulation/curve/dialog/model-filter.tsx +++ b/src/components/dialogs/parameters/dynamicsimulation/curve/dialog/model-filter.tsx @@ -217,6 +217,9 @@ const ModelFilter = forwardRef( // fetch all associated models and variables for study useEffect(() => { + if (!studyUuid) { + return; + } fetchDynamicSimulationModels(studyUuid).then((models: DynamicSimulationModelBack[]) => { setAllModels( models.map((model) => ({ diff --git a/src/components/dialogs/parameters/non-evacuated-energy/non-evacuated-energy-parameters.tsx b/src/components/dialogs/parameters/non-evacuated-energy/non-evacuated-energy-parameters.tsx index 5633a87395..a00385c2ba 100644 --- a/src/components/dialogs/parameters/non-evacuated-energy/non-evacuated-energy-parameters.tsx +++ b/src/components/dialogs/parameters/non-evacuated-energy/non-evacuated-energy-parameters.tsx @@ -221,6 +221,9 @@ export const NonEvacuatedEnergyParameters: FunctionComponent { + if (!studyUuid) { + return; + } setNonEvacuatedEnergyParameters(studyUuid, emptyFormData).catch((error) => { snackError({ messageTxt: error.message, @@ -250,6 +253,9 @@ export const NonEvacuatedEnergyParameters: FunctionComponent { + if (!studyUuid) { + return; + } setNonEvacuatedEnergyParameters(studyUuid, formatNewParams(newParams, true)) .then(() => { setNonEvacuatedEnergyParams(formatNewParams(newParams, false)); diff --git a/src/components/dialogs/parameters/sensi/sensitivity-analysis-parameters.tsx b/src/components/dialogs/parameters/sensi/sensitivity-analysis-parameters.tsx index d58c259f97..fbdc7e6529 100644 --- a/src/components/dialogs/parameters/sensi/sensitivity-analysis-parameters.tsx +++ b/src/components/dialogs/parameters/sensi/sensitivity-analysis-parameters.tsx @@ -147,6 +147,9 @@ export const SensitivityAnalysisParameters: FunctionComponent { + if (!studyUuid) { + return; + } setSensitivityAnalysisParameters(studyUuid, null).catch((error) => { snackError({ messageTxt: error.message, @@ -225,7 +228,7 @@ export const SensitivityAnalysisParameters: FunctionComponent { // 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); @@ -250,7 +253,7 @@ export const SensitivityAnalysisParameters: FunctionComponent { + if (!studyUuid) { + return; + } setIsSubmitAction(true); setSensitivityAnalysisParameters(studyUuid, formatNewParams(newParams)) .then(() => { diff --git a/src/components/dialogs/parameters/short-circuit-parameters.tsx b/src/components/dialogs/parameters/short-circuit-parameters.tsx index c660630600..f1306d11f1 100644 --- a/src/components/dialogs/parameters/short-circuit-parameters.tsx +++ b/src/components/dialogs/parameters/short-circuit-parameters.tsx @@ -193,6 +193,9 @@ export const ShortCircuitParameters: FunctionComponent { + if (!studyUuid) { + return; + } const oldParams = shortCircuitParams; setShortCircuitParameters(studyUuid, { ...prepareDataToSend(shortCircuitParams, newParams), diff --git a/src/components/dialogs/parameters/voltageinit/voltage-init-parameters.tsx b/src/components/dialogs/parameters/voltageinit/voltage-init-parameters.tsx index 689e01be46..c2a44df6b0 100644 --- a/src/components/dialogs/parameters/voltageinit/voltage-init-parameters.tsx +++ b/src/components/dialogs/parameters/voltageinit/voltage-init-parameters.tsx @@ -72,6 +72,9 @@ export const VoltageInitParameters = ({ }, []); const resetVoltageInitParameters = useCallback(() => { + if (!studyUuid) { + return; + } updateVoltageInitParameters(studyUuid, { applyModifications: DEFAULT_GENERAL_APPLY_MODIFICATIONS, computationParameters: null, @@ -105,6 +108,9 @@ export const VoltageInitParameters = ({ const onSubmit = useCallback( (newParams: VoltageInitParametersForm) => { + if (!studyUuid) { + return; + } updateVoltageInitParameters(studyUuid, fromVoltageInitParametersFormToParamValues(newParams)) .then(() => { setVoltageInitParams(fromVoltageInitParametersFormToParamValues(newParams)); diff --git a/src/components/dialogs/restore-modification-dialog.tsx b/src/components/dialogs/restore-modification-dialog.tsx index 00d52f133c..92d65e76bb 100644 --- a/src/components/dialogs/restore-modification-dialog.tsx +++ b/src/components/dialogs/restore-modification-dialog.tsx @@ -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, @@ -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); diff --git a/src/components/graph/menus/network-modification-node-editor.tsx b/src/components/graph/menus/network-modification-node-editor.tsx index 9d057245f3..b1725c5cc0 100644 --- a/src/components/graph/menus/network-modification-node-editor.tsx +++ b/src/components/graph/menus/network-modification-node-editor.tsx @@ -530,7 +530,7 @@ const NetworkModificationNodeEditor = () => { ); const dofetchNetworkModificationsToRestore = useCallback(() => { - if (currentNode?.type !== 'NETWORK_MODIFICATION') { + if (!studyUuid || currentNode?.type !== 'NETWORK_MODIFICATION') { return; } setLaunchLoader(true); @@ -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); @@ -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 ( @@ -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]; diff --git a/src/components/graph/menus/node-editor.tsx b/src/components/graph/menus/node-editor.tsx index 6aceda8cfa..0d8004acc1 100644 --- a/src/components/graph/menus/node-editor.tsx +++ b/src/components/graph/menus/node-editor.tsx @@ -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) => ({ @@ -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 ( diff --git a/src/components/graph/menus/switch-network-modification-active.tsx b/src/components/graph/menus/switch-network-modification-active.tsx index 48ebdee798..3ad45b3c15 100644 --- a/src/components/graph/menus/switch-network-modification-active.tsx +++ b/src/components/graph/menus/switch-network-modification-active.tsx @@ -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' }); }) diff --git a/src/components/menus/bus-menu.tsx b/src/components/menus/bus-menu.tsx index 05ecd19d4e..fb0e11be9c 100644 --- a/src/components/menus/bus-menu.tsx +++ b/src/components/menus/bus-menu.tsx @@ -84,6 +84,9 @@ export const BusMenu: FunctionComponent = ({ ); useEffect(() => { + if (!studyUuid || !currentNode?.id || !currentRootNetworkUuid) { + return; + } fetchNetworkElementInfos( studyUuid, currentNode?.id, @@ -121,12 +124,15 @@ export const BusMenu: FunctionComponent = ({ ); 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', diff --git a/src/components/menus/operating-status-menu.tsx b/src/components/menus/operating-status-menu.tsx index fa8381c766..2caf272221 100644 --- a/src/components/menus/operating-status-menu.tsx +++ b/src/components/menus/operating-status-menu.tsx @@ -94,28 +94,33 @@ const withOperatingStatusMenu = const [enableDeveloperMode] = useParameterState(PARAM_DEVELOPER_MODE); - const getTranslationKey = (key: string) => { - if (equipmentType) { - return key.concat(EQUIPMENT_TYPE_LABEL_KEYS[equipmentType]); - } - }; + const getTranslationKey = useCallback( + (key: string) => { + if (equipmentType) { + return key.concat(EQUIPMENT_TYPE_LABEL_KEYS[equipmentType]); + } + }, + [equipmentType] + ); useEffect(() => { - if (equipment?.id) { - fetchNetworkElementInfos( - studyUuid, - currentNode?.id, - currentRootNetworkUuid, - equipmentType, - EQUIPMENT_INFOS_TYPES.OPERATING_STATUS.type, - equipment.id, - false - ).then((value) => { - if (value) { - setEquipmentInfos(value); - } - }); + if (!studyUuid || !currentNode?.id || !currentRootNetworkUuid || !equipment?.id) { + return; } + + fetchNetworkElementInfos( + studyUuid, + currentNode?.id, + currentRootNetworkUuid, + equipmentType, + EQUIPMENT_INFOS_TYPES.OPERATING_STATUS.type, + equipment.id, + false + ).then((value) => { + if (value) { + setEquipmentInfos(value); + } + }); }, [studyUuid, currentNode?.id, currentRootNetworkUuid, equipmentType, equipment?.id]); const isNodeEditable = useMemo( @@ -133,50 +138,68 @@ const withOperatingStatusMenu = [equipmentInfos, currentNode, isAnyNodeBuilding, modificationInProgress] ); - function handleError(error: Error, translationKey: string) { - snackError({ - messageTxt: error.message, - headerId: getTranslationKey(translationKey), - }); - if (setModificationInProgress !== undefined) { - setModificationInProgress(false); - } - } + const handleError = useCallback( + (error: Error, translationKey: string) => { + snackError({ + messageTxt: error.message, + headerId: getTranslationKey(translationKey), + }); + if (setModificationInProgress !== undefined) { + setModificationInProgress(false); + } + }, + [getTranslationKey, setModificationInProgress, snackError] + ); - function startModification() { + const startModification = useCallback(() => { handleClose(); if (setModificationInProgress !== undefined) { setModificationInProgress(true); } - } + }, [handleClose, setModificationInProgress]); - function handleLockout() { + const handleLockout = useCallback(() => { + if (!studyUuid || !currentNode?.id) { + return; + } startModification(); - lockoutEquipment(studyUuid, currentNode?.id, equipmentInfos).catch((error) => { + lockoutEquipment(studyUuid, currentNode.id, equipmentInfos).catch((error) => { handleError(error, 'UnableToLockout'); }); - } + }, [currentNode?.id, equipmentInfos, handleError, startModification, studyUuid]); - function handleTrip() { + const handleTrip = useCallback(() => { + if (!studyUuid || !currentNode?.id) { + return; + } startModification(); - tripEquipment(studyUuid, currentNode?.id, equipmentInfos).catch((error) => { + tripEquipment(studyUuid, currentNode.id, equipmentInfos).catch((error) => { handleError(error, 'UnableToTrip'); }); - } + }, [currentNode?.id, equipmentInfos, handleError, startModification, studyUuid]); - function handleEnergise(side: BranchSide) { - startModification(); - energiseEquipmentEnd(studyUuid, currentNode?.id, equipmentInfos, side).catch((error) => { - handleError(error, 'UnableToEnergiseOnOneEnd'); - }); - } + const handleEnergise = useCallback( + (side: BranchSide) => { + if (!studyUuid || !currentNode?.id) { + return; + } + startModification(); + energiseEquipmentEnd(studyUuid, currentNode.id, equipmentInfos, side).catch((error) => { + handleError(error, 'UnableToEnergiseOnOneEnd'); + }); + }, + [currentNode?.id, equipmentInfos, handleError, startModification, studyUuid] + ); - function handleSwitchOn() { + const handleSwitchOn = useCallback(() => { + if (!studyUuid || !currentNode?.id) { + return; + } startModification(); - switchOnEquipment(studyUuid, currentNode?.id, equipmentInfos).catch((error) => { + switchOnEquipment(studyUuid, currentNode.id, equipmentInfos).catch((error) => { handleError(error, 'UnableToSwitchOn'); }); - } + }, [currentNode?.id, equipmentInfos, handleError, startModification, studyUuid]); const handleOpenDynamicSimulationEventDialog = useCallback( (equipmentId: string, equipmentType: EquipmentType, dialogTitle: string) => { diff --git a/src/components/network/network-map-tab.tsx b/src/components/network/network-map-tab.tsx index a01ce9bb01..ccb71ad65d 100644 --- a/src/components/network/network-map-tab.tsx +++ b/src/components/network/network-map-tab.tsx @@ -598,12 +598,14 @@ export const NetworkMapTab = ({ // loads all root node geo-data then saves them in redux // it will be considered as the source of truth to check whether we need to fetch geo-data for a specific equipment or not const loadRootNodeGeoData = useCallback(() => { + if (!rootNodeId) { + return; + } console.info(`Loading geo data of study '${studyUuid}'...`); dispatch(setMapDataLoading(true)); setGeoData(undefined); geoDataRef.current = null; - // @ts-expect-error TODO: manage rootNodeId undefined case const substationPositionsDone = fetchSubstationPositions(studyUuid, rootNodeId, currentRootNetworkUuid).then( (data) => { console.info(`Received substations of study '${studyUuid}'...`); @@ -616,8 +618,7 @@ export const NetworkMapTab = ({ const linePositionsDone = !lineFullPath ? Promise.resolve() - : // @ts-expect-error TODO: manage rootNodeId undefined case - fetchLinePositions(studyUuid, rootNodeId, currentRootNetworkUuid).then((data) => { + : fetchLinePositions(studyUuid, rootNodeId, currentRootNetworkUuid).then((data) => { console.info(`Received lines of study '${studyUuid}'...`); const newGeoData = new GeoData(geoDataRef.current?.substationPositionsById || new Map(), new Map()); newGeoData.setLinePositions(data); diff --git a/src/components/results/securityanalysis/security-analysis-result-tab.tsx b/src/components/results/securityanalysis/security-analysis-result-tab.tsx index e777f38ff2..cc26b4ead4 100644 --- a/src/components/results/securityanalysis/security-analysis-result-tab.tsx +++ b/src/components/results/securityanalysis/security-analysis-result-tab.tsx @@ -41,6 +41,7 @@ import { PARAM_DEVELOPER_MODE } from 'utils/config-params'; import { useFilterSelector } from '../../../hooks/use-filter-selector'; import { mapFieldsToColumnsFilter } from '../../../utils/aggrid-headers-utils'; import { securityAnalysisResultInvalidations } from '../../computing-status/use-all-computing-status'; +import { UUID } from 'crypto'; const styles = { tabsAndToolboxContainer: { @@ -119,7 +120,7 @@ export const SecurityAnalysisResultTab: FunctionComponent { + (studyUuid: UUID, nodeUuid: UUID) => { if (tabIndex === LOGS_TAB_INDEX) { return Promise.resolve(); } @@ -149,7 +150,6 @@ export const SecurityAnalysisResultTab: FunctionComponent([]); useEffect(() => { - if (oneBusShortCircuitAnalysisStatus !== RunningStatus.SUCCEED) { + if ( + !studyUuid || + !currentNode?.id || + !currentRootNetworkUuid || + oneBusShortCircuitAnalysisStatus !== RunningStatus.SUCCEED + ) { return; } @@ -66,7 +71,7 @@ export const ShortCircuitAnalysisOneBusResult: FunctionComponent { if (!faultResult || !feederResults) { diff --git a/src/components/results/shortcircuit/shortcircuit-analysis-result.tsx b/src/components/results/shortcircuit/shortcircuit-analysis-result.tsx index a9401f332a..fc8ff80659 100644 --- a/src/components/results/shortcircuit/shortcircuit-analysis-result.tsx +++ b/src/components/results/shortcircuit/shortcircuit-analysis-result.tsx @@ -108,7 +108,7 @@ export const ShortCircuitAnalysisResult: FunctionComponent | undefined; - studyUuid: string; + studyUuid: UUID; currentNode: CurrentTreeNode; handleColumnDrag: (e: ColumnMovedEvent) => void; handleRowDataUpdated: () => void; diff --git a/src/components/spreadsheet/table-wrapper.tsx b/src/components/spreadsheet/table-wrapper.tsx index 67fe3e35a0..2c187b8f75 100644 --- a/src/components/spreadsheet/table-wrapper.tsx +++ b/src/components/spreadsheet/table-wrapper.tsx @@ -36,6 +36,7 @@ import { updateFilters } from '../custom-aggrid/custom-aggrid-filters/utils/aggr import { useEquipmentModification } from './equipment-modification/use-equipment-modification'; import { useSpreadsheetGsFilter } from './use-spreadsheet-gs-filter'; import { changeDisplayedColumns } from '../../redux/actions'; +import { UUID } from 'crypto'; const styles = { table: (theme: Theme) => ({ @@ -75,7 +76,7 @@ const styles = { }; interface TableWrapperProps { - studyUuid: string; + studyUuid: UUID; currentNode: CurrentTreeNode; equipmentId: string; equipmentType: SpreadsheetEquipmentType; diff --git a/src/components/top-bar-equipment-seach-dialog/top-bar-equipment-search-dialog.tsx b/src/components/top-bar-equipment-seach-dialog/top-bar-equipment-search-dialog.tsx index 0151cde13f..cdbdade068 100644 --- a/src/components/top-bar-equipment-seach-dialog/top-bar-equipment-search-dialog.tsx +++ b/src/components/top-bar-equipment-seach-dialog/top-bar-equipment-search-dialog.tsx @@ -69,9 +69,11 @@ export const TopBarEquipmentSearchDialog: FunctionComponent { + if (!studyUuid || !currentNode?.id || !currentRootNetworkUuid) { + return; + } closeDialog(); updateSearchTerm(''); - // @ts-expect-error TODO: manage null case addToLocalStorageSearchEquipmentHistory(studyUuid, equipment); fetchNetworkElementInfos( studyUuid, @@ -86,11 +88,7 @@ export const TopBarEquipmentSearchDialog: FunctionComponent { - excludeElementFromCurrentSearchHistory( - // @ts-expect-error TODO: manage null case - studyUuid, - equipment - ); + excludeElementFromCurrentSearchHistory(studyUuid, equipment); updateSearchTerm(''); snackWarning({ messageId: 'NetworkEquipmentNotFound', diff --git a/src/services/network-modification-types.ts b/src/services/network-modification-types.ts index 2d502c0922..e7b863737c 100644 --- a/src/services/network-modification-types.ts +++ b/src/services/network-modification-types.ts @@ -52,7 +52,7 @@ export interface VscModificationInfo { } export interface BatteryModificationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; modificationUuid?: string; batteryId: string; @@ -77,7 +77,7 @@ export interface BatteryModificationInfo { properties?: Property[]; } export interface LoadCreationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; id: string; name?: string | null; @@ -96,7 +96,7 @@ export interface LoadCreationInfo { } export interface LoadModificationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; modificationUuid?: string; id: string; @@ -115,7 +115,7 @@ export interface LoadModificationInfo { } export interface ShuntCompensatorModificationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; shuntCompensatorId: string; shuntCompensatorName: string | null; @@ -137,7 +137,7 @@ export interface ShuntCompensatorModificationInfo { } export interface GeneratorModificationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; generatorId: string; name: string | null; @@ -178,7 +178,7 @@ export interface GeneratorModificationInfo { } export interface StaticVarCompensatorCreationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; staticCompensatorId: string; staticCompensatorName?: string | null; @@ -213,7 +213,7 @@ export interface StaticVarCompensatorCreationInfo { } export interface TwoWindingsTransformerModificationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; modificationUuid?: string; twoWindingsTransformerId: string; @@ -272,7 +272,7 @@ export interface CurrentLimits { } export interface SubstationModificationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; modificationUuid?: UUID; id: string; @@ -282,7 +282,7 @@ export interface SubstationModificationInfo { } export interface VoltageLeveInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; voltageLevelId: string; voltageLevelName: string | null; @@ -392,7 +392,7 @@ export interface Assignment { propertyName?: string; } export interface BatteryCreationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; id: string; name: string | null; @@ -418,7 +418,7 @@ export interface BatteryCreationInfo { } export interface GeneratorCreationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; id: string; name: string | null; @@ -458,7 +458,7 @@ export interface GeneratorCreationInfo { } export interface ShuntCompensatorCreationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; shuntCompensatorId: string; shuntCompensatorName: string | null; @@ -478,7 +478,7 @@ export interface ShuntCompensatorCreationInfo { } export interface LineCreationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; lineId: string; lineName: string | null; @@ -512,7 +512,7 @@ export interface LineCreationInfo { } export interface LineModificationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; modificationUuid: string; lineId: string; @@ -549,7 +549,7 @@ export interface LineModificationInfo { } export interface TwoWindingsTransformerCreationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; isUpdate: boolean; modificationUuid: string; @@ -583,7 +583,7 @@ export interface TwoWindingsTransformerCreationInfo { properties?: Property[]; } export interface SubstationCreationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; substationId: string; substationName: string | null; @@ -594,7 +594,7 @@ export interface SubstationCreationInfo { } export interface DivideLineInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; modificationUuid: UUID; lineToSplitId: string; @@ -609,7 +609,7 @@ export interface DivideLineInfo { } export interface AttachLineInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; modificationUuid: UUID; lineToAttachToId: string; @@ -627,7 +627,7 @@ export interface AttachLineInfo { } export interface LinesAttachToSplitLinesInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; modificationUuid: UUID; lineToAttachTo1Id: string; @@ -642,7 +642,7 @@ export interface LinesAttachToSplitLinesInfo { } export interface DeleteAttachingLineInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; modificationUuid: UUID; lineToAttachTo1Id: string; @@ -653,7 +653,7 @@ export interface DeleteAttachingLineInfo { } export interface VSCCreationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; id: string; name: string | null; @@ -675,7 +675,7 @@ export interface VSCCreationInfo { } export interface LCCCreationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; id: string; name?: string | null; @@ -692,7 +692,7 @@ export interface LCCCreationInfo { } export interface VSCModificationInfo { - studyUuid: string; + studyUuid: UUID; nodeUuid: UUID; id: string | null; name?: string | null; diff --git a/src/services/study/dynamic-simulation.ts b/src/services/study/dynamic-simulation.ts index e8b0b5f192..2857f1a5e7 100644 --- a/src/services/study/dynamic-simulation.ts +++ b/src/services/study/dynamic-simulation.ts @@ -92,7 +92,7 @@ export function fetchDynamicSimulationResultTimeSeries( return backendFetchJson(url); } -export function fetchDynamicSimulationModels(studyUuid: UUID | null) { +export function fetchDynamicSimulationModels(studyUuid: UUID) { console.info(`Fetching dynamic simulation models on '${studyUuid}' ...`); const url = getStudyUrl(studyUuid) + '/dynamic-simulation/models'; console.debug(url); diff --git a/src/services/study/geo-data.ts b/src/services/study/geo-data.ts index a6dc0a7d84..e95fd84b15 100644 --- a/src/services/study/geo-data.ts +++ b/src/services/study/geo-data.ts @@ -13,7 +13,7 @@ import { getStudyUrlWithNodeUuidAndRootNetworkUuid } from './index'; export function fetchSubstationPositions( studyUuid: UUID, currentNodeUuid: UUID, - currentRootNetworkUuid?: UUID, + currentRootNetworkUuid: UUID, substationsIds?: string[] ): Promise { console.info( @@ -34,7 +34,7 @@ export function fetchSubstationPositions( export function fetchLinePositions( studyUuid: UUID, currentNodeUuid: UUID, - currentRootNetworkUuid: UUID | undefined, + currentRootNetworkUuid: UUID, linesIds?: string[] ): Promise { console.info( diff --git a/src/services/study/index.ts b/src/services/study/index.ts index fbb1070b4c..59e63fe1d2 100644 --- a/src/services/study/index.ts +++ b/src/services/study/index.ts @@ -24,27 +24,20 @@ export function safeEncodeURIComponent(value: string | null | undefined): string export const PREFIX_STUDY_QUERIES = import.meta.env.VITE_API_GATEWAY + '/study'; -export const getStudyUrl = (studyUuid: UUID | null) => +export const getStudyUrl = (studyUuid: UUID) => `${PREFIX_STUDY_QUERIES}/v1/studies/${safeEncodeURIComponent(studyUuid)}`; -export const getStudyUrlWithNodeUuidAndRootNetworkUuid = ( - studyUuid: string | null | undefined, - nodeUuid: string | undefined, - rootNetworkUuid: string | undefined | null -) => +export const getStudyUrlWithNodeUuidAndRootNetworkUuid = (studyUuid: UUID, nodeUuid: UUID, rootNetworkUuid: UUID) => `${PREFIX_STUDY_QUERIES}/v1/studies/${safeEncodeURIComponent(studyUuid)}/root-networks/${safeEncodeURIComponent( rootNetworkUuid )}/nodes/${safeEncodeURIComponent(nodeUuid)}`; -export const getStudyUrlWithRootNetworkUuid = ( - studyUuid: string | null | undefined, - rootNetworkUuid: string | undefined | null -) => +export const getStudyUrlWithRootNetworkUuid = (studyUuid: UUID, rootNetworkUuid: UUID) => `${PREFIX_STUDY_QUERIES}/v1/studies/${safeEncodeURIComponent(studyUuid)}/root-networks/${safeEncodeURIComponent( rootNetworkUuid )}`; -export const getStudyUrlWithNodeUuid = (studyUuid: string | null | undefined, nodeUuid: string | undefined) => +export const getStudyUrlWithNodeUuid = (studyUuid: UUID, nodeUuid: UUID) => `${PREFIX_STUDY_QUERIES}/v1/studies/${safeEncodeURIComponent(studyUuid)}/nodes/${safeEncodeURIComponent(nodeUuid)}`; export const fetchStudy = (studyUuid: UUID) => { @@ -85,7 +78,7 @@ export function getNetworkAreaDiagramUrl( } export function fetchParentNodesReport( - studyUuid: UUID | null, + studyUuid: UUID, nodeUuid: UUID, currentRootNetworkUuid: UUID, nodeOnlyReport: boolean, @@ -117,7 +110,7 @@ export function fetchParentNodesReport( } export function fetchNodeReportLogs( - studyUuid: UUID | null, + studyUuid: UUID, nodeUuid: UUID, currentRootNetworkUuid: UUID, reportId: string | null, diff --git a/src/services/study/network-modifications.ts b/src/services/study/network-modifications.ts index 148a74c72e..d414e60e74 100644 --- a/src/services/study/network-modifications.ts +++ b/src/services/study/network-modifications.ts @@ -42,16 +42,11 @@ import { VSCModificationInfo, } from '../network-modification-types'; import { Filter } from '../../components/dialogs/network-modifications/by-filter/commons/by-filter.type'; -function getNetworkModificationUrl(studyUuid: string | null | undefined, nodeUuid: string | undefined) { +function getNetworkModificationUrl(studyUuid: UUID, nodeUuid: UUID) { return getStudyUrlWithNodeUuid(studyUuid, nodeUuid) + '/network-modifications'; } -export function changeNetworkModificationOrder( - studyUuid: UUID | null, - nodeUuid: UUID | undefined, - itemUuid: UUID, - beforeUuid: UUID -) { +export function changeNetworkModificationOrder(studyUuid: UUID, nodeUuid: UUID, itemUuid: UUID, beforeUuid: UUID) { console.info('reorder node ' + nodeUuid + ' of study ' + studyUuid + ' ...'); const url = getStudyUrlWithNodeUuid(studyUuid, nodeUuid) + @@ -63,7 +58,7 @@ export function changeNetworkModificationOrder( return backendFetch(url, { method: 'put' }); } -export function stashModifications(studyUuid: UUID | null, nodeUuid: UUID | undefined, modificationUuids: UUID[]) { +export function stashModifications(studyUuid: UUID, nodeUuid: UUID, modificationUuids: UUID[]) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('stashed', String(true)); urlSearchParams.append('uuids', String(modificationUuids)); @@ -74,12 +69,7 @@ export function stashModifications(studyUuid: UUID | null, nodeUuid: UUID | unde }); } -export function setModificationActivated( - studyUuid: UUID | null, - nodeUuid: UUID | undefined, - modificationUuid: UUID, - activated: boolean -) { +export function setModificationActivated(studyUuid: UUID, nodeUuid: UUID, modificationUuid: UUID, activated: boolean) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('activated', String(activated)); urlSearchParams.append('uuids', String([modificationUuid])); @@ -91,7 +81,7 @@ export function setModificationActivated( }); } -export function restoreModifications(studyUuid: UUID | null, nodeUuid: UUID | undefined, modificationUuids: UUID[]) { +export function restoreModifications(studyUuid: UUID, nodeUuid: UUID, modificationUuids: UUID[]) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('stashed', String(false)); urlSearchParams.append('uuids', String(modificationUuids)); @@ -103,7 +93,7 @@ export function restoreModifications(studyUuid: UUID | null, nodeUuid: UUID | un }); } -export function deleteModifications(studyUuid: UUID | null, nodeUuid: UUID | undefined, modificationUuids: UUID[]) { +export function deleteModifications(studyUuid: UUID, nodeUuid: UUID, modificationUuids: UUID[]) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('uuids', String(modificationUuids)); @@ -115,7 +105,7 @@ export function deleteModifications(studyUuid: UUID | null, nodeUuid: UUID | und }); } -export function requestNetworkChange(studyUuid: string, nodeUuid: UUID, groovyScript: string) { +export function requestNetworkChange(studyUuid: UUID, nodeUuid: UUID, groovyScript: string) { console.info('Creating groovy script (request network change)'); const changeUrl = getNetworkModificationUrl(studyUuid, nodeUuid); console.debug(changeUrl); @@ -133,8 +123,8 @@ export function requestNetworkChange(studyUuid: string, nodeUuid: UUID, groovySc } function changeOperatingStatus( - studyUuid: UUID | undefined | null, - nodeUuid: UUID | undefined, + studyUuid: UUID, + nodeUuid: UUID, equipment: Partial | null, action: string ) { @@ -168,27 +158,19 @@ function changeOperatingStatus( }); } -export function lockoutEquipment( - studyUuid: UUID | undefined, - nodeUuid: UUID | undefined, - equipment: EquipmentInfos | null -) { +export function lockoutEquipment(studyUuid: UUID, nodeUuid: UUID, equipment: EquipmentInfos | null) { console.info('locking out equipment ' + equipment?.id + ' ...'); return changeOperatingStatus(studyUuid, nodeUuid, equipment, OPERATING_STATUS_ACTION.LOCKOUT); } -export function tripEquipment( - studyUuid: UUID | undefined | null, - nodeUuid: UUID | undefined, - equipment: Partial | null -) { +export function tripEquipment(studyUuid: UUID, nodeUuid: UUID, equipment: Partial | null) { console.info('tripping equipment ' + equipment?.id + ' ...'); return changeOperatingStatus(studyUuid, nodeUuid, equipment, OPERATING_STATUS_ACTION.TRIP); } export function energiseEquipmentEnd( - studyUuid: UUID | undefined, - nodeUuid: UUID | undefined, + studyUuid: UUID, + nodeUuid: UUID, branch: EquipmentInfos | null, branchSide: string ) { @@ -203,11 +185,7 @@ export function energiseEquipmentEnd( ); } -export function switchOnEquipment( - studyUuid: UUID | undefined, - nodeUuid: UUID | undefined, - branch: EquipmentInfos | null -) { +export function switchOnEquipment(studyUuid: UUID, nodeUuid: UUID, branch: EquipmentInfos | null) { console.info('switching on branch ' + branch?.id + ' ...'); return changeOperatingStatus(studyUuid, nodeUuid, branch, OPERATING_STATUS_ACTION.SWITCH_ON); } @@ -1243,7 +1221,7 @@ export function modifyTwoWindingsTransformer({ } export function createTabulareModification( - studyUuid: string, + studyUuid: UUID, nodeUuid: UUID, modificationType: string, modifications: any, @@ -1596,7 +1574,7 @@ export function attachLine({ } export function loadScaling( - studyUuid: string, + studyUuid: UUID, nodeUuid: UUID, modificationUuid: UUID | undefined, variationType: string, @@ -1675,7 +1653,7 @@ export function linesAttachToSplitLines({ } export function deleteVoltageLevelOnLine( - studyUuid: string, + studyUuid: UUID, nodeUuid: UUID, modificationUuid: UUID, lineToAttachTo1Id: string, @@ -1747,8 +1725,8 @@ export function deleteAttachingLine({ } export function deleteEquipment( - studyUuid: string, - nodeUuid: UUID | undefined, + studyUuid: UUID, + nodeUuid: UUID, equipmentType: EquipmentType | string | null, equipmentId: string, modificationUuid: UUID | undefined, @@ -1779,8 +1757,8 @@ export function deleteEquipment( } export function deleteEquipmentByFilter( - studyUuid: string, - nodeUuid: string, + studyUuid: UUID, + nodeUuid: UUID, equipmentType: keyof typeof EQUIPMENT_TYPES | null, filters: Filter[], modificationUuid: string @@ -1808,7 +1786,7 @@ export function deleteEquipmentByFilter( }); } -export function fetchNetworkModifications(studyUuid: UUID | null, nodeUuid: string, onlyStashed: boolean) { +export function fetchNetworkModifications(studyUuid: UUID, nodeUuid: UUID, onlyStashed: boolean) { console.info('Fetching network modifications (metadata) for nodeUuid : ', nodeUuid); const urlSearchParams = new URLSearchParams(); urlSearchParams.append('onlyStashed', onlyStashed.toString()); @@ -1818,7 +1796,7 @@ export function fetchNetworkModifications(studyUuid: UUID | null, nodeUuid: stri return backendFetchJson(modificationsGetUrl); } -export function updateSwitchState(studyUuid: string, nodeUuid: UUID | undefined, switchId: string, open: boolean) { +export function updateSwitchState(studyUuid: UUID, nodeUuid: UUID, switchId: string, open: boolean) { console.info('updating switch ' + switchId + ' ...'); const updateSwitchUrl = getNetworkModificationUrl(studyUuid, nodeUuid); console.debug(updateSwitchUrl); @@ -2002,7 +1980,7 @@ export function modifyVsc({ } export function modifyByFormula( - studyUuid: string, + studyUuid: UUID, nodeUuid: UUID, equipmentType: string, formulas: any, @@ -2035,7 +2013,7 @@ export function modifyByFormula( } export function modifyByAssignment( - studyUuid: string, + studyUuid: UUID, nodeUuid: UUID, equipmentType: string, assignmentsList: Assignment[], @@ -2068,7 +2046,7 @@ export function modifyByAssignment( } export function createTabularCreation( - studyUuid: string, + studyUuid: UUID, nodeUuid: UUID, creationType: string, creations: any, diff --git a/src/services/study/network.ts b/src/services/study/network.ts index cec9d0f6ae..edf3f646a7 100644 --- a/src/services/study/network.ts +++ b/src/services/study/network.ts @@ -205,9 +205,9 @@ export async function fetchNetworkElementsInfos ) { console.info('set voltage init parameters');