@gridsuite/commons-ui 0.139.0 → 0.140.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.
@@ -1,2 +1,2 @@
1
1
  import { CsvExportProps } from './csv-export.type';
2
- export declare function CsvExport({ columns, tableNamePrefix, tableName, disabled, skipColumnHeaders, skipPinnedBottom, language, exportDataAsCsv, }: CsvExportProps): JSX.Element;
2
+ export declare function CsvExport({ columns, tableNamePrefix, tableName, disabled, skipColumnHeaders, skipPinnedBottom, language, getData, }: CsvExportProps): JSX.Element;
@@ -10,29 +10,20 @@ function CsvExport({
10
10
  skipColumnHeaders = false,
11
11
  skipPinnedBottom = false,
12
12
  language,
13
- exportDataAsCsv
13
+ getData
14
14
  }) {
15
- const { downloadCSVData } = useCsvExport();
15
+ const csvExport = useCsvExport();
16
16
  const download = useCallback(() => {
17
- downloadCSVData({
17
+ csvExport.getData({
18
18
  columns,
19
19
  tableName,
20
20
  tableNamePrefix,
21
21
  skipColumnHeaders,
22
22
  skipPinnedBottom,
23
23
  language,
24
- exportDataAsCsv
24
+ getData
25
25
  });
26
- }, [
27
- downloadCSVData,
28
- columns,
29
- tableName,
30
- tableNamePrefix,
31
- skipColumnHeaders,
32
- skipPinnedBottom,
33
- language,
34
- exportDataAsCsv
35
- ]);
26
+ }, [columns, csvExport, tableName, tableNamePrefix, skipColumnHeaders, skipPinnedBottom, language, getData]);
36
27
  return /* @__PURE__ */ jsx(ExportCsvButton, { disabled, onClick: download });
37
28
  }
