@bitrise/bitkit 13.320.0 → 13.321.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.321.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
  <>
@@ -66,8 +66,10 @@ const FilterForm = ({ isOpen, onClose, selectedCategory }: FilterFormProps) => {
66
66
  onChange,
67
67
  });
68
68
 
69
+ const adjustedItems = type === 'switch' ? items.filter((item) => item !== 'all') : items;
70
+
69
71
  const { isScrollable } = useIsScrollable({
70
- items,
72
+ items: adjustedItems,
71
73
  hasNotFilteredOption,
72
74
  ref: bodyRef,
73
75
  });
@@ -198,7 +200,7 @@ const FilterForm = ({ isOpen, onClose, selectedCategory }: FilterFormProps) => {
198
200
  currentOptionMap={currentOptionMap}
199
201
  emptyText={getEmptyText()}
200
202
  isLoading={isLoading}
201
- items={items}
203
+ items={adjustedItems}
202
204
  onChange={setSelected}
203
205
  selectedItems={selected}
204
206
  />
@@ -209,7 +211,7 @@ const FilterForm = ({ isOpen, onClose, selectedCategory }: FilterFormProps) => {
209
211
  emptyText={getEmptyText()}
210
212
  hasNotFilteredOption={hasNotFilteredOption}
211
213
  isLoading={isLoading}
212
- items={items}
214
+ items={adjustedItems}
213
215
  onChange={(option: string) => {
214
216
  onChange(selectedCategory, [option]);
215
217
  }}
@@ -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 = () => {