@bitrise/bitkit 12.109.0 → 12.109.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 +1 -1
- package/src/Components/Filter/Filter.tsx +17 -16
package/package.json
CHANGED
|
@@ -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 {
|
|
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
|
|
41
|
-
Object.entries(
|
|
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
|
-
|
|
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,7 +66,7 @@ const Filter = (props: FilterProps) => {
|
|
|
67
66
|
if (isInited.current === false) {
|
|
68
67
|
return;
|
|
69
68
|
}
|
|
70
|
-
let newState = { ...
|
|
69
|
+
let newState = { ...cleanState };
|
|
71
70
|
if (value && value.length > 0) {
|
|
72
71
|
newState[category] = value;
|
|
73
72
|
} else if (newState[category]) {
|
|
@@ -77,7 +76,7 @@ const Filter = (props: FilterProps) => {
|
|
|
77
76
|
};
|
|
78
77
|
|
|
79
78
|
const onFilterClear = (category: string) => {
|
|
80
|
-
onChange(deleteFromState(category,
|
|
79
|
+
onChange(deleteFromState(category, cleanState));
|
|
81
80
|
};
|
|
82
81
|
|
|
83
82
|
const onClearFilters = () => {
|
|
@@ -96,21 +95,21 @@ const Filter = (props: FilterProps) => {
|
|
|
96
95
|
filters[value.type || 'tag'][category] = value;
|
|
97
96
|
});
|
|
98
97
|
|
|
99
|
-
const stateCategories = Object.keys(
|
|
98
|
+
const stateCategories = Object.keys(cleanState).filter((c) => !['date_range', 'search'].includes(c));
|
|
100
99
|
|
|
101
|
-
const showClearFilters = stateCategories.length > 0 || (
|
|
100
|
+
const showClearFilters = stateCategories.length > 0 || (cleanState.search && cleanState.search.length > 0);
|
|
102
101
|
|
|
103
102
|
const contextValue: FilterContextType = useMemo(
|
|
104
103
|
() => ({
|
|
105
|
-
data
|
|
104
|
+
data,
|
|
106
105
|
filtersDependOn,
|
|
107
106
|
isLoading,
|
|
108
107
|
onFilterChange,
|
|
109
108
|
onFilterClear,
|
|
110
109
|
setPopoverOpen,
|
|
111
|
-
state,
|
|
110
|
+
state: cleanState,
|
|
112
111
|
}),
|
|
113
|
-
[filtersDependOn, isLoading,
|
|
112
|
+
[data, filtersDependOn, isLoading, onFilterChange, onFilterClear, setPopoverOpen, cleanState],
|
|
114
113
|
);
|
|
115
114
|
|
|
116
115
|
useEffect(() => {
|
|
@@ -140,7 +139,7 @@ const Filter = (props: FilterProps) => {
|
|
|
140
139
|
<FilterItem key={category} category={category} />
|
|
141
140
|
))}
|
|
142
141
|
{Object.keys(filters.tag).map((category) => {
|
|
143
|
-
if (!
|
|
142
|
+
if (!cleanState[category]) {
|
|
144
143
|
return;
|
|
145
144
|
}
|
|
146
145
|
return <FilterItem key={category} category={category} />;
|
|
@@ -165,7 +164,9 @@ const Filter = (props: FilterProps) => {
|
|
|
165
164
|
{showClearFilters && showSearch && (
|
|
166
165
|
<Divider flexShrink="0" orientation="vertical" size="1" variant="solid" />
|
|
167
166
|
)}
|
|
168
|
-
{showSearch &&
|
|
167
|
+
{showSearch && (
|
|
168
|
+
<FilterSearch onChange={onFilterChange} value={(cleanState.Search && cleanState.Search[0]) || ''} />
|
|
169
|
+
)}
|
|
169
170
|
</Box>
|
|
170
171
|
)}
|
|
171
172
|
</Box>
|