@gridsuite/commons-ui 0.188.0 → 0.189.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,7 +98,7 @@ function VoltageLevelCreationForm({
98
98
  /* @__PURE__ */ jsx(
99
99
  Tab,
100
100
  {
101
- label: /* @__PURE__ */ jsx(FormattedMessage, { id: "ConnectivityTab" }),
101
+ label: /* @__PURE__ */ jsx(FormattedMessage, { id: "SubstationTab" }),
102
102
  sx: getTabStyle(tabIndexesWithError, VoltageLevelTab.SUBSTATION_TAB)
103
103
  }
104
104
  ),
@@ -2,6 +2,6 @@ import { UUID } from 'node:crypto';
2
2
  import { ContingencyCount } from './types';
3
3
  export declare function ContingencyTable({ showContingencyCount, fetchContingencyCount, isBuiltCurrentNode, }: Readonly<{
4
4
  showContingencyCount: boolean;
5
- fetchContingencyCount?: (contingencyLists: UUID[] | null) => Promise<ContingencyCount>;
5
+ fetchContingencyCount?: (contingencyLists: UUID[] | null, abortSignal: AbortSignal) => Promise<ContingencyCount>;
6
6
  isBuiltCurrentNode?: boolean;
7
7
  }>): import("react/jsx-runtime").JSX.Element;
@@ -1,16 +1,18 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import { Stack, Alert } from "@mui/material";
2
+ import { Stack, Alert, CircularProgress } from "@mui/material";
3
3
  import { useState, useCallback, useEffect } from "react";
4
4
  import { useIntl, FormattedMessage } from "react-intl";
5
5
  import { useWatch } from "react-hook-form";
6
6
  import "../../../../utils/conversionUtils.js";
7
+ import { snackWithFallback } from "../../../../utils/error.js";
7
8
  import "../../../../utils/types/equipmentType.js";
8
9
  import "@mui/icons-material";
9
10
  import "../../../../utils/yupConfig.js";
11
+ import { DEFAULT_TIMEOUT_MS, IGNORE_SIGNAL } from "../../../../services/utils.js";
10
12
  import "localized-countries";
11
13
  import "localized-countries/data/fr";
12
14
  import "localized-countries/data/en";
13
- import "notistack";
15
+ import { useSnackMessage } from "../../../../hooks/useSnackMessage.js";
14
16
  import { useCreateRowData } from "../../../../hooks/use-create-row-data.js";
15
17
  import { ACTIVATED, ID } from "../parameter-table/constants.js";
16
18
  import { ParameterTable } from "../parameter-table/parameter-table.js";
@@ -25,6 +27,8 @@ function ContingencyTable({
25
27
  const [simulatedContingencyCount, setSimulatedContingencyCount] = useState(null);
26
28
  const [rowData, useFieldArrayOutput] = useCreateRowData(ParamContingencyLists);
27
29
  const contingencyListsInfos = useWatch({ name: CONTINGENCY_LISTS_INFOS });
30
+ const [isLoading, setIsLoading] = useState(false);
31
+ const { snackError } = useSnackMessage();
28
32
  const getColumnsDefinition = useCallback(
29
33
  (columns) => {
30
34
  if (columns) {
@@ -38,27 +42,60 @@ function ContingencyTable({
38
42
  [intl]
39
43
  );
40
44
  useEffect(() => {
41
- if (showContingencyCount) {
42
- const hasNoContingencies = !contingencyListsInfos || (contingencyListsInfos.length ?? 0) === 0 || contingencyListsInfos.every(
43
- (contingencyList) => (contingencyList[CONTINGENCY_LISTS]?.length ?? 0) === 0
44
- );
45
- if (hasNoContingencies) {
46
- setSimulatedContingencyCount(null);
45
+ if (!showContingencyCount || !isBuiltCurrentNode) {
46
+ setIsLoading(false);
47
+ return () => {
48
+ };
49
+ }
50
+ const hasNoContingencies = !contingencyListsInfos || (contingencyListsInfos.length ?? 0) === 0 || contingencyListsInfos.every(
51
+ (contingencyList) => !contingencyList[ACTIVATED] || (contingencyList[CONTINGENCY_LISTS]?.length ?? 0) === 0
52
+ );
53
+ if (hasNoContingencies) {
54
+ setIsLoading(false);
55
+ setSimulatedContingencyCount(null);
56
+ return () => {
57
+ };
58
+ }
59
+ let loadingTimeoutId;
60
+ const controller = new AbortController();
61
+ const abortSignal = AbortSignal.any([controller.signal, AbortSignal.timeout(DEFAULT_TIMEOUT_MS)]);
62
+ setIsLoading(true);
63
+ fetchContingencyCount?.(
64
+ contingencyListsInfos.filter((lists) => lists[ACTIVATED]).flatMap((lists) => lists[CONTINGENCY_LISTS]?.map((contingencyList) => contingencyList[ID])),
65
+ abortSignal
66
+ ).then((contingencyCount) => {
67
+ setSimulatedContingencyCount(contingencyCount);
68
+ loadingTimeoutId = setTimeout(() => {
69
+ setIsLoading(false);
70
+ }, 500);
71
+ }).catch((error) => {
72
+ setSimulatedContingencyCount(null);
73
+ if (abortSignal.aborted && abortSignal.reason?.message === IGNORE_SIGNAL) {
47
74
  return;
48
75
  }
49
- fetchContingencyCount?.(
50
- contingencyListsInfos.filter((lists) => lists[ACTIVATED]).flatMap((lists) => lists[CONTINGENCY_LISTS]?.map((contingencyList) => contingencyList[ID]))
51
- ).then((contingencyCount) => {
52
- setSimulatedContingencyCount(contingencyCount);
53
- }).catch(() => {
54
- setSimulatedContingencyCount(null);
55
- });
56
- }
57
- }, [contingencyListsInfos, fetchContingencyCount, showContingencyCount]);
76
+ setIsLoading(false);
77
+ snackWithFallback(snackError, error, { headerId: "getSecurityAnalysisContingenciesCountError" });
78
+ });
79
+ return () => {
80
+ controller?.abort(new Error(IGNORE_SIGNAL));
81
+ clearTimeout(loadingTimeoutId);
82
+ };
83
+ }, [snackError, contingencyListsInfos, fetchContingencyCount, showContingencyCount, isBuiltCurrentNode]);
58
84
  const renderContingencyCount = () => {
59
85
  if (!isBuiltCurrentNode) {
60
86
  return /* @__PURE__ */ jsx(Alert, { variant: "standard", severity: "warning", sx: { color: "text.primary" }, children: /* @__PURE__ */ jsx(FormattedMessage, { id: "contingencyCountImpossibleOnUnbuiltNode" }) });
61
87
  }
88
+ if (isLoading) {
89
+ return /* @__PURE__ */ jsx(
90
+ Alert,
91
+ {
92
+ variant: "standard",
93
+ icon: /* @__PURE__ */ jsx(CircularProgress, { size: 22 }),
94
+ severity: "info",
95
+ sx: { color: "text.primary" }
96
+ }
97
+ );
98
+ }
62
99
  if (simulatedContingencyCount?.contingencies === 0 && simulatedContingencyCount.notFoundElements === 0) {
63
100
  return /* @__PURE__ */ jsx(Alert, { variant: "standard", severity: "error", sx: { color: "text.primary" }, children: /* @__PURE__ */ jsx(FormattedMessage, { id: "noContingency" }) });
64
101
  }
@@ -5,7 +5,7 @@ import { ContingencyCount } from '../common/contingency-table/types';
5
5
  export declare function SecurityAnalysisParametersForm({ securityAnalysisMethods, showContingencyCount, fetchContingencyCount, isBuiltCurrentNode, renderTitleFields, renderActions, isDeveloperMode, }: Readonly<{
6
6
  securityAnalysisMethods: UseSecurityAnalysisParametersFormReturn;
7
7
  showContingencyCount: boolean;
8
- fetchContingencyCount?: (contingencyListIds: UUID[] | null) => Promise<ContingencyCount>;
8
+ fetchContingencyCount?: (contingencyListIds: UUID[] | null, abortSignal: AbortSignal) => Promise<ContingencyCount>;
9
9
  isBuiltCurrentNode?: boolean;
10
10
  renderTitleFields?: () => ReactNode;
11
11
  renderActions?: () => ReactNode;
@@ -5,7 +5,7 @@ import { ContingencyCount } from '../common/contingency-table/types';
5
5
  export declare function SecurityAnalysisParametersInline({ studyUuid, parametersBackend, fetchContingencyCount, isBuiltCurrentNode, setHaveDirtyFields, isDeveloperMode, }: Readonly<{
6
6
  studyUuid: UUID | null;
7
7
  parametersBackend: UseParametersBackendReturnProps<ComputingType.SECURITY_ANALYSIS>;
8
- fetchContingencyCount: (contingencyListIds: UUID[] | null) => Promise<ContingencyCount>;
8
+ fetchContingencyCount: (contingencyListIds: UUID[] | null, abortSignal: AbortSignal) => Promise<ContingencyCount>;
9
9
  isBuiltCurrentNode: boolean;
10
10
  setHaveDirtyFields: (isDirty: boolean) => void;
11
11
  isDeveloperMode: boolean;
@@ -143,6 +143,7 @@ export declare const networkModificationsEn: {
143
143
  Side1: string;
144
144
  Side2: string;
145
145
  Or: string;
146
+ SubstationTab: string;
146
147
  ConnectivityTab: string;
147
148
  CharacteristicsTab: string;
148
149
  StructureTab: string;
@@ -150,6 +150,7 @@ const networkModificationsEn = {
150
150
  Side2: "Side 2",
151
151
  Or: "or",
152
152
  // Tabs
153
+ SubstationTab: "Substation",
153
154
  ConnectivityTab: "Connectivity",
154
155
  CharacteristicsTab: "Characteristics",
155
156
  StructureTab: "Structure",
@@ -248,6 +248,7 @@ export declare const parametersEn: {
248
248
  fetchSecurityAnalysisParametersError: string;
249
249
  fetchSecurityAnalysisProvidersError: string;
250
250
  updateSecurityAnalysisParametersError: string;
251
+ getSecurityAnalysisContingenciesCountError: string;
251
252
  fetchSensitivityAnalysisParametersError: string;
252
253
  fetchSensitivityAnalysisProvidersError: string;
253
254
  updateSensitivityAnalysisParametersError: string;
@@ -245,6 +245,7 @@ const parametersEn = {
245
245
  fetchSecurityAnalysisParametersError: "An error occured when fetching the security analysis parameters",
246
246
  fetchSecurityAnalysisProvidersError: "An error occured when fetching security analysis provider list",
247
247
  updateSecurityAnalysisParametersError: "An error occurred while updating the security analysis parameters",
248
+ getSecurityAnalysisContingenciesCountError: "An error occurred while estimating security analysis contingencies count",
248
249
  // SensitivityAnalysis
249
250
  fetchSensitivityAnalysisParametersError: "An error occured when fetching the sensitivity analysis parameters",
250
251
  fetchSensitivityAnalysisProvidersError: "An error occured when fetching sensitivity analysis provider list",
@@ -143,6 +143,7 @@ export declare const networkModificationsFr: {
143
143
  Side1: string;
144
144
  Side2: string;
145
145
  Or: string;
146
+ SubstationTab: string;
146
147
  ConnectivityTab: string;
147
148
  CharacteristicsTab: string;
148
149
  StructureTab: string;
@@ -150,6 +150,7 @@ const networkModificationsFr = {
150
150
  Side2: "Côté 2",
151
151
  Or: "ou",
152
152
  // Tabs
153
+ SubstationTab: "Site",
153
154
  ConnectivityTab: "Connectivité",
154
155
  CharacteristicsTab: "Caractéristiques",
155
156
  StructureTab: "Structure",
@@ -248,6 +248,7 @@ export declare const parametersFr: {
248
248
  fetchSecurityAnalysisParametersError: string;
249
249
  fetchSecurityAnalysisProvidersError: string;
250
250
  updateSecurityAnalysisParametersError: string;
251
+ getSecurityAnalysisContingenciesCountError: string;
251
252
  fetchSensitivityAnalysisParametersError: string;
252
253
  fetchSensitivityAnalysisProvidersError: string;
253
254
  updateSensitivityAnalysisParametersError: string;
@@ -245,6 +245,7 @@ const parametersFr = {
245
245
  fetchSecurityAnalysisParametersError: "Une erreur est survenue lors de la récupération des paramètres de l'analyse de sécurité",
246
246
  fetchSecurityAnalysisProvidersError: "Une erreur est survenue lors de la récupération des fournisseurs d'analyse de sécurité",
247
247
  updateSecurityAnalysisParametersError: "Une erreur est survenue lors de la mise a jour des paramètres de l'analyse de sécurité",
248
+ getSecurityAnalysisContingenciesCountError: "Une erreur est survenue lors de l'estimation du nombre d'aléas de l'analyse de sécurité",
248
249
  // SensitivityAnalysis
249
250
  fetchSensitivityAnalysisParametersError: "Une erreur est survenue lors de la récupération des paramètres de l'analyse de sensibilité",
250
251
  fetchSensitivityAnalysisProvidersError: "Une erreur est survenue lors de la récupération des fournisseurs d'analyse de sensibilité",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.188.0",
3
+ "version": "0.189.0",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "author": "gridsuite team",
6
6
  "homepage": "https://github.com/gridsuite",