@bitrise/bitkit 12.110.1-alpha.0 → 12.111.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": "12.110.1-alpha.0",
4
+ "version": "12.111.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -22,31 +22,42 @@ import FilterDate from './FilterDate/FilterDate';
22
22
  import FilterSwitchAdapter from './FilterSwitchAdapter/FilterSwitchAdapter';
23
23
 
24
24
  export interface FilterProps extends Omit<BoxProps, 'onChange'> {
25
- data: FilterData;
26
25
  filtersDependOn?: string[];
26
+ initialData: FilterData;
27
+ initialState: FilterState;
27
28
  isLoading?: boolean;
28
29
  onChange: (state: FilterState) => void;
30
+ showAdd?: boolean;
29
31
  showSearch?: boolean;
30
- state: FilterState;
31
32
  }
32
33
 
33
34
  const Filter = (props: FilterProps) => {
34
- const { data, filtersDependOn, isLoading, onChange, showSearch, state, ...rest } = props;
35
+ const {
36
+ filtersDependOn,
37
+ initialData,
38
+ initialState,
39
+ isLoading,
40
+ onChange,
41
+ showAdd = true,
42
+ showSearch,
43
+ ...rest
44
+ } = props;
35
45
 
36
46
  const isInited = useRef<boolean>(false);
37
47
 
38
48
  const filterStyle = useMultiStyleConfig('Filter') as FilterStyle;
39
49
 
40
- const cleanState: FilterState = {};
41
- Object.entries(state).forEach(([category, values]) => {
50
+ const state: FilterState = {};
51
+ Object.entries(initialState).forEach(([category, values]) => {
42
52
  if (values?.length) {
43
53
  const cleanValues = values.filter((v) => v !== null && v !== '' && v !== undefined);
44
54
  if (cleanValues.length) {
45
- cleanState[category] = cleanValues;
55
+ state[category] = cleanValues;
46
56
  }
47
57
  }
48
58
  });
49
59
 
60
+ const [data] = useState<FilterData>(initialData);
50
61
  const [isPopoverOpen, setPopoverOpen] = useState<boolean>(false);
51
62
 
52
63
  const deleteFromState = (category: string, stateProp: FilterState): FilterState => {
@@ -66,15 +77,9 @@ const Filter = (props: FilterProps) => {
66
77
  if (isInited.current === false) {
67
78
  return;
68
79
  }
69
- let newState = { ...cleanState };
80
+ let newState = { ...state };
70
81
  if (value && value.length > 0) {
71
82
  newState[category] = value;
72
- const dependents = getDependents(data, category, filtersDependOn);
73
- if (dependents.length) {
74
- dependents.forEach((key) => {
75
- newState = deleteFromState(key, newState);
76
- });
77
- }
78
83
  } else if (newState[category]) {
79
84
  newState = deleteFromState(category, newState);
80
85
  }
@@ -82,7 +87,7 @@ const Filter = (props: FilterProps) => {
82
87
  };
83
88
 
84
89
  const onFilterClear = (category: string) => {
85
- onChange(deleteFromState(category, cleanState));
90
+ onChange(deleteFromState(category, state));
86
91
  };
87
92
 
88
93
  const onClearFilters = () => {
@@ -101,21 +106,21 @@ const Filter = (props: FilterProps) => {
101
106
  filters[value.type || 'tag'][category] = value;
102
107
  });
103
108
 
104
- const stateCategories = Object.keys(cleanState).filter((c) => !['date_range', 'search'].includes(c));
109
+ const stateCategories = Object.keys(state).filter((c) => !['date_range', 'search'].includes(c));
105
110
 
106
- const showClearFilters = stateCategories.length > 0 || (cleanState.search && cleanState.search.length > 0);
111
+ const showClearFilters = stateCategories.length > 0 || (state.search && state.search.length > 0);
107
112
 
108
113
  const contextValue: FilterContextType = useMemo(
109
114
  () => ({
110
- data,
115
+ data: initialData,
111
116
  filtersDependOn,
112
117
  isLoading,
113
118
  onFilterChange,
114
119
  onFilterClear,
115
120
  setPopoverOpen,
116
- state: cleanState,
121
+ state,
117
122
  }),
118
- [data, filtersDependOn, isLoading, onFilterChange, onFilterClear, setPopoverOpen, cleanState],
123
+ [filtersDependOn, isLoading, initialData, onFilterChange, onFilterClear, setPopoverOpen, state],
119
124
  );
120
125
 
121
126
  useEffect(() => {
@@ -145,13 +150,13 @@ const Filter = (props: FilterProps) => {
145
150
  <FilterItem key={category} category={category} />
146
151
  ))}
147
152
  {Object.keys(filters.tag).map((category) => {
148
- if (!cleanState[category]) {
153
+ if (!state[category]) {
149
154
  return;
150
155
  }
151
156
  return <FilterItem key={category} category={category} />;
152
157
  })}
153
158
 
154
- <FilterAdd onChange={onFilterChange} />
159
+ {showAdd && <FilterAdd onChange={onFilterChange} />}
155
160
  </Box>
156
161
  {(showClearFilters || showSearch) && (
157
162
  <Box sx={filterStyle.rightContent}>
@@ -170,9 +175,7 @@ const Filter = (props: FilterProps) => {
170
175
  {showClearFilters && showSearch && (
171
176
  <Divider flexShrink="0" orientation="vertical" size="1" variant="solid" />
172
177
  )}
173
- {showSearch && (
174
- <FilterSearch onChange={onFilterChange} value={(cleanState.Search && cleanState.Search[0]) || ''} />
175
- )}
178
+ {showSearch && <FilterSearch onChange={onFilterChange} value={(state.Search && state.Search[0]) || ''} />}
176
179
  </Box>
177
180
  )}
178
181
  </Box>
@@ -152,7 +152,7 @@ const FilterForm = (props: FilterFormProps) => {
152
152
  return (
153
153
  <Radio key={opt} value={opt}>
154
154
  {hasIcon ? (
155
- <Box as="span" display="flex" gap="4">
155
+ <Box alignItems="center" as="span" display="flex" gap="4">
156
156
  <Icon name={iconsMap[opt]} />
157
157
  {label}
158
158
  </Box>