@gridsuite/commons-ui 0.244.0 → 0.245.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.
@@ -70,6 +70,7 @@ import { CustomMenuItem, CustomNestedMenuItem } from "./ui/menus/custom-nested-m
70
70
  import { ResizeHandle } from "./ui/resizablePanels/ResizeHandle.js";
71
71
  import { CsvExport } from "./ui/csvDownloader/csv-export.js";
72
72
  import { ExportCsvButton } from "./ui/csvDownloader/export-csv-button.js";
73
+ import { ManagedExportCsvButton } from "./ui/csvDownloader/managed-export-csv-button.js";
73
74
  import { fetchCsvSeparator, useCsvExport } from "./ui/csvDownloader/use-csv-export.js";
74
75
  import { CsvPicker } from "./ui/csvPicker/csv-picker.js";
75
76
  import { TreeViewFinder, generateTreeViewFinderClass } from "./ui/treeViewFinder/TreeViewFinder.js";
@@ -269,6 +270,7 @@ export {
269
270
  LeftPanelOpenIcon,
270
271
  default2 as LogTable,
271
272
  MAX_ROWS_NUMBER,
273
+ ManagedExportCsvButton,
272
274
  MessageLogCellRenderer,
273
275
  MidFormError,
274
276
  ModifyElementSelection,
@@ -1,3 +1,3 @@
1
1
  import { JSX } from 'react';
2
2
  import { CsvExportProps } from './csv-export.type';
3
- export declare function CsvExport({ columns, tableNamePrefix, tableName, disabled, skipColumnHeaders, skipPinnedBottom, language, getData, }: CsvExportProps): JSX.Element;
3
+ export declare function CsvExport({ columns, tableNamePrefix, tableName, disabled, skipColumnHeaders, skipPinnedBottom, language, getData, resetKey, }: CsvExportProps): JSX.Element;
@@ -1,7 +1,7 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useCallback } from "react";
3
3
  import { useCsvExport } from "./use-csv-export.js";
