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