@gridsuite/commons-ui 0.56.0 → 0.58.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 (175) hide show
  1. package/dist/_mocks_/svg.d.ts +4 -0
  2. package/dist/_mocks_/svg.js +8 -0
  3. package/dist/chunks/{criteria-based-filter-edition-dialog.DxqH-mLe.js → criteria-based-filter-edition-dialog.CbhgOSRk.js} +140 -111
  4. package/dist/chunks/{filter-properties.GRon8-ML.js → filter-properties.B7-q_yPf.js} +4 -4
  5. package/dist/components/DirectoryItemSelector/directory-item-selector.js +2 -1
  6. package/dist/components/ElementSearchDialog/element-search-dialog.d.ts +18 -15
  7. package/dist/components/ElementSearchDialog/element-search-dialog.js +28 -65
  8. package/dist/components/ElementSearchDialog/equipment-item.js +4 -3
  9. package/dist/components/OverflowableText/overflowable-text.js +39 -9
  10. package/dist/components/TopBar/TopBar.js +371 -429
  11. package/dist/components/TreeViewFinder/TreeViewFinder.js +1 -1
  12. package/dist/components/TreeViewFinder/index.d.ts +7 -0
  13. package/dist/components/dialogs/custom-mui-dialog.d.ts +2 -1
  14. package/dist/components/dialogs/custom-mui-dialog.js +6 -4
  15. package/dist/components/dialogs/description-modification-dialog.js +2 -2
  16. package/dist/components/dialogs/modify-element-selection.d.ts +14 -0
  17. package/dist/components/dialogs/modify-element-selection.js +108 -0
  18. package/dist/components/dialogs/popup-confirmation-dialog.js +1 -1
  19. package/dist/components/filter/criteria-based/criteria-based-filter-edition-dialog.d.ts +1 -2
  20. package/dist/components/filter/criteria-based/criteria-based-filter-edition-dialog.js +4 -4
  21. package/dist/components/filter/criteria-based/criteria-based-filter-form.js +5 -3
  22. package/dist/components/filter/criteria-based/criteria-based-filter-utils.d.ts +12 -6
  23. package/dist/components/filter/criteria-based/criteria-based-filter-utils.js +44 -4
  24. package/dist/components/filter/criteria-based/criteria-based-form.d.ts +2 -0
  25. package/dist/components/filter/criteria-based/criteria-based-form.js +6 -6
  26. package/dist/components/filter/criteria-based/filter-free-properties.js +5 -5
  27. package/dist/components/filter/criteria-based/filter-properties.js +3 -3
  28. package/dist/components/filter/criteria-based/filter-property.js +3 -3
  29. package/dist/components/filter/{constants → expert}/expert-filter-constants.d.ts +5 -0
  30. package/dist/components/filter/{constants → expert}/expert-filter-constants.js +12 -6
  31. package/dist/components/filter/expert/expert-filter-edition-dialog.d.ts +3 -3
  32. package/dist/components/filter/expert/expert-filter-edition-dialog.js +5 -6
  33. package/dist/components/filter/expert/expert-filter-form.js +5 -5
  34. package/dist/components/filter/expert/expert-filter-utils.d.ts +73 -1
  35. package/dist/components/filter/expert/expert-filter-utils.js +8 -6
  36. package/dist/components/filter/expert/expert-filter.type.d.ts +1 -0
  37. package/dist/components/filter/expert/expert-filter.type.js +1 -0
  38. package/dist/components/filter/explicit-naming/explicit-naming-filter-edition-dialog.d.ts +0 -2
  39. package/dist/components/filter/explicit-naming/explicit-naming-filter-edition-dialog.js +4 -4
  40. package/dist/components/filter/explicit-naming/explicit-naming-filter-form.d.ts +10 -2
  41. package/dist/components/filter/explicit-naming/explicit-naming-filter-form.js +12 -8
  42. package/dist/components/filter/filter-context.d.ts +1 -0
  43. package/dist/components/filter/filter-context.js +2 -1
  44. package/dist/components/filter/filter-creation-dialog.d.ts +5 -2
  45. package/dist/components/filter/filter-creation-dialog.js +3 -3
  46. package/dist/components/filter/filter-form.d.ts +4 -0
  47. package/dist/components/filter/filter-form.js +6 -5
  48. package/dist/components/filter/utils/filter-api.d.ts +5 -0
  49. package/dist/components/filter/utils/{filters-utils.js → filter-api.js} +16 -10
  50. package/dist/components/filter/utils/filter-form-utils.d.ts +17 -0
  51. package/dist/components/filter/utils/{criteria-based-utils.js → filter-form-utils.js} +5 -45
  52. package/dist/components/{react-hook-form/ag-grid-table-rhf → inputs/react-hook-form/ag-grid-table}/bottom-right-buttons.js +1 -1
  53. package/dist/components/{react-hook-form/ag-grid-table-rhf → inputs/react-hook-form/ag-grid-table}/csv-uploader/csv-uploader.js +23 -23
  54. package/dist/components/{react-hook-form/ag-grid-table-rhf → inputs/react-hook-form/ag-grid-table}/custom-ag-grid-table.js +2 -2
  55. package/dist/components/{react-hook-form → inputs/react-hook-form/autocomplete-inputs}/autocomplete-input.d.ts +3 -3
  56. package/dist/components/{react-hook-form → inputs/react-hook-form/autocomplete-inputs}/autocomplete-input.js +4 -4
  57. package/dist/components/{react-hook-form → inputs/react-hook-form}/autocomplete-inputs/multiple-autocomplete-input.js +1 -1
  58. package/dist/components/{react-hook-form → inputs/react-hook-form}/directory-items-input.js +5 -5
  59. package/dist/components/{react-hook-form → inputs/react-hook-form}/numbers/integer-input.d.ts +3 -3
  60. package/dist/components/{react-hook-form → inputs/react-hook-form}/provider/custom-form-provider.js +1 -1
  61. package/dist/components/{react-hook-form → inputs/react-hook-form}/range-input.d.ts +1 -1
  62. package/dist/components/{react-hook-form → inputs/react-hook-form}/range-input.js +2 -2
  63. package/dist/components/{react-hook-form → inputs/react-hook-form}/select-inputs/countries-input.d.ts +1 -1
  64. package/dist/components/{react-hook-form → inputs/react-hook-form}/select-inputs/countries-input.js +2 -3
  65. package/dist/components/{react-hook-form → inputs/react-hook-form}/select-inputs/input-with-popup-confirmation.js +1 -1
  66. package/dist/components/{react-hook-form → inputs/react-hook-form}/select-inputs/select-input.d.ts +2 -2
  67. package/dist/components/{react-hook-form → inputs/react-hook-form}/select-inputs/select-input.js +4 -1
  68. package/dist/components/{react-hook-form → inputs/react-hook-form}/text-input.d.ts +1 -1
  69. package/dist/components/{react-hook-form → inputs/react-hook-form}/unique-name-input.d.ts +2 -2
  70. package/dist/components/{react-hook-form → inputs/react-hook-form}/unique-name-input.js +2 -2
  71. package/dist/components/{react-hook-form → inputs/react-hook-form}/utils/text-field-with-adornment.d.ts +1 -1
  72. package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/combinator-selector.js +1 -1
  73. package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/country-value-editor.js +1 -1
  74. package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/custom-react-query-builder.js +3 -3
  75. package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/element-value-editor.js +22 -22
  76. package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/property-value-editor.js +3 -3
  77. package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/remove-button.js +2 -2
  78. package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/use-convert-value.js +1 -1
  79. package/dist/components/inputs/react-query-builder/value-editor.js +18 -0
  80. package/dist/components/inputs/select-clearable.js +1 -1
  81. package/dist/components/translations/filter-en.d.ts +22 -0
  82. package/dist/components/translations/filter-en.js +23 -0
  83. package/dist/components/translations/filter-fr.d.ts +22 -0
  84. package/dist/components/translations/filter-fr.js +23 -0
  85. package/dist/hooks/useDebounce.d.ts +1 -1
  86. package/dist/hooks/useSnackMessage.d.ts +4 -7
  87. package/dist/hooks/useSnackMessage.js +36 -43
  88. package/dist/index.d.ts +53 -39
  89. package/dist/index.js +129 -116
  90. package/dist/redux/commonStore.d.ts +15 -0
  91. package/dist/redux/commonStore.js +11 -0
  92. package/dist/services/explore.d.ts +4 -0
  93. package/dist/services/explore.js +34 -0
  94. package/dist/services/study.d.ts +3 -0
  95. package/dist/services/study.js +16 -0
  96. package/dist/services/utils.d.ts +8 -0
  97. package/dist/services/utils.js +58 -0
  98. package/dist/utils/AuthService.js +1 -1
  99. package/dist/utils/types.d.ts +1 -1
  100. package/package.json +9 -9
  101. package/dist/components/filter/utils/criteria-based-utils.d.ts +0 -28
  102. package/dist/components/filter/utils/filters-utils.d.ts +0 -5
  103. package/dist/components/react-query-builder-inputs/value-editor.js +0 -18
  104. /package/dist/components/{react-hook-form → inputs/react-hook-form}/ExpandingTextField.d.ts +0 -0
  105. /package/dist/components/{react-hook-form → inputs/react-hook-form}/ExpandingTextField.js +0 -0
  106. /package/dist/components/{react-hook-form/ag-grid-table-rhf → inputs/react-hook-form/ag-grid-table}/bottom-right-buttons.d.ts +0 -0
  107. /package/dist/components/{react-hook-form/ag-grid-table-rhf → inputs/react-hook-form/ag-grid-table}/cell-editors/numericEditor.d.ts +0 -0
  108. /package/dist/components/{react-hook-form/ag-grid-table-rhf → inputs/react-hook-form/ag-grid-table}/cell-editors/numericEditor.js +0 -0
  109. /package/dist/components/{react-hook-form/ag-grid-table-rhf → inputs/react-hook-form/ag-grid-table}/csv-uploader/csv-uploader.d.ts +0 -0
  110. /package/dist/components/{react-hook-form/ag-grid-table-rhf → inputs/react-hook-form/ag-grid-table}/custom-ag-grid-table.d.ts +0 -0
  111. /package/dist/components/{react-hook-form → inputs/react-hook-form}/autocomplete-inputs/multiple-autocomplete-input.d.ts +0 -0
  112. /package/dist/components/{react-hook-form → inputs/react-hook-form}/booleans/boolean-input.d.ts +0 -0
  113. /package/dist/components/{react-hook-form → inputs/react-hook-form}/booleans/boolean-input.js +0 -0
  114. /package/dist/components/{react-hook-form → inputs/react-hook-form}/booleans/checkbox-input.d.ts +0 -0
  115. /package/dist/components/{react-hook-form → inputs/react-hook-form}/booleans/checkbox-input.js +0 -0
  116. /package/dist/components/{react-hook-form → inputs/react-hook-form}/booleans/switch-input.d.ts +0 -0
  117. /package/dist/components/{react-hook-form → inputs/react-hook-form}/booleans/switch-input.js +0 -0
  118. /package/dist/components/{react-hook-form → inputs/react-hook-form}/directory-items-input.d.ts +0 -0
  119. /package/dist/components/{react-hook-form → inputs/react-hook-form}/error-management/error-input.d.ts +0 -0
  120. /package/dist/components/{react-hook-form → inputs/react-hook-form}/error-management/error-input.js +0 -0
  121. /package/dist/components/{react-hook-form → inputs/react-hook-form}/error-management/field-error-alert.d.ts +0 -0
  122. /package/dist/components/{react-hook-form → inputs/react-hook-form}/error-management/field-error-alert.js +0 -0
  123. /package/dist/components/{react-hook-form → inputs/react-hook-form}/error-management/mid-form-error.d.ts +0 -0
  124. /package/dist/components/{react-hook-form → inputs/react-hook-form}/error-management/mid-form-error.js +0 -0
  125. /package/dist/components/{react-hook-form → inputs/react-hook-form}/numbers/float-input.d.ts +0 -0
  126. /package/dist/components/{react-hook-form → inputs/react-hook-form}/numbers/float-input.js +0 -0
  127. /package/dist/components/{react-hook-form → inputs/react-hook-form}/numbers/integer-input.js +0 -0
  128. /package/dist/components/{react-hook-form → inputs/react-hook-form}/numbers/utils.d.ts +0 -0
  129. /package/dist/components/{react-hook-form → inputs/react-hook-form}/numbers/utils.js +0 -0
  130. /package/dist/components/{react-hook-form → inputs/react-hook-form}/provider/custom-form-provider.d.ts +0 -0
  131. /package/dist/components/{react-hook-form → inputs/react-hook-form}/provider/use-custom-form-context.d.ts +0 -0
  132. /package/dist/components/{react-hook-form → inputs/react-hook-form}/provider/use-custom-form-context.js +0 -0
  133. /package/dist/components/{react-hook-form → inputs/react-hook-form}/radio-input.d.ts +0 -0
  134. /package/dist/components/{react-hook-form → inputs/react-hook-form}/radio-input.js +0 -0
  135. /package/dist/components/{react-hook-form → inputs/react-hook-form}/raw-read-only-input.d.ts +0 -0
  136. /package/dist/components/{react-hook-form → inputs/react-hook-form}/raw-read-only-input.js +0 -0
  137. /package/dist/components/{react-hook-form → inputs/react-hook-form}/select-inputs/input-with-popup-confirmation.d.ts +0 -0
  138. /package/dist/components/{react-hook-form → inputs/react-hook-form}/select-inputs/mui-select-input.d.ts +0 -0
  139. /package/dist/components/{react-hook-form → inputs/react-hook-form}/select-inputs/mui-select-input.js +0 -0
  140. /package/dist/components/{react-hook-form → inputs/react-hook-form}/slider-input.d.ts +0 -0
  141. /package/dist/components/{react-hook-form → inputs/react-hook-form}/slider-input.js +0 -0
  142. /package/dist/components/{react-hook-form → inputs/react-hook-form}/text-input.js +0 -0
  143. /package/dist/components/{react-hook-form → inputs/react-hook-form}/utils/cancel-button.d.ts +0 -0
  144. /package/dist/components/{react-hook-form → inputs/react-hook-form}/utils/cancel-button.js +0 -0
  145. /package/dist/components/{react-hook-form → inputs/react-hook-form}/utils/field-label.d.ts +0 -0
  146. /package/dist/components/{react-hook-form → inputs/react-hook-form}/utils/field-label.js +0 -0
  147. /package/dist/components/{react-hook-form → inputs/react-hook-form}/utils/functions.d.ts +0 -0
  148. /package/dist/components/{react-hook-form → inputs/react-hook-form}/utils/functions.js +0 -0
  149. /package/dist/components/{react-hook-form → inputs/react-hook-form}/utils/submit-button.d.ts +0 -0
  150. /package/dist/components/{react-hook-form → inputs/react-hook-form}/utils/submit-button.js +0 -0
  151. /package/dist/components/{react-hook-form → inputs/react-hook-form}/utils/text-field-with-adornment.js +0 -0
  152. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/add-button.d.ts +0 -0
  153. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/add-button.js +0 -0
  154. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/combinator-selector.d.ts +0 -0
  155. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/country-value-editor.d.ts +0 -0
  156. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/custom-react-query-builder.d.ts +0 -0
  157. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/element-value-editor.d.ts +0 -0
  158. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/property-value-editor.d.ts +0 -0
  159. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/remove-button.d.ts +0 -0
  160. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/text-value-editor.d.ts +0 -0
  161. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/text-value-editor.js +0 -0
  162. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/translated-value-editor.d.ts +0 -0
  163. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/translated-value-editor.js +0 -0
  164. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/use-convert-value.d.ts +0 -0
  165. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/use-valid.d.ts +0 -0
  166. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/use-valid.js +0 -0
  167. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/value-editor.d.ts +0 -0
  168. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/value-selector.d.ts +0 -0
  169. /package/dist/components/{react-query-builder-inputs → inputs/react-query-builder}/value-selector.js +0 -0
  170. /package/dist/{utils → redux}/actions.d.ts +0 -0
  171. /package/dist/{utils → redux}/actions.js +0 -0
  172. /package/dist/{components/filter/constants → utils}/equipment-types.d.ts +0 -0
  173. /package/dist/{components/filter/constants → utils}/equipment-types.js +0 -0
  174. /package/dist/{components/filter/constants → utils}/field-constants.d.ts +0 -0
  175. /package/dist/{components/filter/constants → utils}/field-constants.js +0 -0