4
- import { ExportCsvButton } from "./export-csv-button.js";
4
+ import { ManagedExportCsvButton } from "./managed-export-csv-button.js";
5
5
  function CsvExport({
6
6
  columns,
7
7
  tableNamePrefix = "",
@@ -10,11 +10,12 @@ function CsvExport({
10
10
  skipColumnHeaders = false,
11
11
  skipPinnedBottom = false,
12
12
  language,
13
- getData
13
+ getData,
14
+ resetKey
14
15
  }) {
15
16
  const csvExport = useCsvExport();
16
- const download = useCallback(() => {
17
- csvExport.getData({
17
+ const exportCsv = useCallback(async () => {
18
+ await csvExport.getData({
18
19
  columns,
19
20
  tableName,
20
21
  tableNamePrefix,
@@ -24,7 +25,7 @@ function CsvExport({
24
25
  getData
25
26
  });
26
27
  }, [columns, csvExport, tableName, tableNamePrefix, skipColumnHeaders, skipPinnedBottom, language, getData]);
27
- return /* @__PURE__ */ jsx(ExportCsvButton, { disabled, onClick: download });
28
+ return /* @__PURE__ */ jsx(ManagedExportCsvButton, { disabled, exportCsv, resetKey });
28
29
  }
29
30
  export {
30
31
  CsvExport
@@ -1,4 +1,5 @@
1
1
  import { ColDef, CsvExportParams } from 'ag-grid-community';
2
+ import { Key } from 'react';
2
3
  import { GsLangUser } from '../../../utils';
3
4
  export type CsvDownloadProps = {
4
5
  columns: ColDef[];
@@ -9,6 +10,7 @@ export type CsvDownloadProps = {
9
10
  language: GsLangUser;
10
11
  getData: (params?: CsvExportParams) => string | undefined | void;
11
12
  isCopyCsv?: boolean;
13
+ resetKey?: Key;
12
14
  };
13
15
  export type CsvExportProps = CsvDownloadProps & {
14
16
  disabled: boolean;
@@ -7,4 +7,5 @@
7
7
  export * from './csv-export';
8
8
  export * from './csv-export.type';
9
9
  export * from './export-csv-button';
10
+ export * from './managed-export-csv-button';
10
11
  export * from './use-csv-export';
@@ -1,9 +1,11 @@
1
1
  import { CsvExport } from "./csv-export.js";
2
2
  import { ExportCsvButton } from "./export-csv-button.js";
3
+ import { ManagedExportCsvButton } from "./managed-export-csv-button.js";
3
4
  import { fetchCsvSeparator, useCsvExport } from "./use-csv-export.js";
4
5
  export {
5
6
  CsvExport,
6
7
  ExportCsvButton,
8
+ ManagedExportCsvButton,
7
9
  fetchCsvSeparator,
8
10
  useCsvExport
9
11
  };
@@ -0,0 +1,8 @@
1
+ export interface ManagedExportCsvButtonProps {
2
+ disabled?: boolean;
3
+ exportCsv: () => Promise<void>;
4
+ resetKey?: unknown;
5
+ onSuccess?: () => void;
6
+ onError?: (error: unknown) => void;
7
+ }
8
+ export declare function ManagedExportCsvButton({ disabled, exportCsv, resetKey, onSuccess, onError, }: Readonly<ManagedExportCsvButtonProps>): import("react").JSX.Element;
@@ -0,0 +1,48 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useState, useEffect, useCallback } from "react";
3
+ import { ExportCsvButton } from "./export-csv-button.js";
4
+ function ManagedExportCsvButton({
5
+ disabled = false,
6
+ exportCsv,
7
+ resetKey,
8
+ onSuccess,
9
+ onError
10
+ }) {
11
+ const [isLoading, setIsLoading] = useState(false);
12
+ const [isSuccessful, setIsSuccessful] = useState(false);
13
+ useEffect(() => {
14
+ setIsLoading(false);
15
+ setIsSuccessful(false);
16
+ }, [resetKey]);
17
+ useEffect(() => {
18
+ if (disabled) {
19
+ setIsSuccessful(false);
20
+ }
21
+ }, [disabled]);
22
+ const handleClick = useCallback(async () => {
23
+ setIsSuccessful(false);
24
+ setIsLoading(true);
25
+ try {
26
+ await exportCsv();
27
+ setIsSuccessful(true);
28
+ onSuccess?.();
29
+ } catch (error) {
30
+ setIsSuccessful(false);
31
+ onError?.(error);
32
+ } finally {
33
+ setIsLoading(false);
34
+ }
35
+ }, [exportCsv, onSuccess, onError]);
36
+ return /* @__PURE__ */ jsx(
37
+ ExportCsvButton,
38
+ {
39
+ disabled: disabled || isLoading,
40
+ onClick: handleClick,
41
+ isDownloadLoading: isLoading,
42
+ isDownloadSuccessful: isSuccessful
43
+ }
44
+ );
45
+ }
46
+ export {
47
+ ManagedExportCsvButton
48
+ };
@@ -70,6 +70,7 @@ import { CustomMenuItem, CustomNestedMenuItem } from "./menus/custom-nested-menu
70
70
  import { ResizeHandle } from "./resizablePanels/ResizeHandle.js";
71
71
  import { CsvExport } from "./csvDownloader/csv-export.js";
72
72
  import { ExportCsvButton } from "./csvDownloader/export-csv-button.js";
73
+ import { ManagedExportCsvButton } from "./csvDownloader/managed-export-csv-button.js";
73
74
  import { fetchCsvSeparator, useCsvExport } from "./csvDownloader/use-csv-export.js";
74
75
  import { CsvPicker } from "./csvPicker/csv-picker.js";
75
76
  import { TreeViewFinder, generateTreeViewFinderClass } from "./treeViewFinder/TreeViewFinder.js";
@@ -127,6 +128,7 @@ export {
127
128
  IntegerInput,
128
129
  LeftPanelCloseIcon,
129
130
  LeftPanelOpenIcon,
131
+ ManagedExportCsvButton,
130
132
  MidFormError,
131
133
  ModifyElementSelection,
132
134
  MuiSelectInput,
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import { Stack, Box, Grid2, ButtonGroup, Tooltip, LinearProgress } from "@mui/material";
2
+ import { Stack, Grid2, Typography, ButtonGroup, Tooltip, Box, LinearProgress } from "@mui/material";
3
3
  import { Upload, RestartAlt } from "@mui/icons-material";
4
4
  import { useState, useCallback } from "react";
5
5
  import { useIntl, FormattedMessage } from "react-intl";
@@ -78,29 +78,32 @@ function ParameterLayout({
78
78
  }, []);
79
79
  const intl = useIntl();
80
80
  return /* @__PURE__ */ jsxs(Stack, { sx: styles.stack, children: [
81
- (title || selectParameterHandler || resetHandler) && /* @__PURE__ */ jsx(Box, { sx: styles.title, children: /* @__PURE__ */ jsxs(Grid2, { container: true, sx: { alignItems: "center", justifyContent: "space-between" }, children: [
82
- /* @__PURE__ */ jsx(Grid2, { size: 4, children: title && !isXsScreen && /* @__PURE__ */ jsx(FormattedMessage, { id: title }) }),
83
- /* @__PURE__ */ jsx(Grid2, { size: "auto", children: /* @__PURE__ */ jsxs(ButtonGroup, { children: [
84
- selectParameterHandler && /* @__PURE__ */ jsx(
85
- LabelledButton,
86
- {
87
- callback: handlePrefillClick,
88
- label: "button.prefill",
89
- "data-testid": "PrefillButton",
90
- startIcon: /* @__PURE__ */ jsx(Upload, {})
91
- }
92
- ),
93
- resetHandler && /* @__PURE__ */ jsx(Tooltip, { title: /* @__PURE__ */ jsx(FormattedMessage, { id: "tooltip.reset" }), children: /* @__PURE__ */ jsx(
94
- LabelledButton,
95
- {
96
- callback: handleResetClick,
97
- label: "button.reset",
98
- "data-testid": "ResetButton",
99
- startIcon: /* @__PURE__ */ jsx(RestartAlt, {})
100
- }
101
- ) })
102
- ] }) })
103
- ] }) }),
81
+ (title || selectParameterHandler || resetHandler) && /* @__PURE__ */ jsxs(Stack, { sx: styles.title, children: [
82
+ /* @__PURE__ */ jsxs(Grid2, { container: true, sx: { alignItems: "center", justifyContent: "space-between" }, paddingBottom: 1, children: [
83
+ /* @__PURE__ */ jsx(Grid2, { size: "auto", children: title && !isXsScreen && /* @__PURE__ */ jsx(Typography, { variant: "h6", children: /* @__PURE__ */ jsx(FormattedMessage, { id: title }) }) }),
84
+ /* @__PURE__ */ jsx(Grid2, { size: "auto", children: /* @__PURE__ */ jsxs(ButtonGroup, { children: [
85
+ selectParameterHandler && /* @__PURE__ */ jsx(
86
+ LabelledButton,
87
+ {
88
+ callback: handlePrefillClick,
89
+ label: "button.prefill",
90
+ "data-testid": "PrefillButton",
91
+ startIcon: /* @__PURE__ */ jsx(Upload, {})
92
+ }
93
+ ),
94
+ resetHandler && /* @__PURE__ */ jsx(Tooltip, { title: /* @__PURE__ */ jsx(FormattedMessage, { id: "tooltip.reset" }), children: /* @__PURE__ */ jsx(
95
+ LabelledButton,
96
+ {
97
+ callback: handleResetClick,
98
+ label: "button.reset",
99
+ "data-testid": "ResetButton",
100
+ startIcon: /* @__PURE__ */ jsx(RestartAlt, {})
101
+ }
102
+ ) })
103
+ ] }) })
104
+ ] }),
105
+ /* @__PURE__ */ jsx(LineSeparator, {})
106
+ ] }),
104
107
  /* @__PURE__ */ jsx(Box, { sx: styles.content, children: isLoading ? /* @__PURE__ */ jsx(LinearProgress, {}) : children }),
105
108
  /* @__PURE__ */ jsxs(Stack, { spacing: 1, children: [
106
109
  /* @__PURE__ */ jsx(LineSeparator, {}),
@@ -57,7 +57,7 @@ const parametersStyles = {
57
57
  overflowY: "auto",
58
58
  overflowX: "hidden",
59
59
  paddingRight: theme.spacing(2),
60
- paddingTop: theme.spacing(2),
60
+ paddingTop: theme.spacing(1),
61
61
  paddingBottom: theme.spacing(1),
62
62
  flexGrow: 1
63
63
  }),
package/dist/index.js CHANGED
@@ -71,6 +71,7 @@ import { CustomMenuItem, CustomNestedMenuItem } from "./components/ui/menus/cust
71
71
  import { ResizeHandle } from "./components/ui/resizablePanels/ResizeHandle.js";
72
72
  import { CsvExport } from "./components/ui/csvDownloader/csv-export.js";
73
73
  import { ExportCsvButton } from "./components/ui/csvDownloader/export-csv-button.js";
74
+ import { ManagedExportCsvButton } from "./components/ui/csvDownloader/managed-export-csv-button.js";
74
75
  import { fetchCsvSeparator, useCsvExport } from "./components/ui/csvDownloader/use-csv-export.js";
75
76
  import { CsvPicker } from "./components/ui/csvPicker/csv-picker.js";
76
77
  import { TreeViewFinder, generateTreeViewFinderClass } from "./components/ui/treeViewFinder/TreeViewFinder.js";
@@ -845,6 +846,7 @@ export {
845
846
  MONITORED_BRANCHES_EQUIPMENT_TYPES,
846
847
  MONITORED_VOLTAGE_LEVELS_EQUIPMENT_TYPES,
847
848
  MVAPowerAdornment,
849
+ ManagedExportCsvButton,
848
850
  MessageLogCellRenderer,
849
851
  MicroSusceptanceAdornment,
850
852
  MidFormError,
@@ -38,6 +38,7 @@ export declare const businessErrorsEn: {
38
38
  'study.tooManyNadConfigs': string;
39
39
  'study.tooManyMapCards': string;
40
40
  'study.elementAlreadyExists': string;
41
+ 'study.maxOperationTypeExceeded': string;
41
42
  'useradmin.permissionDenied': string;
42
43
  'useradmin.userNotFound': string;
43
44
  'useradmin.userAlreadyExists': string;
@@ -32,6 +32,7 @@ const businessErrorsEn = {
32
32
  "study.tooManyNadConfigs": "Maximum number of NAD configuration exceeded.",
33
33
  "study.tooManyMapCards": "Maximum number of cards exceeded.",
34
34
  "study.elementAlreadyExists": "An element with the name {fileName} already exists",
35
+ "study.maxOperationTypeExceeded": "Max number of operation reached : {currentComputation}/{maxComputation}",
35
36
  "useradmin.permissionDenied": "You don't have permission to perform this action.",
36
37
  "useradmin.userNotFound": "User not found.",
37
38
  "useradmin.userAlreadyExists": "User already exists.",
@@ -38,6 +38,7 @@ export declare const businessErrorsFr: {
38
38
  'study.tooManyNadConfigs': string;
39
39
  'study.tooManyMapCards': string;
40
40
  'study.elementAlreadyExists': string;
41
+ 'study.maxOperationTypeExceeded': string;
41
42
  'useradmin.permissionDenied': string;
42
43
  'useradmin.userNotFound': string;
43
44
  'useradmin.userAlreadyExists': string;
@@ -32,6 +32,7 @@ const businessErrorsFr = {
32
32
  "study.tooManyNadConfigs": "Nombre maximal de configurations d'image nodale de zone atteint.",
33
33
  "study.tooManyMapCards": "Nombre maximal de carte atteint.",
34
34
  "study.elementAlreadyExists": "Un élément avec le nom {fileName} est déjà présent",
35
+ "study.maxOperationTypeExceeded": "Nombre maximal d'opération de ce type atteint : {currentComputation}/{maxComputation}",
35
36
  "useradmin.permissionDenied": "Vous n'avez pas la permission d'effectuer cette action.",
36
37
  "useradmin.userNotFound": "Utilisateur introuvable.",
37
38
  "useradmin.userAlreadyExists": "L'utilisateur existe déjà.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.244.0",
3
+ "version": "0.245.0",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "author": "gridsuite team",
6
6
  "homepage": "https://github.com/gridsuite",