38
29
  export {
@@ -7,7 +7,7 @@ export type CsvDownloadProps = {
7
7
  skipColumnHeaders?: boolean;
8
8
  skipPinnedBottom?: boolean;
9
9
  language: GsLang;
10
- exportDataAsCsv: (params?: CsvExportParams) => void;
10
+ getData: (params?: CsvExportParams) => string | undefined | void;
11
11
  };
12
12
  export type CsvExportProps = CsvDownloadProps & {
13
13
  disabled: boolean;
@@ -1,4 +1,4 @@
1
1
  import { CsvDownloadProps } from './csv-export.type';
2
2
  export declare const useCsvExport: () => {
3
- downloadCSVData: (props: CsvDownloadProps) => void;
3
+ getData: (props: CsvDownloadProps) => string | undefined | void;
4
4
  };
@@ -7,30 +7,30 @@ import "@mui/icons-material";
7
7
  import "../../utils/types/equipmentType.js";
8
8
  import "../../utils/yupConfig.js";
9
9
  const NA_VALUE = "N/A";
10
- const formatNAValue = (value, intl) => {
11
- return value === NA_VALUE ? intl.formatMessage({ id: "export/undefined" }) : value;
12
- };
13
10
  const useCsvExport = () => {
14
11
  const intl = useIntl();
15
- const getCSVFilename = useCallback((tableName) => {
16
- return tableName.trim().replace(/[\\/:"*?<>|\s]/g, "-").substring(0, 27);
17
- }, []);
18
- const downloadCSVData = useCallback(
12
+ const getData = useCallback(
19
13
  (props) => {
14
+ const formatNAValue = (value) => {
15
+ return value === NA_VALUE ? intl.formatMessage({ id: "export/undefined" }) : value;
16
+ };
20
17
  const hasColId = (colId) => {
21
18
  return colId !== void 0;
22
19
  };
23
20
  const processCell = (params) => {
24
21
  if (params.column.getColId() === "limitName") {
25
- return formatNAValue(params.value, intl);
22
+ return formatNAValue(params.value);
26
23
  }
27
24
  if (props.language === LANG_FRENCH && typeof params.value === "number") {
28
25
  return params.value.toString().replace(".", ",");
29
26
  }
30
27
  return params.value;
31
28
  };
29
+ const getCSVFilename = (tableName) => {
30
+ return tableName.trim().replace(/[\\/:"*?<>|\s]/g, "-").substring(0, 27);
31
+ };
32
32
  const prefix = props.tableNamePrefix ?? "";
33
- props.exportDataAsCsv({
33
+ return props.getData({
34
34
  suppressQuotes: false,
35
35
  skipPinnedBottom: props.skipPinnedBottom,
36
36
  columnSeparator: props.language === LANG_FRENCH ? ";" : ",",
@@ -41,9 +41,9 @@ const useCsvExport = () => {
41
41
  processCellCallback: processCell
42
42
  });
43
43
  },
44
- [getCSVFilename, intl]
44
+ [intl]
45
45
  );
46
- return { downloadCSVData };
46
+ return { getData };
47
47
  };
48
48
  export {
49
49
  useCsvExport
@@ -111,7 +111,8 @@ function FilterCreationDialog({
111
111
  creation: true,
112
112
  activeDirectory,
113
113
  filterType,
114
- sourceFilterForExplicitNamingConversion
114
+ sourceFilterForExplicitNamingConversion,
115
+ language
115
116
  }
116
117
  )
117
118
  }
@@ -1,2 +1,16 @@
1
- import { FilterFormProps } from './HeaderFilterForm';
2
- export declare function FilterForm({ sourceFilterForExplicitNamingConversion, creation, activeDirectory, filterType, }: Readonly<FilterFormProps>): import("react/jsx-runtime").JSX.Element;
1
+ import { UUID } from 'node:crypto';
2
+ import { GsLang } from '../../utils';
3
+ export interface FilterFormProps {
4
+ creation?: boolean;
5
+ activeDirectory?: UUID;
6
+ filterType?: {
7
+ id: string;
8
+ label: string;
9
+ };
10
+ sourceFilterForExplicitNamingConversion?: {
11
+ id: UUID;
12
+ equipmentType: string;
13
+ };
14
+ language?: GsLang;
15
+ }
16
+ export declare function FilterForm({ sourceFilterForExplicitNamingConversion, creation, activeDirectory, filterType, language, }: Readonly<FilterFormProps>): import("react/jsx-runtime").JSX.Element;
@@ -20,21 +20,16 @@ function FilterForm({
20
20
  sourceFilterForExplicitNamingConversion,
21
21
  creation,
22
22
  activeDirectory,
23
- filterType
23
+ filterType,
24
+ language
24
25
  }) {
25
26
  return /* @__PURE__ */ jsxs(Fragment, { children: [
26
- /* @__PURE__ */ jsx(Box, { sx: unscrollableDialogStyles.unscrollableHeader, children: /* @__PURE__ */ jsx(
27
- HeaderFilterForm,
28
- {
29
- creation,
30
- activeDirectory,
31
- sourceFilterForExplicitNamingConversion
32
- }
33
- ) }),
27
+ /* @__PURE__ */ jsx(Box, { sx: unscrollableDialogStyles.unscrollableHeader, children: /* @__PURE__ */ jsx(HeaderFilterForm, { creation, activeDirectory }) }),
34
28
  filterType?.id === FilterType.EXPLICIT_NAMING.id && /* @__PURE__ */ jsx(
35
29
  ExplicitNamingFilterForm,
36
30
  {
37
- sourceFilterForExplicitNamingConversion
31
+ sourceFilterForExplicitNamingConversion,
32
+ language
38
33
  }
39
34
  ),
40
35
  filterType?.id === FilterType.EXPERT.id && /* @__PURE__ */ jsx(ExpertFilterForm, {})
@@ -10,21 +10,17 @@ export declare const filterStyles: {
10
10
  readonly width: "50%";
11
11
  };
12
12
  };
13
- export interface FilterFormProps {
13
+ export declare const HeaderFilterSchema: {
14
+ name: yup.StringSchema<string, yup.AnyObject, undefined, "">;
15
+ equipmentType: yup.StringSchema<string, yup.AnyObject, undefined, "">;
16
+ description: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
17
+ };
18
+ export interface HeaderFilterFormProps {
14
19
  creation?: boolean;
15
20
  activeDirectory?: UUID;
16
- filterType?: {
17
- id: string;
18
- label: string;
19
- };
20
21
  sourceFilterForExplicitNamingConversion?: {
21
22
  id: UUID;
22
23
  equipmentType: string;
23
24
  };
24
25
  }
25
- export declare const HeaderFilterSchema: {
26
- name: yup.StringSchema<string, yup.AnyObject, undefined, "">;
27
- equipmentType: yup.StringSchema<string, yup.AnyObject, undefined, "">;
28
- description: yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
29
- };
30
- export declare function HeaderFilterForm({ creation, activeDirectory }: Readonly<FilterFormProps>): import("react/jsx-runtime").JSX.Element;
26
+ export declare function HeaderFilterForm({ creation, activeDirectory }: Readonly<HeaderFilterFormProps>): import("react/jsx-runtime").JSX.Element;
@@ -102,7 +102,14 @@ function ExplicitNamingFilterEditionDialog({
102
102
  isDataFetching: dataFetchStatus === FetchStatus.FETCHING,
103
103
  language,
104
104
  unscrollableFullHeight: true,
105
- children: isDataReady && /* @__PURE__ */ jsx(FilterForm, { activeDirectory, filterType: FilterType.EXPLICIT_NAMING })
105
+ children: isDataReady && /* @__PURE__ */ jsx(
106
+ FilterForm,
107
+ {
108
+ activeDirectory,
109
+ filterType: FilterType.EXPLICIT_NAMING,
110
+ language
111
+ }
112
+ )
106
113
  }
107
114
  );
108
115
  }
@@ -2,6 +2,7 @@ import { UUID } from 'node:crypto';
2
2
  import { FieldConstants } from '../../../utils/constants/fieldConstants';
3
3
  import { default as yup } from '../../../utils/yupConfig';
4
4
  import { DISTRIBUTION_KEY } from '../constants/FilterConstants';
5
+ import { GsLang } from '../../../utils';
5
6
  export declare const explicitNamingFilterSchema: {
6
7
  filterEquipmentsAttributes: yup.ArraySchema<{
7
8
  equipmentID?: string | null | undefined;
@@ -22,6 +23,7 @@ export interface FilterForExplicitConversionProps {
22
23
  }
23
24
  interface ExplicitNamingFilterFormProps {
24
25
  sourceFilterForExplicitNamingConversion?: FilterForExplicitConversionProps;
26
+ language?: GsLang;
25
27
  }
26
- export declare function ExplicitNamingFilterForm({ sourceFilterForExplicitNamingConversion }: ExplicitNamingFilterFormProps): import("react/jsx-runtime").JSX.Element;
28
+ export declare function ExplicitNamingFilterForm({ sourceFilterForExplicitNamingConversion, language, }: Readonly<ExplicitNamingFilterFormProps>): import("react/jsx-runtime").JSX.Element;
27
29
  export {};
@@ -23,7 +23,10 @@ import "../../dialogs/descriptionModificationDialog/DescriptionModificationDialo
23
23
  import "../../dialogs/elementSaveDialog/ElementSaveDialog.js";
24
24
  import { FILTER_EQUIPMENTS_ATTRIBUTES } from "./ExplicitNamingFilterConstants.js";
25
25
  import { filterStyles } from "../HeaderFilterForm.js";
26
+ import "../../../utils/conversionUtils.js";
26
27
  import { snackWithFallback } from "../../../utils/error.js";
28
+ import "@mui/icons-material";
29
+ import "../../../utils/types/equipmentType.js";
27
30
  import * as yup from "yup";
28
31
  function isGeneratorOrLoad(equipmentType) {
29
32
  return equipmentType === Generator.type || equipmentType === Load.type;
@@ -58,7 +61,10 @@ function getExplicitNamingFilterEmptyFormData() {
58
61
  [FILTER_EQUIPMENTS_ATTRIBUTES]: makeDefaultTableRows()
59
62
  };
60
63
  }
61
- function ExplicitNamingFilterForm({ sourceFilterForExplicitNamingConversion }) {
64
+ function ExplicitNamingFilterForm({
65
+ sourceFilterForExplicitNamingConversion,
66
+ language
67
+ }) {
62
68
  const intl = useIntl();
63
69
  const { snackError } = useSnackMessage();
64
70
  const { getValues, setValue } = useFormContext();
@@ -203,7 +209,8 @@ function ExplicitNamingFilterForm({ sourceFilterForExplicitNamingConversion }) {
203
209
  id: "filterCsvFileName"
204
210
  }),
205
211
  fileHeaders: csvFileHeaders,
206
- getDataFromCsv: getDataFromCsvFile
212
+ getDataFromCsv: getDataFromCsvFile,
213
+ language
207
214
  },
208
215
  cssProps: {
209
216
  padding: 1,
package/dist/index.js CHANGED
@@ -213,6 +213,7 @@ import { areArrayElementsUnique, isObjectEmpty, keyGenerator } from "./utils/fun
213
213
  import { LANG_ENGLISH, LANG_FRENCH, LANG_SYSTEM } from "./utils/langs.js";
214
214
  import { getFileIcon } from "./utils/mapper/getFileIcon.js";
215
215
  import { equipmentTypesForPredefinedPropertiesMapper } from "./utils/mapper/equipmentTypesForPredefinedPropertiesMapper.js";
216
+ import { copyToClipboard } from "./utils/navigator-clipboard.js";
216
217
  import { NotificationsUrlKeys, PREFIX_CONFIG_NOTIFICATION_WS, PREFIX_DIRECTORY_NOTIFICATION_WS, PREFIX_STUDY_NOTIFICATION_WS } from "./utils/constants/notificationsProvider.js";
217
218
  import { DARK_THEME, LIGHT_THEME, makeComposeClasses, mergeSx, toNestedGlobalSelectors } from "./utils/styles.js";
218
219
  import { CustomError, formatMessageValues } from "./utils/types/CustomError.js";
@@ -687,6 +688,7 @@ export {
687
688
  componentsFr,
688
689
  convertInputValue,
689
690
  convertOutputValue,
691
+ copyToClipboard,
690
692
  countRules,
691
693
  createFilter,
692
694
  createParameter,
@@ -11,6 +11,7 @@ export * from './error';
11
11
  export * from './functions';
12
12
  export * from './langs';
13
13
  export * from './mapper';
14
+ export * from './navigator-clipboard';
14
15
  export * from './constants/notificationsProvider';
15
16
  export * from './styles';
16
17
  export * from './types';
@@ -11,6 +11,7 @@ import { areArrayElementsUnique, isObjectEmpty, keyGenerator } from "./functions
11
11
  import { LANG_ENGLISH, LANG_FRENCH, LANG_SYSTEM } from "./langs.js";
12
12
  import { getFileIcon } from "./mapper/getFileIcon.js";
13
13
  import { equipmentTypesForPredefinedPropertiesMapper } from "./mapper/equipmentTypesForPredefinedPropertiesMapper.js";
14
+ import { copyToClipboard } from "./navigator-clipboard.js";
14
15
  import { NotificationsUrlKeys, PREFIX_CONFIG_NOTIFICATION_WS, PREFIX_DIRECTORY_NOTIFICATION_WS, PREFIX_STUDY_NOTIFICATION_WS } from "./constants/notificationsProvider.js";
15
16
  import { DARK_THEME, LIGHT_THEME, makeComposeClasses, mergeSx, toNestedGlobalSelectors } from "./styles.js";
16
17
  import { CustomError, formatMessageValues } from "./types/CustomError.js";
@@ -102,6 +103,7 @@ export {
102
103
  catchErrorHandler,
103
104
  convertInputValue,
104
105
  convertOutputValue,
106
+ copyToClipboard,
105
107
  equalsArray,
106
108
  equipmentStyles,
107
109
  equipmentTypesForPredefinedPropertiesMapper,
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) 2025, RTE (http://www.rte-france.com)
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+ */
7
+ export declare function copyToClipboard(valueToCopy: string, onSuccess?: () => void, onError?: () => void): void;
@@ -0,0 +1,16 @@
1
+ function copyToClipboard(valueToCopy, onSuccess, onError) {
2
+ if ("clipboard" in navigator) {
3
+ navigator.clipboard.writeText(valueToCopy).then(() => {
4
+ if (onSuccess) onSuccess();
5
+ }).catch((error) => {
6
+ console.error("Clipboard copy error: ", error);
7
+ if (onError) onError();
8
+ });
9
+ } else {
10
+ console.error("navigator.clipboard is not supported by your current navigator");
11
+ if (onError) onError();
12
+ }
13
+ }
14
+ export {
15
+ copyToClipboard
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.139.0",
3
+ "version": "0.140.0",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "author": "gridsuite team",
6
6
  "homepage": "https://github.com/gridsuite",