@@ -1,7 +1,6 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import { useState, useEffect, useCallback } from "react";
2
+ import { useMemo, useCallback } from "react";
3
3
  import { Dialog, DialogContent, Autocomplete, TextField } from "@mui/material";
4
- import PropTypes from "prop-types";
5
4
  import { SearchOff, Search } from "@mui/icons-material";
6
5
  import { useIntl } from "react-intl";
7
6
  const ElementSearchDialog = (props) => {
@@ -10,48 +9,23 @@ const ElementSearchDialog = (props) => {
10
9
  open,
11
10
  onClose,
12
11
  searchingLabel,
12
+ searchTerm,
13
13
  onSearchTermChange,
14
14
  onSelectionChange,
15
15
  elementsFound,
16
- // [{ label: aLabel, id: anId }, ...]
17
16
  renderElement,
18
17
  searchTermDisabled,
19
- searchTermDisableReason
18
+ searchTermDisableReason,
19
+ isLoading,
20
+ loadingText
20
21
  } = props;
21
- const [expanded, setExpanded] = useState(false);
22
- const [value, setValue] = useState(
23
- searchTermDisabled && searchTermDisableReason ? { label: searchTermDisableReason } : null
24
- );
25
- const [loading, setLoading] = useState(false);
26
- useEffect(() => {
27
- setLoading(false);
28
- }, [elementsFound]);
29
- useEffect(() => {
30
- if (!searchTermDisabled || !searchTermDisableReason) {
31
- setValue(null);
32
- } else {
33
- setValue({ label: searchTermDisableReason });
34
- }
35
- }, [searchTermDisabled, searchTermDisableReason]);
36
- useEffect(() => {
37
- setValue((old) => !open ? null : old);
38
- }, [open]);
39
- const handleSearchTermChange = (term) => {
40
- if (term) {
41
- setLoading(true);
42
- onSearchTermChange(term);
43
- setExpanded(true);
44
- setValue({ label: term });
45
- } else {
46
- setExpanded(false);
47
- setValue(null);
48
- }
49
- };
22
+ const displayedValue = useMemo(() => {
23
+ return searchTermDisabled || searchTermDisableReason ? searchTermDisableReason : searchTerm;
24
+ }, [searchTerm, searchTermDisabled, searchTermDisableReason]);
50
25
  const handleClose = useCallback(() => {
51
- setValue(null);
52
- setExpanded(false);
26
+ onSearchTermChange("");
53
27
  onClose();
54
- }, [onClose]);
28
+ }, [onSearchTermChange, onClose]);
55
29
  return /* @__PURE__ */ jsx(
56
30
  Dialog,
57
31
  {
@@ -63,32 +37,32 @@ const ElementSearchDialog = (props) => {
63
37
  children: /* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(
64
38
  Autocomplete,
65
39
  {
40
+ open: isLoading || (elementsFound == null ? void 0 : elementsFound.length) > 0,
66
41
  id: "element-search",
67
42
  forcePopupIcon: false,
68
- open: expanded,
69
- onClose: () => {
70
- setExpanded(false);
71
- },
72
43
  fullWidth: true,
73
44
  freeSolo: true,
74
- clearOnBlur: true,
75
- onInputChange: (_event, value2) => {
76
- if (!searchTermDisabled) {
77
- handleSearchTermChange(value2);
45
+ onInputChange: (_event, value, reason) => {
46
+ if (!searchTermDisabled && reason !== "reset") {
47
+ onSearchTermChange(value);
78
48
  }
79
49
  },
80
50
  onChange: (_event, newValue, reason) => {
81
- if (reason === "selectOption") {
51
+ if (newValue != null && typeof newValue !== "string" && reason === "selectOption") {
82
52
  onSelectionChange(newValue);
83
- setValue(newValue);
53
+ }
54
+ },
55
+ getOptionLabel: (option) => typeof option === "string" ? option : option.label,
56
+ isOptionEqualToValue: (option, value) => {
57
+ if (typeof option === "string" || typeof value === "string") {
58
+ return option === value;
84
59
  } else {
85
- setValue(null);
60
+ return option.id === value.id;
86
61
  }
87
62
  },
88
- getOptionLabel: (option) => option.label,
89
- isOptionEqualToValue: (option, value2) => option.id === value2.id,
90
- options: loading ? [] : elementsFound,
91
- loading,
63
+ options: isLoading ? [] : elementsFound,
64
+ loading: isLoading,
65
+ loadingText,
92
66
  autoHighlight: true,
93
67
  noOptionsText: intl.formatMessage({
94
68
  id: "element_search/noResult"
@@ -104,7 +78,7 @@ const ElementSearchDialog = (props) => {
104
78
  {
105
79
  autoFocus: true,
106
80
  ...params,
107
- label: searchingLabel || intl.formatMessage({
81
+ label: searchingLabel ?? intl.formatMessage({
108
82
  id: "element_search/label"
109
83
  }),
110
84
  InputProps: {
@@ -113,27 +87,16 @@ const ElementSearchDialog = (props) => {
113
87
  searchTermDisabled ? /* @__PURE__ */ jsx(SearchOff, { color: "disabled" }) : /* @__PURE__ */ jsx(Search, { color: "disabled" }),
114
88
  params.InputProps.startAdornment
115
89
  ] })
