Skip to content
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

Fix console error : "uncaught (in promise) undefined" #2458

Open
wants to merge 3 commits 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
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
23 changes: 16 additions & 7 deletions src/components/dialogs/parameters/network-parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,32 @@ import { LabelledButton, styles, useParameterState } from './parameters';
import ParameterLineDropdown from './widget/parameter-line-dropdown';
import ParameterLineSwitch from './widget/parameter-line-switch';
import LineSeparator from '../commons/line-separator';
import { useSnackMessage } from '@gridsuite/commons-ui';

export enum FluxConventions {
IIDM = 'iidm',
TARGET = 'target',
}

export const NetworkParameters = () => {
const { snackError } = useSnackMessage();
const [, handleChangeFluxConvention] = useParameterState(PARAM_FLUX_CONVENTION);
const [enableDeveloperMode, handleChangeEnableDeveloperMode] = useParameterState(PARAM_DEVELOPER_MODE);
const resetNetworkParameters = () => {
fetchDefaultParametersValues().then((defaultValues) => {
const defaultFluxConvention = defaultValues.fluxConvention;
if (Object.values(FluxConventions).includes(defaultFluxConvention)) {
handleChangeFluxConvention(defaultFluxConvention);
}
handleChangeEnableDeveloperMode(defaultValues?.enableDeveloperMode ?? false);
});
fetchDefaultParametersValues()
.then((defaultValues) => {
const defaultFluxConvention = defaultValues.fluxConvention;
if (Object.values(FluxConventions).includes(defaultFluxConvention)) {
handleChangeFluxConvention(defaultFluxConvention);
}
handleChangeEnableDeveloperMode(defaultValues?.enableDeveloperMode ?? false);
})
.catch((error) => {
snackError({
messageTxt: error.message,
headerId: 'paramsRetrievingError',
});
});
};

return (
Expand Down
38 changes: 24 additions & 14 deletions src/components/network/network-map-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,11 @@ export const NetworkMapTab = ({
const reloadMapEquipments = useCallback(
(currentNodeAtReloadCalling: CurrentTreeNode | null, substationsIds: UUID[] | undefined) => {
if (!isNodeBuilt(currentNode) || !studyUuid || !mapEquipments) {
return Promise.reject();
return Promise.reject(
new Error(
'reloadMapEquipments error: currentNode not build or studyUuid undefined or mapEquipments not initialized'
)
);
}

const { updatedSubstations, updatedLines, updatedTieLines, updatedHvdcLines } = mapEquipments
Expand Down Expand Up @@ -701,11 +705,6 @@ export const NetworkMapTab = ({

const updateMapEquipments = useCallback(
(currentNodeAtReloadCalling: CurrentTreeNode | null) => {
if (!isNodeBuilt(currentNode) || !studyUuid || !mapEquipments) {
dispatch(resetMapReloaded());
return Promise.reject();
}

const mapEquipmentsTypes = [
EquipmentType.SUBSTATION,
EquipmentType.LINE,
Expand Down Expand Up @@ -734,37 +733,48 @@ export const NetworkMapTab = ({
dispatch(resetMapReloaded());
resetImpactedElementTypes();
resetImpactedSubstationsIds();
return reloadMapEquipments(currentNodeAtReloadCalling, updatedSubstationsToSend);
return reloadMapEquipments(currentNodeAtReloadCalling, updatedSubstationsToSend).catch((e) =>
snackError({
messageTxt: e.message,
})
);
},
[
currentNode,
studyUuid,
mapEquipments,
impactedElementTypes,
impactedSubstationsIds,
dispatch,
resetImpactedElementTypes,
resetImpactedSubstationsIds,
reloadMapEquipments,
snackError,
]
);

const updateMapEquipmentsAndGeoData = useCallback(() => {
const currentNodeAtReloadCalling = currentNodeRef.current;
updateMapEquipments(currentNodeAtReloadCalling)?.then(() => {
if (!isNodeBuilt(currentNode) || !studyUuid || !mapEquipments) {
dispatch(resetMapReloaded());
return;
}

updateMapEquipments(currentNodeAtReloadCalling).then(() => {
if (checkNodeConsistency(currentNodeAtReloadCalling)) {
loadGeoData();
}
});
}, [loadGeoData, updateMapEquipments]);
}, [currentNode, dispatch, loadGeoData, mapEquipments, studyUuid, updateMapEquipments]);

useEffect(() => {
if (isInitialized && studyUpdatedForce.eventData.headers) {
if (studyUpdatedForce.eventData.headers[UPDATE_TYPE_HEADER] === 'loadflowResult') {
reloadMapEquipments(currentNodeRef.current, undefined);
reloadMapEquipments(currentNodeRef.current, undefined).catch((e) =>
snackError({
messageTxt: e.message,
})
);
}
}
}, [isInitialized, studyUpdatedForce, reloadMapEquipments]);
}, [isInitialized, studyUpdatedForce, reloadMapEquipments, snackError]);

useEffect(() => {
if (!mapEquipments || refIsMapManualRefreshEnabled.current) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const fetchDefaultParametersValues = () => {
console.info('fecthing default parameters values from apps-metadata file');
const studyMetadata = res.find((metadata) => metadata.name === 'Study');
if (!studyMetadata) {
return Promise.reject('Study entry could not be found in metadatas');
return Promise.reject(new Error('Study entry could not be found in metadatas'));
}

return studyMetadata.defaultParametersValues;
Expand Down
Loading