@gisce/react-ooui 1.5.8-rc.0 → 1.5.9-rc.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/react-ooui",
3
- "version": "1.5.8-rc.0",
3
+ "version": "1.5.9-rc.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "src",
@@ -11,7 +11,7 @@ type Props = {
11
11
  icon: any;
12
12
  label?: string;
13
13
  disabled?: boolean;
14
- searchable?: true | false | 'auto';
14
+ searchable?: true | false | "auto";
15
15
  };
16
16
 
17
17
  function DropdownButton(props: Props) {
@@ -22,30 +22,56 @@ function DropdownButton(props: Props) {
22
22
  onItemClick,
23
23
  label,
24
24
  disabled = false,
25
- searchable = 'auto',
25
+ searchable = "auto",
26
26
  } = props;
27
- const [ filteredItems, setFilteredItems ] = useState([...items]);
27
+ const [searchValue, setSearchValue] = useState<string>();
28
28
 
29
- const onSearch = (value:string) => {
29
+ const onSearch = (value?: string) => {
30
30
  if (!value) {
31
- setFilteredItems([...items]);
32
- } else {
33
- setFilteredItems(items.filter((item) => item.name.toLowerCase().indexOf(value.toLowerCase()) !== -1))
31
+ setSearchValue(undefined);
32
+ return;
33
+ }
34
+
35
+ const sanitizedValue = value.trim();
36
+
37
+ if (sanitizedValue.length === 0) {
38
+ setSearchValue(undefined);
39
+ return;
34
40
  }
35
- }
41
+
42
+ setSearchValue(sanitizedValue);
43
+ };
36
44
 
37
45
  function getMenu() {
38
- const menuItems = filteredItems?.map((item, idx) => {
46
+ let itemsData = [];
47
+ if (searchValue) {
48
+ itemsData = items.filter((item) => {
49
+ return item.name.toLowerCase().includes(searchValue.toLowerCase());
50
+ });
51
+ } else {
52
+ itemsData = items;
53
+ }
54
+
55
+ const menuItems = itemsData.map((item, idx) => {
39
56
  if (item.name === "divider") {
40
57
  return <Menu.Divider key={"divider" + idx} />;
41
58
  }
42
59
  return <Menu.Item key={item.id}>{item.name}</Menu.Item>;
43
60
  });
44
61
 
62
+ const mustShowSearch =
63
+ searchable === true || (searchable === "auto" && items.length > 3);
64
+
45
65
  return (
46
66
  <Menu onClick={handleMenuClick}>
47
- {((searchable === 'auto' && items.length > 3) || searchable === true)
48
- && <Search onChange={(e) => onSearch(e.target.value)} onSearch={onSearch} allowClear />}
67
+ {mustShowSearch && (
68
+ <Search
69
+ onChange={(e: any) => onSearch(e.target.value)}
70
+ onSearch={onSearch}
71
+ allowClear
72
+ style={{ padding: 5 }}
73
+ />
74
+ )}
49
75
  <Menu.ItemGroup title={tooltip}>{menuItems}</Menu.ItemGroup>
50
76
  </Menu>
51
77
  );
@@ -182,7 +182,7 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
182
182
  });
183
183
 
184
184
  if (newId) {
185
- await goToResourceId?.(newId);
185
+ await goToResourceId?.([newId]);
186
186
  }
187
187
  } catch (e) {
188
188
  showErrorDialog(JSON.stringify(e));