@bitrise/bitkit 12.110.0 → 12.110.1-alpha.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.0",
4
+ "version": "12.110.1-alpha.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -22,32 +22,31 @@ 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;
25
26
  filtersDependOn?: string[];
26
- initialData: FilterData;
27
- initialState: FilterState;
28
27
  isLoading?: boolean;
29
28
  onChange: (state: FilterState) => void;
30
29
  showSearch?: boolean;
30
+ state: FilterState;
31
31
  }
32
32
 
33
33
  const Filter = (props: FilterProps) => {
34
- const { filtersDependOn, initialData, initialState, isLoading, onChange, showSearch, ...rest } = props;
34
+ const { data, filtersDependOn, isLoading, onChange, showSearch, state, ...rest } = props;
35
35
 
36
36
  const isInited = useRef<boolean>(false);
37
37
 
38
38
  const filterStyle = useMultiStyleConfig('Filter') as FilterStyle;
39
39
 
40
- const state: FilterState = {};
41
- Object.entries(initialState).forEach(([category, values]) => {
40
+ const cleanState: FilterState = {};
41
+ Object.entries(state).forEach(([category, values]) => {
42
42
  if (values?.length) {
43
43
  const cleanValues = values.filter((v) => v !== null && v !== '' && v !== undefined);
44
44
  if (cleanValues.length) {
45
- state[category] = cleanValues;
45
+ cleanState[category] = cleanValues;
46
46
  }
47
47
  }
48
48
  });
49
49
 
50
- const [data] = useState<FilterData>(initialData);
51
50
  const [isPopoverOpen, setPopoverOpen] = useState<boolean>(false);
52
51
 
53
52
  const deleteFromState = (category: string, stateProp: FilterState): FilterState => {
@@ -67,9 +66,15 @@ const Filter = (props: FilterProps) => {
67
66
  if (isInited.current === false) {
68
67
  return;
69
68
  }
70
- let newState = { ...state };
69
+ let newState = { ...cleanState };
71
70
  if (value && value.length > 0) {
72
71
  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
+ }
73
78
  } else if (newState[category]) {
74
79
  newState = deleteFromState(category, newState);
75
80
  }
@@ -77,7 +82,7 @@ const Filter = (props: FilterProps) => {
77
82
  };
78
83
 
79
84
  const onFilterClear = (category: string) => {
80
- onChange(deleteFromState(category, state));
85
+ onChange(deleteFromState(category, cleanState));
81
86
  };
82
87
 
83
88
  const onClearFilters = () => {
@@ -96,21 +101,21 @@ const Filter = (props: FilterProps) => {
96
101
  filters[value.type || 'tag'][category] = value;
97
102
  });
98
103
 
99
- const stateCategories = Object.keys(state).filter((c) => !['date_range', 'search'].includes(c));
104
+ const stateCategories = Object.keys(cleanState).filter((c) => !['date_range', 'search'].includes(c));
100
105
 
101
- const showClearFilters = stateCategories.length > 0 || (state.search && state.search.length > 0);
106
+ const showClearFilters = stateCategories.length > 0 || (cleanState.search && cleanState.search.length > 0);
102
107
 
103
108
  const contextValue: FilterContextType = useMemo(
104
109
  () => ({
105
- data: initialData,
110
+ data,
106
111
  filtersDependOn,
107
112
  isLoading,
108
113
  onFilterChange,
109
114
  onFilterClear,
110
115
  setPopoverOpen,
111
- state,
116
+ state: cleanState,
112
117
  }),
113
- [filtersDependOn, isLoading, initialData, onFilterChange, onFilterClear, setPopoverOpen, state],
118
+ [data, filtersDependOn, isLoading, onFilterChange, onFilterClear, setPopoverOpen, cleanState],
114
119
  );
115
120
 
116
121
  useEffect(() => {
@@ -140,7 +145,7 @@ const Filter = (props: FilterProps) => {
140
145
  <FilterItem key={category} category={category} />
141
146
  ))}
142
147
  {Object.keys(filters.tag).map((category) => {
143
- if (!state[category]) {
148
+ if (!cleanState[category]) {
144
149
  return;
145
150
  }
146
151
  return <FilterItem key={category} category={category} />;
@@ -165,7 +170,9 @@ const Filter = (props: FilterProps) => {
165
170
  {showClearFilters && showSearch && (
166
171
  <Divider flexShrink="0" orientation="vertical" size="1" variant="solid" />
167
172
  )}
168
- {showSearch && <FilterSearch onChange={onFilterChange} value={(state.Search && state.Search[0]) || ''} />}
173
+ {showSearch && (
174
+ <FilterSearch onChange={onFilterChange} value={(cleanState.Search && cleanState.Search[0]) || ''} />
175
+ )}
169
176
  </Box>
170
177
  )}
171
178
  </Box>
@@ -152,7 +152,7 @@ const FilterForm = (props: FilterFormProps) => {
152
152
  return (
153
153
  <Radio key={opt} value={opt}>
154
154
  {hasIcon ? (
155
- <Box alignItems="center" as="span" display="flex" gap="4">
155
+ <Box as="span" display="flex" gap="4">
156
156
  <Icon name={iconsMap[opt]} />
157
157
  {label}
158
158
  </Box>