@bitrise/bitkit 13.320.0 → 13.322.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "13.320.0",
4
+ "version": "13.322.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -9,6 +9,7 @@ import FilterForm from './FilterForm';
9
9
 
10
10
  const Filter = ({ isLoading, showAdd = true }: FilterProps) => {
11
11
  const {
12
+ data,
12
13
  isPopoverOpen,
13
14
  onClearFilters,
14
15
  selectedCategory,
@@ -18,7 +19,11 @@ const Filter = ({ isLoading, showAdd = true }: FilterProps) => {
18
19
  state,
19
20
  } = useFilterContext();
20
21
 
21
- const count = Object.values(state).filter((item) => item?.length > 0).length;
22
+ const isAllOptionForSwitch = (category: string) => {
23
+ return data[category].type === 'switch' && state[category]?.[0] === 'all';
24
+ };
25
+
26
+ const count = Object.entries(state).filter(([name, item]) => item?.length > 0 && !isAllOptionForSwitch(name)).length;
22
27
 
23
28
  return (
24
29
  <>
@@ -1,4 +1,4 @@
1
- import { useRef } from 'react';
1
+ import { useEffect, useRef } from 'react';
2
2
  import ProgressSpinner from '../../ProgressSpinner/ProgressSpinner';
3
3
  import Divider from '../../Divider/Divider';
4
4
  import SearchInput from '../../SearchInput/SearchInput';
@@ -66,8 +66,16 @@ const FilterForm = ({ isOpen, onClose, selectedCategory }: FilterFormProps) => {
66
66
  onChange,
67
67
  });
68
68
 
69
+ useEffect(() => {
70
+ if (isOpen) {
71
+ onSearchChange('');
72
+ }
73
+ }, [isOpen]);
74
+
75
+ const adjustedItems = type === 'switch' ? items.filter((item) => item !== 'all') : items;
76
+
69
77
  const { isScrollable } = useIsScrollable({
70
- items,
78
+ items: adjustedItems,
71
79
  hasNotFilteredOption,
72
80
  ref: bodyRef,
73
81
  });
@@ -198,7 +206,7 @@ const FilterForm = ({ isOpen, onClose, selectedCategory }: FilterFormProps) => {
198
206
  currentOptionMap={currentOptionMap}
199
207
  emptyText={getEmptyText()}
200
208
  isLoading={isLoading}
201
- items={items}
209
+ items={adjustedItems}
202
210
  onChange={setSelected}
203
211
  selectedItems={selected}
204
212
  />
@@ -209,7 +217,7 @@ const FilterForm = ({ isOpen, onClose, selectedCategory }: FilterFormProps) => {
209
217
  emptyText={getEmptyText()}
210
218
  hasNotFilteredOption={hasNotFilteredOption}
211
219
  isLoading={isLoading}
212
- items={items}
220
+ items={adjustedItems}
213
221
  onChange={(option: string) => {
214
222
  onChange(selectedCategory, [option]);
215
223
  }}
@@ -34,6 +34,10 @@ const FilterItem = ({ category }: FilterItemProps) => {
34
34
  return `${value.length} ${pluralCategoryString}`;
35
35
  }
36
36
 
37
+ if (type === 'switch' && value[0] === 'all') {
38
+ return `All ${pluralCategoryString}`;
39
+ }
40
+
37
41
  return getOptionLabel(value[0], optionsMap);
38
42
  };
39
43
 
@@ -65,8 +65,12 @@ const useFilterForm = (props: Omit<FilterFormProps, 'onCancel'>) => {
65
65
  };
66
66
 
67
67
  const onClearClick = () => {
68
- setSelected([]);
69
- onChange(category, [], value);
68
+ let newValue: FilterValue = [];
69
+ if (data[category]?.type === 'switch') {
70
+ newValue = ['all'];
71
+ }
72
+ setSelected(newValue);
73
+ onChange(category, newValue, value);
70
74
  };
71
75
 
72
76
  const getEmptyText = () => {