116
- }
90
+ },
91
+ value: displayedValue ?? ""
117
92
  }
118
93
  ),
119
- value,
120
94
  disabled: searchTermDisabled
121
95
  }
122
96
  ) })
123
97
  }
124
98
  );
125
99
  };
126
- ElementSearchDialog.propTypes = {
127
- open: PropTypes.bool.isRequired,
128
- onClose: PropTypes.func.isRequired,
129
- searchingLabel: PropTypes.string,
130
- onSearchTermChange: PropTypes.func.isRequired,
131
- onSelectionChange: PropTypes.func.isRequired,
132
- elementsFound: PropTypes.array.isRequired,
133
- renderElement: PropTypes.func.isRequired,
134
- searchTermDisabled: PropTypes.bool,
135
- searchTermDisableReason: PropTypes.string
136
- };
137
100
  export {
138
101
  ElementSearchDialog as default
139
102
  };
@@ -1,13 +1,14 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import "./element-search-dialog.js";
2
+ import "react";
3
+ import { Box } from "@mui/material";
4
+ import "@mui/icons-material";
5
+ import { FormattedMessage } from "react-intl";
3
6
  import { TagRenderer } from "./tag-renderer.js";
4
7
  import match from "autosuggest-highlight/match";
5
8
  import parse from "autosuggest-highlight/parse";
