@gridsuite/commons-ui 0.97.0 → 0.98.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.
@@ -11,10 +11,11 @@ export interface DirectoryItemsInputProps {
11
11
  onRowChanged?: (a: boolean) => void;
12
12
  onChange?: (e: any) => void;
13
13
  disable?: boolean;
14
+ allowMultiSelect?: boolean;
14
15
  labelRequiredFromContext?: boolean;
15
16
  }
16
17
  export declare function DirectoryItemsInput({ label, name, elementType, // Used to specify type of element (Filter, Contingency list, ...)
17
18
  equipmentTypes, // Mostly used for filters, it allows the user to get elements of specific equipment only
18
19
  itemFilter, // Used to further filter the results displayed according to specific requirement
19
20
  titleId, // title of directory item selector dialogue
20
- hideErrorMessage, onRowChanged, onChange, disable, labelRequiredFromContext, }: DirectoryItemsInputProps): import("react/jsx-runtime").JSX.Element;
21
+ hideErrorMessage, onRowChanged, onChange, disable, allowMultiSelect, labelRequiredFromContext, }: Readonly<DirectoryItemsInputProps>): import("react/jsx-runtime").JSX.Element;
@@ -58,13 +58,14 @@ function DirectoryItemsInput({
58
58
  onRowChanged,
59
59
  onChange,
60
60
  disable = false,
61
+ allowMultiSelect = true,
61
62
  labelRequiredFromContext = true
62
63
  }) {
63
64
  const { snackError } = useSnackMessage();
64
65
  const intl = useIntl();
65
66
  const [selected, setSelected] = useState([]);
66
67
  const [expanded, setExpanded] = useState([]);
67
- const [multiSelect, setMultiSelect] = useState(true);
68
+ const [multiSelect, setMultiSelect] = useState(allowMultiSelect);
68
69
  const types = useMemo(() => [elementType], [elementType]);
69
70
  const [directoryItemSelectorOpen, setDirectoryItemSelectorOpen] = useState(false);
70
71
  const {
@@ -134,6 +135,9 @@ function DirectoryItemsInput({
134
135
  },
135
136
  [getValues, name]
136
137
  );
138
+ const shouldReplaceElement = useMemo(() => {
139
+ return allowMultiSelect === false && (elements == null ? void 0 : elements.length) === 1;
140
+ }, [allowMultiSelect, elements]);
137
141
  return /* @__PURE__ */ jsxs(Fragment, { children: [
138
142
  /* @__PURE__ */ jsxs(
139
143
  FormControl,
@@ -175,8 +179,14 @@ function DirectoryItemsInput({
175
179
  size: "small",
176
180
  disabled: disable,
177
181
  onClick: () => {
178
- setDirectoryItemSelectorOpen(true);
179
- setMultiSelect(true);
182
+ if (shouldReplaceElement) {
183
+ handleChipClick(0);
184
+ } else {
185
+ setDirectoryItemSelectorOpen(true);
186
+ if (allowMultiSelect) {
187
+ setMultiSelect(true);
188
+ }
189
+ }
180
190
  },
181
191
  children: /* @__PURE__ */ jsx(Folder, {})
182
192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.97.0",
3
+ "version": "0.98.0",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "author": "gridsuite team",
6
6
  "homepage": "https://github.com/gridsuite",