@gridsuite/commons-ui 0.244.0 → 0.246.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.
Files changed (27) hide show
  1. package/dist/components/composite/agGridTable/BottomTableButtons.js +8 -23
  2. package/dist/components/composite/agGridTable/agGridTable-utils.d.ts +0 -1
  3. package/dist/components/composite/filter/explicitNaming/ExplicitNamingFilterForm.js +75 -64
  4. package/dist/components/index.js +4 -0
  5. package/dist/components/ui/csvDownloader/csv-download-button.d.ts +11 -0
  6. package/dist/components/ui/csvDownloader/csv-download-button.js +28 -0
  7. package/dist/components/ui/csvDownloader/csv-export.d.ts +1 -1
  8. package/dist/components/ui/csvDownloader/csv-export.js +6 -5
  9. package/dist/components/ui/csvDownloader/csv-export.type.d.ts +2 -0
  10. package/dist/components/ui/csvDownloader/export-csv-button.d.ts +3 -2
  11. package/dist/components/ui/csvDownloader/export-csv-button.js +2 -1
  12. package/dist/components/ui/csvDownloader/index.d.ts +2 -0
  13. package/dist/components/ui/csvDownloader/index.js +4 -0
  14. package/dist/components/ui/csvDownloader/managed-export-csv-button.d.ts +8 -0
  15. package/dist/components/ui/csvDownloader/managed-export-csv-button.js +48 -0
  16. package/dist/components/ui/csvPicker/csv-picker.js +10 -24
  17. package/dist/components/ui/index.js +4 -0
  18. package/dist/features/parameters/common/parameter-layout/parameter-layout.js +27 -24
  19. package/dist/features/parameters/parameters-style.js +1 -1
  20. package/dist/index.js +4 -0
  21. package/dist/translations/en/businessErrorsEn.d.ts +1 -0
  22. package/dist/translations/en/businessErrorsEn.js +1 -0
  23. package/dist/translations/en/csvEn.js +3 -3
  24. package/dist/translations/fr/businessErrorsFr.d.ts +1 -0
  25. package/dist/translations/fr/businessErrorsFr.js +1 -0
  26. package/dist/translations/fr/csvFr.js +3 -3
  27. package/package.json +1 -1
@@ -1,25 +1,18 @@
1
1
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
- import { styled, IconButton, Grid2, Box, Button } from "@mui/material";
2
+ import { styled, IconButton, Grid2, Box } from "@mui/material";
3
3
  import { ControlPoint, Delete, ArrowCircleUp, ArrowCircleDown } from "@mui/icons-material";
4
- import { FormattedMessage } from "react-intl";
5
- import { useCSVDownloader } from "react-papaparse";
6
4
  import { ErrorInput } from "../../ui/reactHookForm/errorManagement/ErrorInput.js";
7
5
  import { FieldErrorAlert } from "../../ui/reactHookForm/errorManagement/FieldErrorAlert.js";
6
+ import { CsvDownloadButton } from "../../ui/csvDownloader/csv-download-button.js";
7
+ import "react";
8
+ import "react-intl";
8
9
  import "../../../utils/conversionUtils.js";
9
10
  import "../../../utils/types/equipmentType.js";
10
- import { getCsvDelimiter } from "../../../utils/langs.js";
11
11
  const InnerColoredButton = styled(IconButton)(({ theme }) => {
12
12
  return {
13
13
  color: theme.palette.primary.main
14
14
  };
15
15
  });
