@bitrise/bitkit 12.109.1-alpha.0 → 12.110.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 -2
- package/src/Components/Filter/Filter.tsx +16 -17
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.
|
|
4
|
+
"version": "12.110.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"create-theme-from-tokens": "node ./scripts/createThemeFromTokens.js",
|
|
14
14
|
"lint": "eslint src --ext ts,tsx",
|
|
15
15
|
"lint:fix": "eslint src --ext ts,tsx --fix",
|
|
16
|
-
"postinstall": "npm run theme",
|
|
17
16
|
"release": "release-it minor --ci",
|
|
18
17
|
"release-alpha": "release-it --preRelease=alpha --ci",
|
|
19
18
|
"start": "npm run storybook",
|
|
@@ -22,31 +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;
|
|
26
25
|
filtersDependOn?: string[];
|
|
26
|
+
initialData: FilterData;
|
|
27
|
+
initialState: FilterState;
|
|
27
28
|
isLoading?: boolean;
|
|
28
29
|
onChange: (state: FilterState) => void;
|
|
29
30
|
showSearch?: boolean;
|
|
30
|
-
state: FilterState;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const Filter = (props: FilterProps) => {
|
|
34
|
-
const {
|
|
34
|
+
const { filtersDependOn, initialData, initialState, isLoading, onChange, showSearch, ...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 state: FilterState = {};
|
|
41
|
+
Object.entries(initialState).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
|
+
state[category] = cleanValues;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
const [data] = useState<FilterData>(initialData);
|
|
50
51
|
const [isPopoverOpen, setPopoverOpen] = useState<boolean>(false);
|
|
51
52
|
|
|
52
53
|
const deleteFromState = (category: string, stateProp: FilterState): FilterState => {
|
|
@@ -66,7 +67,7 @@ const Filter = (props: FilterProps) => {
|
|
|
66
67
|
if (isInited.current === false) {
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
|
-
let newState = { ...
|
|
70
|
+
let newState = { ...state };
|
|
70
71
|
if (value && value.length > 0) {
|
|
71
72
|
newState[category] = value;
|
|
72
73
|
} else if (newState[category]) {
|
|
@@ -76,7 +77,7 @@ const Filter = (props: FilterProps) => {
|
|
|
76
77
|
};
|
|
77
78
|
|
|
78
79
|
const onFilterClear = (category: string) => {
|
|
79
|
-
onChange(deleteFromState(category,
|
|
80
|
+
onChange(deleteFromState(category, state));
|
|
80
81
|
};
|
|
81
82
|
|
|
82
83
|
const onClearFilters = () => {
|
|
@@ -95,21 +96,21 @@ const Filter = (props: FilterProps) => {
|
|
|
95
96
|
filters[value.type || 'tag'][category] = value;
|
|
96
97
|
});
|
|
97
98
|
|
|
98
|
-
const stateCategories = Object.keys(
|
|
99
|
+
const stateCategories = Object.keys(state).filter((c) => !['date_range', 'search'].includes(c));
|
|
99
100
|
|
|
100
|
-
const showClearFilters = stateCategories.length > 0 || (
|
|
101
|
+
const showClearFilters = stateCategories.length > 0 || (state.search && state.search.length > 0);
|
|
101
102
|
|
|
102
103
|
const contextValue: FilterContextType = useMemo(
|
|
103
104
|
() => ({
|
|
104
|
-
data,
|
|
105
|
+
data: initialData,
|
|
105
106
|
filtersDependOn,
|
|
106
107
|
isLoading,
|
|
107
108
|
onFilterChange,
|
|
108
109
|
onFilterClear,
|
|
109
110
|
setPopoverOpen,
|
|
110
|
-
state
|
|
111
|
+
state,
|
|
111
112
|
}),
|
|
112
|
-
[
|
|
113
|
+
[filtersDependOn, isLoading, initialData, onFilterChange, onFilterClear, setPopoverOpen, state],
|
|
113
114
|
);
|
|
114
115
|
|
|
115
116
|
useEffect(() => {
|
|
@@ -139,7 +140,7 @@ const Filter = (props: FilterProps) => {
|
|
|
139
140
|
<FilterItem key={category} category={category} />
|
|
140
141
|
))}
|
|
141
142
|
{Object.keys(filters.tag).map((category) => {
|
|
142
|
-
if (!
|
|
143
|
+
if (!state[category]) {
|
|
143
144
|
return;
|
|
144
145
|
}
|
|
145
146
|
return <FilterItem key={category} category={category} />;
|
|
@@ -164,9 +165,7 @@ const Filter = (props: FilterProps) => {
|
|
|
164
165
|
{showClearFilters && showSearch && (
|
|
165
166
|
<Divider flexShrink="0" orientation="vertical" size="1" variant="solid" />
|
|
166
167
|
)}
|
|
167
|
-
{showSearch && (
|
|
168
|
-
<FilterSearch onChange={onFilterChange} value={(cleanState.Search && cleanState.Search[0]) || ''} />
|
|
169
|
-
)}
|
|
168
|
+
{showSearch && <FilterSearch onChange={onFilterChange} value={(state.Search && state.Search[0]) || ''} />}
|
|
170
169
|
</Box>
|
|
171
170
|
)}
|
|
172
171
|
</Box>
|