@gridsuite/commons-ui 0.38.0 → 0.40.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.
@@ -45,6 +45,13 @@ var ElementSearchDialog = function ElementSearchDialog(props) {
45
45
  });
46
46
  }
47
47
  }, [searchTermDisabled, searchTermDisableReason]);
48
+
49
+ // to reset the value between the dialog closing and opening
50
+ useEffect(function () {
51
+ setValue(function (old) {
52
+ return !open ? null : old;
53
+ });
54
+ }, [open]);
48
55
  var handleSearchTermChange = function handleSearchTermChange(term) {
49
56
  if (term) {
50
57
  setLoading(true);
@@ -1,4 +1,5 @@
1
1
  var _defaultStyles;
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
3
  /**
3
4
  * Copyright (c) 2021, RTE (http://www.rte-france.com)
4
5
  * This Source Code Form is subject to the terms of the Mozilla Public
@@ -7,7 +8,7 @@ var _defaultStyles;
7
8
  */
8
9
 
9
10
  import React, { useState, useCallback, useEffect } from 'react';
10
- import { FormattedMessage, useIntl } from 'react-intl';
11
+ import { useIntl } from 'react-intl';
11
12
  import PropTypes from 'prop-types';
12
13
  import { toNestedGlobalSelectors, makeComposeClasses } from '../../utils/styles';
13
14
  import { styled } from '@mui/system';
@@ -23,6 +24,7 @@ import Typography from '@mui/material/Typography';
23
24
  import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
24
25
  import ChevronRightIcon from '@mui/icons-material/ChevronRight';
25
26
  import CheckIcon from '@mui/icons-material/Check';
27
+ import CancelButton from '../react-hook-form/utils/cancel-button';
26
28
 
27
29
  // As a bunch of individual variables to try to make it easier
28
30
  // to track that they are all used. Not sure, maybe group them in an object ?
@@ -84,6 +86,7 @@ var composeClasses = makeComposeClasses(generateTreeViewFinderClass);
84
86
  * @param {String} [validationButtonText=default text] - Customized Validation Button text (default: Add N Elements)
85
87
  * @param {Boolean} [onlyLeaves=true] - Allow/Forbid selection only on leaves
86
88
  * @param {Boolean} [multiselect=false] - Allow/Forbid multiselection on Tree
89
+ * @param {Object} [cancelButtonProps] - The cancel button props
87
90
  */
88
91
  var TreeViewFinder = function TreeViewFinder(props) {
89
92
  var intl = useIntl();
@@ -100,7 +103,8 @@ var TreeViewFinder = function TreeViewFinder(props) {
100
103
  onlyLeaves = props.onlyLeaves,
101
104
  multiselect = props.multiselect,
102
105
  sortMethod = props.sortMethod,
103
- className = props.className;
106
+ className = props.className,
107
+ cancelButtonProps = props.cancelButtonProps;
104
108
  var _useState = useState({}),
105
109
  mapPrintedNodes = _useState[0],
106
110
  setMapPrintedNodes = _useState[1];
@@ -277,8 +281,7 @@ var TreeViewFinder = function TreeViewFinder(props) {
277
281
  multiSelect: multiselect
278
282
  }, data && Array.isArray(data) ? data.sort(sortMethod).map(function (child) {
279
283
  return renderTree(child);
280
- }) : null)), /*#__PURE__*/React.createElement(DialogActions, null, /*#__PURE__*/React.createElement(Button, {
281
- variant: "contained",
284
+ }) : null)), /*#__PURE__*/React.createElement(DialogActions, null, /*#__PURE__*/React.createElement(CancelButton, _extends({
282
285
  style: {
283
286
  "float": 'left',
284
287
  margin: '5px'
@@ -287,10 +290,8 @@ var TreeViewFinder = function TreeViewFinder(props) {
287
290
  _onClose([]);
288
291
  setSelected([]);
289
292
  }
290
- }, /*#__PURE__*/React.createElement(FormattedMessage, {
291
- id: "treeview_finder/cancel"
292
- })), /*#__PURE__*/React.createElement(Button, {
293
- variant: "contained",
293
+ }, cancelButtonProps)), /*#__PURE__*/React.createElement(Button, {
294
+ variant: "outlined",
294
295
  style: {
295
296
  "float": 'left',
296
297
  margin: '5px'
@@ -323,7 +324,8 @@ TreeViewFinder.propTypes = process.env.NODE_ENV !== "production" ? {
323
324
  defaultExpanded: PropTypes.arrayOf(PropTypes.string),
324
325
  onlyLeaves: PropTypes.bool,
325
326
  multiselect: PropTypes.bool,
326
- sortMethod: PropTypes.func
327
+ sortMethod: PropTypes.func,
328
+ cancelButtonProps: PropTypes.object
327
329
  } : {};
328
330
 
329
331
  /* TreeViewFinder props default values */
@@ -9,13 +9,51 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
9
9
  import React from 'react';
10
10
  import TextInput from '../text-input';
11
11
  import { isFloatNumber } from './utils';
12
+
13
+ // toLocaleString never uses exponential notation unlike toString. Avoiding
14
+ // exponential notation makes in place normalizing of numbers after each
15
+ // keystroke less intrusive: we can almost always normalize to a number that
16
+ // uses the same string representation as the intermediate text that the user
17
+ // typed. For example, if the user wants to input "625", they will write "6"
18
+ // and then "62" and then "625". The intermediate strings are numbers that have
19
+ // nothing in common with the final number but their normalization is the
20
+ // same as what was typed by the user. With exponential notation, if the user
21
+ // wants to input "12.5e21", at the intermediate step of "12.5e2" their input
22
+ // is normalized to "1.25e3" and after adding the final "1" they get "12.5e31"
23
+ // instead of "12.5e21".
24
+ // Note: with 16+ digits, two small problems in the current implementation appear:
25
+ // - rounding due to precision causes the cursor to jump at the end.
26
+ // - rounding due to precision causes the last digits of the number to jiggle.
27
+ // These two problems should be fixable with manual rounding and cursor
28
+ // handling if we need it.
29
+ var normalizeFixed = function normalizeFixed(number) {
30
+ return number.toLocaleString('en-US', {
31
+ maximumFractionDigits: 20,
32
+ useGrouping: false
33
+ });
34
+ };
12
35
  var FloatInput = function FloatInput(props) {
13
36
  var inputTransform = function inputTransform(value) {
14
- var sanitizedValue = value === null || value === void 0 ? void 0 : value.toString().replace(',', '.');
15
- if (['-', '.'].includes(sanitizedValue)) {
16
- return sanitizedValue;
37
+ if (typeof value == 'number' && !isNaN(value)) {
38
+ // if we have a parsed real number, normalize like we do after each
39
+ // keystroke in outputTransform for consistency. We get parsed
40
+ // numbers when the data doesn't come from a user edit in the form,
41
+ // but from data persisted as a float.
42
+ return normalizeFixed(value);
43
+ } else {
44
+ // The user is editing, leave as is because we already did what we
45
+ // need to do in outputTransform after the previous keystroke.
46
+ // NOTE: To avoid "bad things" we haven't predicted and be extra
47
+ // cautious, we clear the text on NaN, so we need to special case
48
+ // known inputs that would be rejected by isNaN but are accepted by
49
+ // our acceptValue because they are needed as intermediate strings
50
+ // for the user to input useful numbers.
51
+ // TODO can we remove the isNaN check and the special cases check?
52
+ if (['-', '.'].includes(value)) {
53
+ return value;
54
+ }
55
+ return value === null || isNaN(value) ? '' : value;
17
56
  }
18
- return sanitizedValue === null || isNaN(sanitizedValue) ? '' : sanitizedValue;
19
57
  };
20
58
  var outputTransform = function outputTransform(value) {
21
59
  if (value === '-') {
@@ -25,10 +63,37 @@ var FloatInput = function FloatInput(props) {
25
63
  return null;
26
64
  }
27
65
  var tmp = (value === null || value === void 0 ? void 0 : value.replace(',', '.')) || '';
28
- if (tmp.endsWith('.') || tmp.endsWith('0')) {
66
+
67
+ // Can't show the normalization to the user when the fractional part
68
+ // ends with 0 because normalizing removes the trailing zeroes and prevents
69
+ // inputting the required intermediate strings (e.g "1." or "1.0" to input "1.02")
70
+ // So we return the user string instead. This has the downside that
71
+ // when the user finally writes a non 0 digit at the end, the normalization takes place
72
+ // and may startle the user when changing a lot of its input text.
73
+ // For example:
74
+ // - "1.00000000000000000000000000" and then press any non zero digit
75
+ // removes all the zeroes at once
76
+ // - "1." or "1.0" and then left arrow to move the cursor to the left and then inputting many digits
77
+ // disables all normalization, can write huge numbers that are not rounded like
78
+ // - 1231231231241231241231245123124234234123123124234.
79
+ // vs 1231231231241231300000000000000000000000000000000
80
+ // - 1.4312322342321323434534234235234
81
+ // vs 1.4312322342321324
82
+ // Note: this is a symmetric problem inputting many zeros
83
+ // to the left of a number to allow to input a final leading nonzero
84
+ // digit, but users never want to do that, unlike inputting trailing zeroes in the
85
+ // fractional part before inputing the final trailing non zero digit
86
+ if (tmp.endsWith('.') || tmp.includes('.') && tmp.endsWith('0')) {
29
87
  return tmp;
30
88
  }
31
- return parseFloat(tmp) || null;
89
+
90
+ // normalize after each user keystroke, needs to be very unintrusive
91
+ // otherwise users are surprised when typing doesn't do what they want
92
+ // NOTE: the parse should always succeed and produce non-NaN because we
93
+ // restrict what the user can type with "acceptValue" but if we
94
+ // have a bug just clear the data instead of sending "NaN"
95
+ var parsed = parseFloat(tmp);
96
+ return isNaN(parsed) ? null : normalizeFixed(parsed);
32
97
  };
33
98
  return /*#__PURE__*/React.createElement(TextInput, _extends({
34
99
  acceptValue: isFloatNumber,
@@ -1,26 +1,23 @@
1
+ function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ /**
4
+ * Copyright (c) 2023, RTE (http://www.rte-france.com)
5
+ * This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
1
10
  import React from 'react';
2
11
  import { Button } from '@mui/material';
3
12
  import { FormattedMessage } from 'react-intl';
4
13
  import PropTypes from 'prop-types';
5
14
  var CancelButton = function CancelButton(_ref) {
6
- var onClick = _ref.onClick,
7
- variant = _ref.variant,
8
- disabled = _ref.disabled,
9
- _ref$withCustomColor = _ref.withCustomColor,
10
- withCustomColor = _ref$withCustomColor === void 0 ? true : _ref$withCustomColor;
11
- return /*#__PURE__*/React.createElement(Button, {
12
- onClick: onClick,
13
- variant: variant,
14
- disabled: disabled,
15
- color: withCustomColor ? 'customButton' : 'primary'
16
- }, /*#__PURE__*/React.createElement(FormattedMessage, {
15
+ var buttonProps = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
16
+ return /*#__PURE__*/React.createElement(Button, buttonProps, /*#__PURE__*/React.createElement(FormattedMessage, {
17
17
  id: "cancel"
18
18
  }));
19
19
  };
20
20
  CancelButton.propTypes = process.env.NODE_ENV !== "production" ? {
21
- onClick: PropTypes.func.isRequired,
22
- variant: PropTypes.string,
23
- disabled: PropTypes.bool,
24
- withCustomColor: PropTypes.bool
21
+ buttonProps: PropTypes.object
25
22
  } : {};
26
23
  export default CancelButton;
@@ -1,3 +1,5 @@
1
+ function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1
3
  /**
2
4
  * Copyright (c) 2022, RTE (http://www.rte-france.com)
3
5
  * This Source Code Form is subject to the terms of the Mozilla Public
@@ -9,17 +11,19 @@ import React from 'react';
9
11
  import { Button } from '@mui/material';
10
12
  import { useFormState } from 'react-hook-form';
11
13
  import { FormattedMessage } from 'react-intl';
14
+ import PropTypes from 'prop-types';
12
15
  var SubmitButton = function SubmitButton(_ref) {
13
- var onClick = _ref.onClick,
14
- _ref$disabled = _ref.disabled,
15
- disabled = _ref$disabled === void 0 ? false : _ref$disabled;
16
+ var _buttonProps$disabled;
17
+ var buttonProps = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
16
18
  var _useFormState = useFormState(),
17
19
  isDirty = _useFormState.isDirty;
18
- return /*#__PURE__*/React.createElement(Button, {
19
- onClick: onClick,
20
- disabled: !isDirty || disabled
21
- }, /*#__PURE__*/React.createElement(FormattedMessage, {
20
+ return /*#__PURE__*/React.createElement(Button, _extends({}, buttonProps, {
21
+ disabled: !isDirty || ((_buttonProps$disabled = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.disabled) !== null && _buttonProps$disabled !== void 0 ? _buttonProps$disabled : false)
22
+ }), /*#__PURE__*/React.createElement(FormattedMessage, {
22
23
  id: "validate"
23
24
  }));
24
25
  };
26
+ SubmitButton.propTypes = process.env.NODE_ENV !== "production" ? {
27
+ buttonProps: PropTypes.object
28
+ } : {};
25
29
  export default SubmitButton;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2023, 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
+
8
+ var common_button_en = {
9
+ cancel: 'Cancel',
10
+ validate: 'Validate'
11
+ };
12
+ export default common_button_en;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2023, 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
+
8
+ var common_button_fr = {
9
+ cancel: 'Annuler',
10
+ validate: 'Valider'
11
+ };
12
+ export default common_button_fr;
@@ -7,7 +7,6 @@
7
7
 
8
8
  var treeview_finder_en = {
9
9
  'treeview_finder/close': 'Close',
10
- 'treeview_finder/cancel': 'Cancel',
11
10
  'treeview_finder/validate': 'Validate',
12
11
  'treeview_finder/add': 'Add...',
13
12
  'treeview_finder/deleteSelection': 'Delete selection',
@@ -7,7 +7,6 @@
7
7
 
8
8
  var treeview_finder_fr = {
9
9
  'treeview_finder/close': 'Fermer',
10
- 'treeview_finder/cancel': 'Annuler',
11
10
  'treeview_finder/validate': 'Valider',
12
11
  'treeview_finder/add': 'Ajouter...',
13
12
  'treeview_finder/deleteSelection': 'Supprimer la selection',
package/es/index.js CHANGED
@@ -43,6 +43,8 @@ export { default as flat_parameters_en } from './components/translations/flat-pa
43
43
  export { default as flat_parameters_fr } from './components/translations/flat-parameters-fr';
44
44
  export { default as multiple_selection_dialog_en } from './components/translations/multiple-selection-dialog-en';
45
45
  export { default as multiple_selection_dialog_fr } from './components/translations/multiple-selection-dialog-fr';
46
+ export { default as common_button_en } from './components/translations/common-button-en';
47
+ export { default as common_button_fr } from './components/translations/common-button-fr';
46
48
  export { TagRenderer } from './components/ElementSearchDialog';
47
49
  export { EquipmentItem } from './components/ElementSearchDialog/equipment-item';
48
50
  export { default as CardErrorBoundary } from './components/CardErrorBoundary';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.38.0",
3
+ "version": "0.40.0",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "engines": {
6
6
  "npm": ">=9",