16
- function CsvDownloadButton({ data, fileName, delimiter, labelId, disabled }) {
17
- const { CSVDownloader } = useCSVDownloader();
18
- if (disabled) {
19
- return /* @__PURE__ */ jsx(Button, { variant: "outlined", disabled: true, children: /* @__PURE__ */ jsx(FormattedMessage, { id: labelId }) });
20
- }
21
- return /* @__PURE__ */ jsx(CSVDownloader, { data, filename: fileName, config: { delimiter }, children: /* @__PURE__ */ jsx(Button, { variant: "outlined", children: /* @__PURE__ */ jsx(FormattedMessage, { id: labelId }) }) });
22
- }
23
16
  function BottomTableButtons({
24
17
  name,
25
18
  disableUp,
@@ -32,24 +25,16 @@ function BottomTableButtons({
32
25
  csvProps
33
26
  }) {
34
27
  return /* @__PURE__ */ jsxs(Fragment, { children: [
35
- /* @__PURE__ */ jsxs(Grid2, { container: true, paddingTop: 1, alignItems: "center", spacing: 1, children: [
36
- csvProps?.getTemplateData && /* @__PURE__ */ jsx(Grid2, { children: /* @__PURE__ */ jsx(
37
- CsvDownloadButton,
38
- {
39
- data: csvProps.getTemplateData,
40
- fileName: csvProps.fileName,
41
- delimiter: getCsvDelimiter(csvProps.language),
42
- labelId: "GenerateCSV"
43
- }
44
- ) }),
28
+ /* @__PURE__ */ jsxs(Grid2, { container: true, paddingTop: 1, paddingLeft: 1, alignItems: "center", spacing: 1, children: [
45
29
  csvProps?.getTableData && /* @__PURE__ */ jsx(Grid2, { children: /* @__PURE__ */ jsx(
46
30
  CsvDownloadButton,
47
31
  {
48
32
  data: csvProps.getTableData,
49
33
  fileName: csvProps.fileName,
50
- delimiter: getCsvDelimiter(csvProps.language),
34
+ language: csvProps.language,
51
35
  labelId: "DownloadCSV",
52
- disabled: !csvProps.hasTableData
36
+ disabled: !csvProps.hasTableData,
37
+ withExportButton: true
53
38
  }
54
39
  ) }),
55
40
  csvProps?.extraButtons && /* @__PURE__ */ jsx(Grid2, { children: csvProps.extraButtons }),
@@ -2,7 +2,6 @@ import { ReactNode } from 'react';
2
2
  export interface CsvProps {
3
3
  fileName: string;
4
4
  language?: string;
5
- getTemplateData?: () => unknown[];
6
5
  getTableData?: () => unknown[];
7
6
  extraButtons?: ReactNode;
8
7
  hasTableData?: boolean;
@@ -1,4 +1,4 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
1
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { useEffect, useMemo, useCallback, useState, useRef } from "react";
3
3
  import { useIntl } from "react-intl";
4
4
  import { useWatch } from "react-hook-form";
@@ -45,6 +45,7 @@ import "../../../ui/dialogs/elementSaveDialog/ElementSaveDialog.js";
45
45
  import "../../../ui/snackbarProvider/SnackbarProvider.js";
46
46
  import "mui-nested-menu";
47
47
  import "react-resizable-panels";
48
+ import { CsvDownloadButton } from "../../../ui/csvDownloader/csv-download-button.js";
48
49
  import { CsvPicker } from "../../../ui/csvPicker/csv-picker.js";
49
50
  const explicitNamingFilterSchema = {
50
51
  [FILTER_EQUIPMENTS_ATTRIBUTES]: yup.array().of(
@@ -193,77 +194,87 @@ function ExplicitNamingFilterForm({
193
194
  padding: 1,
194
195
  sx: { flexGrow: 1, flexWrap: "nowrap", minHeight: 0 },
195
196
  children: [
196
- /* @__PURE__ */ jsxs(Grid2, { container: true, justifyContent: "space-between", alignItems: "center", children: [
197
- /* @__PURE__ */ jsxs(Grid2, { children: [
198
- /* @__PURE__ */ jsx(
199
- InputWithPopupConfirmation,
197
+ /* @__PURE__ */ jsxs(Grid2, { children: [
198
+ /* @__PURE__ */ jsx(
199
+ InputWithPopupConfirmation,
200
+ {
201
+ Input: SelectInput,
202
+ name: FieldConstants.EQUIPMENT_TYPE,
203
+ options: Object.values(FILTER_EQUIPMENTS),
204
+ disabled: !!sourceFilterForExplicitNamingConversion || isEditing && !isDeveloperMode,
205
+ label: "equipmentType",
206
+ shouldOpenPopup: openConfirmationPopup,
207
+ resetOnConfirmation: handleResetOnConfirmation,
208
+ message: "changeTypeMessage",
209
+ validateButtonLabel: "button.changeType",
210
+ sx: { width: 400, maxWidth: "100%" },
211
+ "data-testid": "EquipmentTypeSelector"
212
+ }
213
+ ),
214
+ sourceFilterForExplicitNamingConversion && /* @__PURE__ */ jsx(
215
+ ModifyElementSelection,
216
+ {
217
+ elementType: ElementType.STUDY,
218
+ onElementValidated: onStudySelected,
219
+ dialogOpeningButtonLabel: "selectStudyDialogButton",
220
+ dialogTitleLabel: "selectStudyDialogTitle",
221
+ dialogMessageLabel: "selectStudyText",
222
+ noElementMessageLabel: "noSelectedStudyText"
223
+ }
224
+ )
225
+ ] }),
226
+ watchEquipmentType && /* @__PURE__ */ jsxs(Fragment, { children: [
227
+ /* @__PURE__ */ jsxs(Grid2, { container: true, spacing: 2, justifyContent: "space-between", alignItems: "center", children: [
228
+ /* @__PURE__ */ jsx(Grid2, { children: /* @__PURE__ */ jsx(
229
+ CsvDownloadButton,
200
230
  {
201
- Input: SelectInput,
202
- name: FieldConstants.EQUIPMENT_TYPE,
203
- options: Object.values(FILTER_EQUIPMENTS),
204
- disabled: !!sourceFilterForExplicitNamingConversion || isEditing && !isDeveloperMode,
205
- label: "equipmentType",
206
- shouldOpenPopup: openConfirmationPopup,
207
- resetOnConfirmation: handleResetOnConfirmation,
208
- message: "changeTypeMessage",
209
- validateButtonLabel: "button.changeType",
210
- sx: { width: 400, maxWidth: "100%" },
211
- "data-testid": "EquipmentTypeSelector"
231
+ data: getTemplateData,
232
+ fileName: intl.formatMessage({ id: "filterCsvFileName" }),
233
+ language,
234
+ labelId: "GenerateCSV",
235
+ variant: "contained"
212
236
  }
213
- ),
214
- sourceFilterForExplicitNamingConversion && /* @__PURE__ */ jsx(
215
- ModifyElementSelection,
237
+ ) }),
238
+ /* @__PURE__ */ jsx(Grid2, { sx: { flex: 1, minWidth: 0 }, children: /* @__PURE__ */ jsx(
239
+ CsvPicker,
216
240
  {
217
- elementType: ElementType.STUDY,
218
- onElementValidated: onStudySelected,
219
- dialogOpeningButtonLabel: "selectStudyDialogButton",
220
- dialogTitleLabel: "selectStudyDialogTitle",
221
- dialogMessageLabel: "selectStudyText",
222
- noElementMessageLabel: "noSelectedStudyText"
241
+ label: "UploadCSV",
242
+ requiredColumns: csvFileHeaders,
243
+ language: language ?? LANG_SYSTEM,
244
+ selectedFile,
245
+ onFileChange: setSelectedFile,
246
+ onFileError: setFileErrorMessage,
247
+ getTableData: () => getValues(FILTER_EQUIPMENTS_ATTRIBUTES),
248
+ onAppend: (results) => tableRef.current?.append(getDataFromCsvFile(results.data)),
249
+ onReplace: (results) => tableRef.current?.replace(getDataFromCsvFile(results.data))
223
250
  }
224
- )
251
+ ) })
225
252
  ] }),
226
- /* @__PURE__ */ jsx(Grid2, { children: /* @__PURE__ */ jsx(
227
- CsvPicker,
253
+ fileErrorMessage && /* @__PURE__ */ jsx(Grid2, { children: /* @__PURE__ */ jsx(Alert, { severity: "error", children: fileErrorMessage }) }),
254
+ /* @__PURE__ */ jsx(Grid2, { sx: { flexGrow: 1, minHeight: 0, display: "flex", flexDirection: "column" }, children: /* @__PURE__ */ jsx(
255
+ CustomAgGridTable,
228
256
  {
229
- label: "UploadCSV",
230
- requiredColumns: csvFileHeaders,
231
- language: language ?? LANG_SYSTEM,
232
- disabled: !watchEquipmentType,
233
- selectedFile,
234
- onFileChange: setSelectedFile,
235
- onFileError: setFileErrorMessage,
236
- getTableData: () => getValues(FILTER_EQUIPMENTS_ATTRIBUTES),
237
- onAppend: (results) => tableRef.current?.append(getDataFromCsvFile(results.data)),
238
- onReplace: (results) => tableRef.current?.replace(getDataFromCsvFile(results.data))
257
+ ref: tableRef,
258
+ name: FILTER_EQUIPMENTS_ATTRIBUTES,
259
+ columnDefs,
260
+ defaultColDef,
261
+ makeDefaultRowData,
262
+ pagination: true,
263
+ rowSelection: {
264
+ mode: "multiRow",
265
+ enableClickSelection: false,
266
+ checkboxes: true,
267
+ headerCheckbox: true
268
+ },
269
+ alwaysShowVerticalScroll: true,
270
+ csvProps: {
271
+ fileName: intl.formatMessage({ id: "filterCsvFileName" }),
272
+ language,
273
+ getTableData
274
+ }
239
275
  }
240
276
  ) })
241
- ] }),
242
- fileErrorMessage && /* @__PURE__ */ jsx(Grid2, { children: /* @__PURE__ */ jsx(Alert, { severity: "error", children: fileErrorMessage }) }),
243
- watchEquipmentType && /* @__PURE__ */ jsx(Grid2, { sx: { flexGrow: 1, minHeight: 0, display: "flex", flexDirection: "column" }, children: /* @__PURE__ */ jsx(
244
- CustomAgGridTable,
245
- {
246
- ref: tableRef,
247
- name: FILTER_EQUIPMENTS_ATTRIBUTES,
248
- columnDefs,
249
- defaultColDef,
250
- makeDefaultRowData,
251
- pagination: true,
252
- rowSelection: {
253
- mode: "multiRow",
254
- enableClickSelection: false,
255
- checkboxes: true,
256
- headerCheckbox: true
257
- },
258
- alwaysShowVerticalScroll: true,
259
- csvProps: {
260
- fileName: intl.formatMessage({ id: "filterCsvFileName" }),
261
- language,
262
- getTemplateData,
263
- getTableData
264
- }
265
- }
266
- ) })
277
+ ] })
267
278
  ]
268
279
  }
269
280
  );
@@ -68,8 +68,10 @@ import { EditNoteIcon } from "./ui/icons/EditNoteIcon.js";
68
68
  import { VoltageUnitIcon } from "./ui/icons/VoltageUnitIcon.js";
69
69
  import { CustomMenuItem, CustomNestedMenuItem } from "./ui/menus/custom-nested-menu.js";
70
70
  import { ResizeHandle } from "./ui/resizablePanels/ResizeHandle.js";
71
+ import { CsvDownloadButton } from "./ui/csvDownloader/csv-download-button.js";
71
72
  import { CsvExport } from "./ui/csvDownloader/csv-export.js";
72
73
  import { ExportCsvButton } from "./ui/csvDownloader/export-csv-button.js";
74
+ import { ManagedExportCsvButton } from "./ui/csvDownloader/managed-export-csv-button.js";
73
75
  import { fetchCsvSeparator, useCsvExport } from "./ui/csvDownloader/use-csv-export.js";
74
76
  import { CsvPicker } from "./ui/csvPicker/csv-picker.js";
75
77
  import { TreeViewFinder, generateTreeViewFinderClass } from "./ui/treeViewFinder/TreeViewFinder.js";
@@ -181,6 +183,7 @@ export {
181
183
  CountriesInput,
182
184
  CountrySelectionInput,
183
185
  CountryValueEditor,
186
+ CsvDownloadButton,
184
187
  CsvExport,
185
188
  CsvPicker,
186
189
  CustomAGGrid,
@@ -269,6 +272,7 @@ export {
269
272
  LeftPanelOpenIcon,
270
273
  default2 as LogTable,
271
274
  MAX_ROWS_NUMBER,
275
+ ManagedExportCsvButton,
272
276
  MessageLogCellRenderer,
273
277
  MidFormError,
274
278
  ModifyElementSelection,
@@ -0,0 +1,11 @@
1
+ import { ButtonProps } from '@mui/material';
2
+ export interface CsvDownloadButtonProps {
3
+ labelId: string;
4
+ data: () => unknown[];
5
+ fileName: string;
6
+ language?: string;
7
+ withExportButton?: boolean;
8
+ disabled?: boolean;
9
+ variant?: ButtonProps['variant'];
10
+ }
11
+ export declare function CsvDownloadButton({ labelId, data, fileName, language, withExportButton, disabled, variant, }: Readonly<CsvDownloadButtonProps>): import("react").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Button } from "@mui/material";
3
+ import { FormattedMessage } from "react-intl";
4
+ import { useCSVDownloader } from "react-papaparse";
5
+ import "../../../utils/conversionUtils.js";
6
+ import "../../../utils/types/equipmentType.js";
7
+ import { getCsvDelimiter } from "../../../utils/langs.js";
8
+ import "@mui/icons-material";
9
+ import { ExportCsvButton } from "./export-csv-button.js";
10
+ function CsvDownloadButton({
11
+ labelId,
12
+ data,
13
+ fileName,
14
+ language,
15
+ withExportButton = false,
16
+ disabled,
17
+ variant = "outlined"
18
+ }) {
19
+ const { CSVDownloader } = useCSVDownloader();
20
+ const button = withExportButton ? /* @__PURE__ */ jsx(ExportCsvButton, { labelId, disabled }) : /* @__PURE__ */ jsx(Button, { variant, disabled, children: /* @__PURE__ */ jsx(FormattedMessage, { id: labelId }) });
21
+ if (disabled) {
22
+ return button;
23
+ }
24
+ return /* @__PURE__ */ jsx(CSVDownloader, { data, filename: fileName, config: { delimiter: getCsvDelimiter(language) }, children: button });
25
+ }
26
+ export {
27
+ CsvDownloadButton
28
+ };
@@ -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;
@@ -1,7 +1,8 @@
1
1
  export interface ExportButtonProps {
2
+ labelId?: string;
2
3
  disabled?: boolean;
3
- onClick: () => void;
4
+ onClick?: () => void;
4
5
  isDownloadLoading?: boolean;
5
6
  isDownloadSuccessful?: boolean;
6
7
  }
7
- export declare function ExportCsvButton({ onClick, disabled, isDownloadLoading: isCsvLoading, isDownloadSuccessful, }: Readonly<ExportButtonProps>): import("react").JSX.Element;
8
+ export declare function ExportCsvButton({ labelId, onClick, disabled, isDownloadLoading: isCsvLoading, isDownloadSuccessful, }: Readonly<ExportButtonProps>): import("react").JSX.Element;
@@ -3,13 +3,14 @@ import { Box, IconButton, CircularProgress } from "@mui/material";
3
3
  import { FormattedMessage } from "react-intl";
4
4
  import { Check, GetApp } from "@mui/icons-material";
5
5
  function ExportCsvButton({
6
+ labelId = "MuiVirtualizedTable/exportCSV",
6
7
  onClick,
7
8
  disabled = false,
8
9
  isDownloadLoading: isCsvLoading = false,
9
10
  isDownloadSuccessful = false
10
11
  }) {
11
12
  return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center" }, children: [
12
- /* @__PURE__ */ jsx(FormattedMessage, { id: "MuiVirtualizedTable/exportCSV" }),
13
+ /* @__PURE__ */ jsx(FormattedMessage, { id: labelId }),
13
14
  /* @__PURE__ */ jsxs(Box, { sx: { position: "relative" }, children: [
14
15
  /* @__PURE__ */ jsx(IconButton, { disabled, "aria-label": "exportCSVButton", onClick, children: isDownloadSuccessful ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(GetApp, {}) }),
15
16
  isCsvLoading && /* @__PURE__ */ jsx(
@@ -4,7 +4,9 @@
4
4
  * License, v. 2.0. If a copy of the MPL was not distributed with this
5
5
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
  */
7
+ export * from './csv-download-button';
7
8
  export * from './csv-export';
8
9
  export * from './csv-export.type';
9
10
  export * from './export-csv-button';
11
+ export * from './managed-export-csv-button';
10
12
  export * from './use-csv-export';
@@ -1,9 +1,13 @@
1
+ import { CsvDownloadButton } from "./csv-download-button.js";
1
2
  import { CsvExport } from "./csv-export.js";
2
3
  import { ExportCsvButton } from "./export-csv-button.js";
4
+ import { ManagedExportCsvButton } from "./managed-export-csv-button.js";
3
5
  import { fetchCsvSeparator, useCsvExport } from "./use-csv-export.js";
4
6
  export {
7
+ CsvDownloadButton,
5
8
  CsvExport,
6
9
  ExportCsvButton,
10
+ ManagedExportCsvButton,
7
11
  fetchCsvSeparator,
8
12
  useCsvExport
9
13
  };
@@ -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
+ };
@@ -1,7 +1,7 @@
1
1
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
2
  import { useState, useCallback } from "react";
3
3
  import { useIntl, FormattedMessage } from "react-intl";
4
- import { Button } from "@mui/material";
4
+ import { Grid2, Tooltip, Typography, Button } from "@mui/material";
5
5
  import { useCSVReader } from "react-papaparse";
6
6
  import "../../../utils/conversionUtils.js";
7
7
  import "../../../utils/types/equipmentType.js";
@@ -74,31 +74,17 @@ function CsvPicker({
74
74
  ...parseConfig
75
75
  },
76
76
  onUploadAccepted: handleUploadAccepted,
77
- children: ({ getRootProps, ProgressBar }) => /* @__PURE__ */ jsxs(Fragment, { children: [
78
- /* @__PURE__ */ jsx(
79
- "span",
77
+ children: ({ getRootProps }) => /* @__PURE__ */ jsxs(Grid2, { container: true, spacing: 1, alignItems: "center", justifyContent: "right", wrap: "nowrap", children: [
78
+ /* @__PURE__ */ jsx(Grid2, { children: /* @__PURE__ */ jsx(Tooltip, { title: selectedFile?.name, children: /* @__PURE__ */ jsx(Typography, { sx: { fontWeight: "bold", overflow: "hidden", textOverflow: "ellipsis" }, children: selectedFile ? selectedFile.name : /* @__PURE__ */ jsx(FormattedMessage, { id: "uploadMessage" }) }) }) }),
79
+ /* @__PURE__ */ jsx(Grid2, { size: "auto", children: /* @__PURE__ */ jsx(
80
+ Button,
80
81
  {
81
- style: {
82
- marginRight: "10px",
83
- fontWeight: "bold"
84
- },
85
- children: selectedFile ? selectedFile.name : intl.formatMessage({ id: "uploadMessage" })
82
+ ...getRootProps(),
83
+ variant: selectedFile ? "contained" : "text",
84
+ disabled,
85
+ children: /* @__PURE__ */ jsx(FormattedMessage, { id: label })
86
86
  }
87
- ),
88
- /* @__PURE__ */ jsxs(Button, { ...getRootProps(), variant: "outlined", disabled, children: [
89
- /* @__PURE__ */ jsx(FormattedMessage, { id: label }),
90
- /* @__PURE__ */ jsx(
91
- ProgressBar,
92
- {
93
- style: {
94
- position: "absolute",
95
- inset: 0,
96
- width: "100%",
97
- height: "100%"
98
- }
99
- }
100
- )
101
- ] })
87
+ ) })
102
88
  ] })
103
89
  }
104
90
  ),
@@ -68,8 +68,10 @@ import { EditNoteIcon } from "./icons/EditNoteIcon.js";
68
68
  import { VoltageUnitIcon } from "./icons/VoltageUnitIcon.js";
69
69
  import { CustomMenuItem, CustomNestedMenuItem } from "./menus/custom-nested-menu.js";
70
70
  import { ResizeHandle } from "./resizablePanels/ResizeHandle.js";
71
+ import { CsvDownloadButton } from "./csvDownloader/csv-download-button.js";
71
72
  import { CsvExport } from "./csvDownloader/csv-export.js";
72
73
  import { ExportCsvButton } from "./csvDownloader/export-csv-button.js";
74
+ import { ManagedExportCsvButton } from "./csvDownloader/managed-export-csv-button.js";
73
75
  import { fetchCsvSeparator, useCsvExport } from "./csvDownloader/use-csv-export.js";
74
76
  import { CsvPicker } from "./csvPicker/csv-picker.js";
75
77
  import { TreeViewFinder, generateTreeViewFinderClass } from "./treeViewFinder/TreeViewFinder.js";
@@ -92,6 +94,7 @@ export {
92
94
  ChipItemsInput,
93
95
  CountriesInput,
94
96
  CountrySelectionInput,
97
+ CsvDownloadButton,
95
98
  CsvExport,
96
99
  CsvPicker,
97
100
  CustomFormContext,
@@ -127,6 +130,7 @@ export {
127
130
  IntegerInput,
128
131
  LeftPanelCloseIcon,
129
132
  LeftPanelOpenIcon,
133
+ ManagedExportCsvButton,
130
134
  MidFormError,
131
135
  ModifyElementSelection,
132
136
  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
@@ -69,8 +69,10 @@ import { EditNoteIcon } from "./components/ui/icons/EditNoteIcon.js";
69
69
  import { VoltageUnitIcon } from "./components/ui/icons/VoltageUnitIcon.js";
70
70
  import { CustomMenuItem, CustomNestedMenuItem } from "./components/ui/menus/custom-nested-menu.js";
71
71
  import { ResizeHandle } from "./components/ui/resizablePanels/ResizeHandle.js";
72
+ import { CsvDownloadButton } from "./components/ui/csvDownloader/csv-download-button.js";
72
73
  import { CsvExport } from "./components/ui/csvDownloader/csv-export.js";
73
74
  import { ExportCsvButton } from "./components/ui/csvDownloader/export-csv-button.js";
75
+ import { ManagedExportCsvButton } from "./components/ui/csvDownloader/managed-export-csv-button.js";
74
76
  import { fetchCsvSeparator, useCsvExport } from "./components/ui/csvDownloader/use-csv-export.js";
75
77
  import { CsvPicker } from "./components/ui/csvPicker/csv-picker.js";
76
78
  import { TreeViewFinder, generateTreeViewFinderClass } from "./components/ui/treeViewFinder/TreeViewFinder.js";
@@ -595,6 +597,7 @@ export {
595
597
  CountrySelectionInput,
596
598
  CountryValueEditor,
597
599
  CreateParameterDialog,
600
+ CsvDownloadButton,
598
601
  CsvExport,
599
602
  CsvPicker,
600
603
  CustomAGGrid,
@@ -845,6 +848,7 @@ export {
845
848
  MONITORED_BRANCHES_EQUIPMENT_TYPES,
846
849
  MONITORED_VOLTAGE_LEVELS_EQUIPMENT_TYPES,
847
850
  MVAPowerAdornment,
851
+ ManagedExportCsvButton,
848
852
  MessageLogCellRenderer,
849
853
  MicroSusceptanceAdornment,
850
854
  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.",
@@ -1,10 +1,10 @@
1
1
  const csvEn = {
2
2
  noDataInCsvFile: "No data found in file ''{filename}''",
3
- wrongCsvHeadersError: "The file ''{filename}'' has the wrong headers. Use Generate CSV template button to get supported CSV format",
3
+ wrongCsvHeadersError: "The file ''{filename}'' has the wrong headers. Use ''Generate template'' button to get supported CSV format",
4
4
  keepCSVDataMessage: "Do you want to replace or add the new data to the current list ?",
5
- GenerateCSV: "Generate CSV template",
5
+ GenerateCSV: "Generate template",
6
6
  DownloadCSV: "Download CSV",
7
- UploadCSV: "Upload CSV",
7
+ UploadCSV: "Import CSV",
8
8
  uploadMessage: " No file selected",
9
9
  tooManyLinesInCsvFile: "The number of lines in file ''{filename}'' must not exceed {value}"
10
10
  };
@@ -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à.",
@@ -1,10 +1,10 @@
1
1
  const csvFr = {
2
2
  noDataInCsvFile: 'Aucune donnée trouvée dans le fichier "{filename}"',
3
- wrongCsvHeadersError: 'Les en-têtes du fichier "{filename}" sont incorrects. Utilisez le bouton Générer le modèle CSV pour obtenir le format CSV pris en charge',
3
+ wrongCsvHeadersError: 'Les en-têtes du fichier "{filename}" sont incorrects. Utilisez le bouton "Générer le modèle" pour obtenir le format CSV pris en charge',
4
4
  keepCSVDataMessage: "Voulez-vous remplacer la liste existante ou y ajouter les nouvelles données ?",
5
- GenerateCSV: "Générer le modèle CSV",
5
+ GenerateCSV: "Générer le modèle",
6
6
  DownloadCSV: "Télécharger en CSV",
7
- UploadCSV: "Charger un CSV",
7
+ UploadCSV: "Importer un CSV",
8
8
  uploadMessage: " Aucun fichier sélectionné",
9
9
  tooManyLinesInCsvFile: 'Le nombre de lignes dans le fichier "{filename}" ne doit pas dépasser {value}'
10
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.244.0",
3
+ "version": "0.246.0",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "author": "gridsuite team",
6
6
  "homepage": "https://github.com/gridsuite",