Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -18,8 +18,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { AppState } from '../../../../../redux/reducer.type';
import { useBaseVoltages } from '../../../../../hooks/use-base-voltages';
import { addToGlobalFilterOptions } from '../../../../../redux/actions';
import { fetchNetworkExistence } from 'services/study/network';
import { HttpStatusCode } from 'utils/http-status-code';
import { fetchNetworkExistence, RootNetworkExistence } from 'services/study/network';

/**
* Custom hook that manages global filter options for tables.
Expand Down Expand Up @@ -58,9 +57,9 @@ export const useGlobalFilterOptions = () => {
if (!studyUuid || !currentNode?.id || !currentRootNetworkUuid) return;

try {
const response = await fetchNetworkExistence(studyUuid, currentRootNetworkUuid);
const response: RootNetworkExistence = await fetchNetworkExistence(studyUuid, currentRootNetworkUuid);

if (response.status === HttpStatusCode.OK) {
if (response?.exists) {
const countryCodes = await fetchAllCountries(studyUuid, currentNode.id, currentRootNetworkUuid);

const newCountriesFilter = countryCodes
Expand Down
107 changes: 56 additions & 51 deletions src/components/study-container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ import { useAllComputingStatus } from './computing-status/use-all-computing-stat
import { fetchNetworkModificationTree } from '../services/study/tree-subtree';
import { useTreeModelSync } from '../hooks/use-tree-model-sync';
import { useNodeActivitySync } from 'components/node-activity/hooks/use-node-activity-sync';
import { fetchNetworkExistence, fetchRootNetworkIndexationStatus } from '../services/study/network';
import {
fetchNetworkExistence,
fetchRootNetworkIndexationStatus,
RootNetworkLoadStatus,
} from '../services/study/network';
import { fetchStudy, recreateStudyNetwork, reindexAllRootNetwork } from 'services/study/study';

import { HttpStatusCode } from 'utils/http-status-code';
Expand Down Expand Up @@ -163,7 +167,7 @@ export function StudyContainer() {

useAllComputingStatus(studyUuid, currentNode?.id, currentRootNetworkUuid);

const { snackError, snackWarning, snackInfo } = useSnackMessage();
const { snackError, snackWarning, snackInfo, snackSuccess } = useSnackMessage();

useExportNotification();
useTreeModelSync(studyUuid);
Expand Down Expand Up @@ -400,51 +404,57 @@ export function StudyContainer() {
}, [studyUuid, currentRootNetworkUuid, dispatch, snackError]);

const checkNetworkExistenceAndRecreateIfNotFound = useCallback(
(successCallback) => {
fetchNetworkExistence(studyUuid, currentRootNetworkUuid)
.then((response) => {
if (response.status === HttpStatusCode.OK) {
successCallback && successCallback();
checkRootNetworkIndexation().then(loadTree);
} else {
// response.state === NO_CONTENT
// if network is not found, we try to recreate study network from existing case
recreateStudyNetwork(studyUuid, currentRootNetworkUuid)
.then(() => {
snackWarning({
headerId: 'recreatingNetworkStudy',
persist: true,
});
})
.catch((error) => {
if (error.status === HttpStatusCode.FAILED_DEPENDENCY) {
// when trying to recreate study network, if case can't be found (424 error), we display an error
setErrorMessage(
intlRef.current.formatMessage({
id: 'invalidStudyError',
})
);
} else {
// unknown error when trying to recreate network from study case
setErrorMessage(
intlRef.current.formatMessage({
id: 'networkRecreationError',
})
);
}
async (successCallback) => {
try {
const existence = await fetchNetworkExistence(studyUuid, currentRootNetworkUuid);
if (existence?.exists) {
successCallback?.();
const status = await checkRootNetworkIndexation();
loadTree(status);
} else {
// response.state === NO_CONTENT
// if network is not found, we try to recreate study network from existing case
try {
await recreateStudyNetwork(studyUuid, currentRootNetworkUuid);
if (existence?.rootNetworkLoadStatus === RootNetworkLoadStatus.UNLOADED) {
snackInfo({
headerId: 'networkStudyUnloadedInactivity',
Comment thread
ghazwarhili marked this conversation as resolved.
Outdated
persist: true,
});
} else {
snackWarning({
headerId: 'recreatingNetworkStudy',
persist: true,
});
}
} catch (error) {
if (error.status === HttpStatusCode.FAILED_DEPENDENCY) {
// when trying to recreate study network, if case can't be found (424 error), we display an error
setErrorMessage(
intlRef.current.formatMessage({
id: 'invalidStudyError',
})
);
} else {
// unknown error when trying to recreate network from study case
setErrorMessage(
intlRef.current.formatMessage({
id: 'networkRecreationError',
})
);
}
}
})
.catch(() => {
// unknown error when checking network existence
setErrorMessage(
intlRef.current.formatMessage({
id: 'checkNetworkExistenceError',
})
);
});
}
} catch {
// unknown error when checking network existence
setErrorMessage(
intlRef.current.formatMessage({
id: 'checkNetworkExistenceError',
})
);
}
},
[studyUuid, currentRootNetworkUuid, checkRootNetworkIndexation, loadTree, snackWarning, intlRef]
[studyUuid, currentRootNetworkUuid, checkRootNetworkIndexation, loadTree, snackInfo, snackWarning, intlRef]
);

useEffect(() => {
Expand All @@ -467,11 +477,6 @@ export function StudyContainer() {
return;
}
dispatch(setRootNetworkIndexationStatus(eventData.headers.indexation_status));
if (eventData.headers.indexation_status === RootNetworkIndexationStatus.INDEXED) {
Comment thread
ghazwarhili marked this conversation as resolved.
snackInfo({
headerId: 'rootNetworkIndexationDone',
});
}
// notification that the study is not indexed anymore then ask to refresh
if (eventData.headers.indexation_status === RootNetworkIndexationStatus.NOT_INDEXED) {
snackWarning({
Expand All @@ -481,7 +486,7 @@ export function StudyContainer() {
}
if (isStudyNetworkRecreationNotification(eventData)) {
const successCallback = () =>
snackInfo({
snackSuccess({
headerId: 'studyNetworkRecovered',
});

Expand All @@ -494,7 +499,7 @@ export function StudyContainer() {
}
}
},
[checkNetworkExistenceAndRecreateIfNotFound, snackInfo, snackWarning, dispatch]
[dispatch, snackWarning, checkNetworkExistenceAndRecreateIfNotFound, snackSuccess]
);

useNotificationsListener(NotificationsUrlKeys.STUDY, {
Expand Down
15 changes: 13 additions & 2 deletions src/services/study/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,21 @@ export function fetchVoltageLevelsMapInfos(
);
}

export const fetchNetworkExistence = (studyUuid: UUID, rootNetworkUuid: UUID) => {
export enum RootNetworkLoadStatus {
LOADED = 'LOADED',
UNLOADED = 'UNLOADED',
UNLOADING = 'UNLOADING',
}

export interface RootNetworkExistence {
exists: boolean;
rootNetworkLoadStatus: RootNetworkLoadStatus;
}

export const fetchNetworkExistence = (studyUuid: UUID, rootNetworkUuid: UUID): Promise<RootNetworkExistence> => {
const fetchNetworkExistenceUrl = `${PREFIX_STUDY_QUERIES}/v1/studies/${studyUuid}/root-networks/${rootNetworkUuid}/network`;

return backendFetch(fetchNetworkExistenceUrl, { method: 'HEAD' });
return backendFetchJson(fetchNetworkExistenceUrl, { method: 'GET' });
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};

export const fetchRootNetworkIndexationStatus = (studyUuid: UUID, rootNetworkUuid: UUID) => {
Expand Down
2 changes: 1 addition & 1 deletion src/translations/messages-en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ const messages_en = {
GeneratorAvailability: 'Generator availability',
chooseElement: 'Choose element',
studyNetworkRecovered: 'Study network has been recreated successfully',
networkStudyUnloadedInactivity: 'Due to a period of inactivity, this study has been unloaded',
recreatingNetworkStudy:
'Impossible to get the study network. Reconstruction of the network from the initial situation...',
invalidStudyError: 'Invalid study : Root situation can not be found',
Expand Down Expand Up @@ -987,7 +988,6 @@ const messages_en = {
ShortcircuitInProgress: 'Shortcircuit computation in progress...',

tableChangingError: 'An error occurred when modifying the data',
rootNetworkIndexationDone: 'Root Network indexation done. Search functionality is now available',
rootNetworkIndexationNotIndexed:
"Serverside warning: Something went wrong, Study equipments aren't indexed anymore. Please refresh the page (F5)",
rootNetworkIndexationError: 'Root Network indexation process has failed.',
Expand Down
3 changes: 1 addition & 2 deletions src/translations/messages-fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ const messages_fr = {
GeneratorAvailability: 'Indisponibilité groupes',
chooseElement: 'Choisir un element',
studyNetworkRecovered: "Le réseau de l'étude a été réimporté avec succès",
networkStudyUnloadedInactivity: "En raison d'une période d'inactivité, cette étude a été déchargée",
recreatingNetworkStudy:
"Impossible de récupérer le réseau de l'étude. Reconstruction du réseau à partir de la situation initiale...",
invalidStudyError: 'Étude invalide : la situation racine est introuvable',
Expand Down Expand Up @@ -1000,8 +1001,6 @@ const messages_fr = {
ShortcircuitInProgress: 'Calcul de court-circuit en cours...',

tableChangingError: 'Une erreur est survenue lors de la modification des données',
rootNetworkIndexationDone:
"L'indexation de réseau racine est terminée. La fonctionnalité de recherche est disponible",
rootNetworkIndexationNotIndexed:
"Alerte côté serveur :Un incident s'est produit, les équipements de l'étude ne sont plus indexés. Merci de rafraîchir la page (F5)",
rootNetworkIndexationError: "L'indexation de réseau racine a échoué.",
Expand Down
Loading