6
9
  import clsx from "clsx";
7
- import { FormattedMessage } from "react-intl";
8
10
  import { OverflowableText } from "../OverflowableText/overflowable-text.js";
9
11
  import { EQUIPMENT_TYPE } from "../../utils/EquipmentType.js";
10
- import { Box } from "@mui/material";
11
12
  import { mergeSx } from "../../utils/styles.js";
12
13
  const EquipmentItem = ({
13
14
  inputValue,
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useRef, useState, useCallback, useLayoutEffect } from "react";
2
+ import { useRef, useMemo, useState, useCallback, useLayoutEffect } from "react";
3
3
  import { Tooltip, Box } from "@mui/material";
4
4
  import PropTypes from "prop-types";
5
5
  import { styled } from "@mui/system";
@@ -16,26 +16,56 @@ const overflowStyle = {
16
16
  maxWidth: "fit-content"
17
17
  }
18
18
  };
19
+ const multilineOverflowStyle = (numberOfLinesToDisplay) => ({
20
+ overflow: "hidden",
21
+ display: "-webkit-box",
22
+ WebkitLineClamp: numberOfLinesToDisplay,
23
+ lineClamp: numberOfLinesToDisplay,
24
+ WebkitBoxOrient: "vertical",
25
+ wordWrap: "break-word"
26
+ // prevent bug when writing a very long word
27
+ });
19
28
  const OverflowableText = styled(
20
- ({ text, tooltipStyle, tooltipSx, className, children, ...props }) => {
21
- var _a, _b;
29
+ ({
30
+ text,
31
+ maxLineCount,
32
+ // overflowable text can be displayed on several lines if this is set to a number > 1
33
+ tooltipStyle,
34
+ tooltipSx,
35
+ className,
36
+ children,
37
+ ...props
38
+ }) => {
39
+ var _a, _b, _c, _d;
22
40
  const element = useRef();
41
+ const isMultiLine = useMemo(
42
+ () => maxLineCount && maxLineCount > 1,
43
+ [maxLineCount]
44
+ );
23
45
  const [overflowed, setOverflowed] = useState(false);
24
46
  const checkOverflow = useCallback(() => {
25
47
  if (!element.current) {
26
48
  return;
27
49
  }
28
- setOverflowed(
29
- element.current.scrollWidth > element.current.clientWidth
30
- );
31
- }, [setOverflowed, element]);
50
+ if (isMultiLine) {
51
+ setOverflowed(
52
+ element.current.scrollHeight > element.current.clientHeight
53
+ );
54
+ } else {
55
+ setOverflowed(
56
+ element.current.scrollWidth > element.current.clientWidth
57
+ );
58
+ }
59
+ }, [isMultiLine, setOverflowed, element]);
32
60
  useLayoutEffect(() => {
33
61
  checkOverflow();
34
62
  }, [
35
63
  checkOverflow,
36
64
  text,
37
65
  (_a = element.current) == null ? void 0 : _a.scrollWidth,
38
- (_b = element.current) == null ? void 0 : _b.clientWidth
66
+ (_b = element.current) == null ? void 0 : _b.clientWidth,
67
+ (_c = element.current) == null ? void 0 : _c.scrollHeight,
68
+ (_d = element.current) == null ? void 0 : _d.clientHeight
39
69
  ]);
40
70
  const defaultTooltipSx = !tooltipStyle ? overflowStyle.tooltip : false;
41
71
  const finalTooltipSx = tooltipSx || defaultTooltipSx;
@@ -58,7 +88,7 @@ const OverflowableText = styled(
58
88
  ref: element,
59
89
  children: children || text,
60
90
  className,
61
- sx: overflowStyle.overflow
91
+ sx: isMultiLine ? multilineOverflowStyle(maxLineCount) : overflowStyle.overflow
62
92
  }
63
93
  )
64
94
  }