@bitrise/bitkit 13.10.0 → 13.10.1-alpha.1
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
|
@@ -92,7 +92,7 @@ export const FILTER_STORY_DATA: FilterData = {
|
|
|
92
92
|
export const FILTER_STORY_INIT_STATE: FilterState = {
|
|
93
93
|
app: ['46b6b9a78a418ee8'],
|
|
94
94
|
cache_type: ['gradle'],
|
|
95
|
-
pipeline: ['ipsum'
|
|
95
|
+
pipeline: ['ipsum'],
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
export const FILTER_STORY_CONTEXT: FilterContextType = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { Modal, ModalOverlay, useMultiStyleConfig } from '@chakra-ui/react';
|
|
3
|
+
import { isEqual } from '../../utils/utils';
|
|
3
4
|
import Box, { BoxProps } from '../Box/Box';
|
|
4
5
|
import Button from '../Button/Button';
|
|
5
6
|
import Divider from '../Divider/Divider';
|
|
@@ -45,8 +46,6 @@ const Filter = (props: FilterProps) => {
|
|
|
45
46
|
...rest
|
|
46
47
|
} = props;
|
|
47
48
|
|
|
48
|
-
const isInited = useRef<boolean>(false);
|
|
49
|
-
|
|
50
49
|
const filterStyle = useMultiStyleConfig('Filter') as FilterStyle;
|
|
51
50
|
|
|
52
51
|
const cleanState: FilterState = {};
|
|
@@ -60,6 +59,8 @@ const Filter = (props: FilterProps) => {
|
|
|
60
59
|
}
|
|
61
60
|
});
|
|
62
61
|
|
|
62
|
+
const initialState = useRef<FilterState>(cleanState);
|
|
63
|
+
|
|
63
64
|
const [isPopoverOpen, setPopoverOpen] = useState<boolean>(false);
|
|
64
65
|
|
|
65
66
|
const deleteFromState = (category: string, stateProp: FilterState): FilterState => {
|
|
@@ -76,9 +77,6 @@ const Filter = (props: FilterProps) => {
|
|
|
76
77
|
};
|
|
77
78
|
|
|
78
79
|
const onFilterChange = (category: string, value: FilterValue) => {
|
|
79
|
-
if (isInited.current === false) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
80
|
let newState = { ...cleanState };
|
|
83
81
|
if (value && value.length > 0) {
|
|
84
82
|
newState[category] = value;
|
|
@@ -99,7 +97,7 @@ const Filter = (props: FilterProps) => {
|
|
|
99
97
|
};
|
|
100
98
|
|
|
101
99
|
const onClearFilters = () => {
|
|
102
|
-
onChange({});
|
|
100
|
+
onChange(initialState.current || {});
|
|
103
101
|
};
|
|
104
102
|
|
|
105
103
|
const filters = {
|
|
@@ -114,9 +112,7 @@ const Filter = (props: FilterProps) => {
|
|
|
114
112
|
filters[value.type || 'tag'][category] = value;
|
|
115
113
|
});
|
|
116
114
|
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
const showClearFilters = stateCategories.length > 0 || (cleanState.search && cleanState.search.length > 0);
|
|
115
|
+
const showClearFilters = !isEqual(initialState.current, state);
|
|
120
116
|
|
|
121
117
|
const contextValue: FilterContextType = useMemo(
|
|
122
118
|
() => ({
|
|
@@ -131,12 +127,6 @@ const Filter = (props: FilterProps) => {
|
|
|
131
127
|
[data, filtersDependOn, isLoading, onFilterChange, onFilterClear, setPopoverOpen, cleanState],
|
|
132
128
|
);
|
|
133
129
|
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
if (isInited.current === false) {
|
|
136
|
-
isInited.current = true;
|
|
137
|
-
}
|
|
138
|
-
}, [isInited.current]);
|
|
139
|
-
|
|
140
130
|
return (
|
|
141
131
|
<FilterContext value={contextValue}>
|
|
142
132
|
<Box sx={filterStyle.container} {...rest}>
|
|
@@ -183,7 +173,7 @@ const Filter = (props: FilterProps) => {
|
|
|
183
173
|
{showSearch && (
|
|
184
174
|
<>
|
|
185
175
|
<Divider flexShrink="0" orientation="vertical" size="1" variant="solid" />
|
|
186
|
-
<FilterSearch onChange={onFilterChange} value={
|
|
176
|
+
<FilterSearch onChange={onFilterChange} value={cleanState.search?.length ? cleanState.search[0] : ''} />
|
|
187
177
|
</>
|
|
188
178
|
)}
|
|
189
179
|
</Box>
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
InputRightElement,
|
|
8
8
|
useMultiStyleConfig,
|
|
9
9
|
} from '@chakra-ui/react';
|
|
10
|
-
import { useDebounce } from '../../../utils/utils';
|
|
11
10
|
import Icon from '../../Icon/Icon';
|
|
12
11
|
import IconButton from '../../IconButton/IconButton';
|
|
13
12
|
import { FilterStyle } from '../Filter.theme';
|
|
@@ -23,7 +22,6 @@ const FilterSearch = (props: FilterSearchProps) => {
|
|
|
23
22
|
const filterStyle = useMultiStyleConfig('Filter') as FilterStyle;
|
|
24
23
|
|
|
25
24
|
const [searchValue, setSearchValue] = useState(value);
|
|
26
|
-
const debouncedSearchValue = useDebounce<string>(searchValue, 500);
|
|
27
25
|
|
|
28
26
|
const onInputChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
29
27
|
setSearchValue(event.currentTarget.value);
|
|
@@ -34,8 +32,11 @@ const FilterSearch = (props: FilterSearchProps) => {
|
|
|
34
32
|
};
|
|
35
33
|
|
|
36
34
|
useEffect(() => {
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const delayInputTimeoutId = setTimeout(() => {
|
|
36
|
+
onChange('search', searchValue.length ? [searchValue] : []);
|
|
37
|
+
}, 500);
|
|
38
|
+
return () => clearTimeout(delayInputTimeoutId);
|
|
39
|
+
}, [searchValue]);
|
|
39
40
|
|
|
40
41
|
useEffect(() => {
|
|
41
42
|
setSearchValue(value);
|
package/src/utils/utils.ts
CHANGED
|
@@ -15,10 +15,24 @@ export function useObjectMemo<T extends object>(obj: T): T {
|
|
|
15
15
|
}, Object.values(obj));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export function isEqual(a:
|
|
18
|
+
export function isEqual(a: any, b: any) {
|
|
19
19
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
20
20
|
return a.length === b.length && [...a].every((val) => [...b].includes(val));
|
|
21
21
|
}
|
|
22
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
|
23
|
+
let isEqualObjects = true;
|
|
24
|
+
Object.keys(a).forEach((key: any) => {
|
|
25
|
+
if (!isEqual(a[key], b[key])) {
|
|
26
|
+
isEqualObjects = false;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
Object.keys(b).forEach((key: any) => {
|
|
30
|
+
if (!isEqual(b[key], a[key])) {
|
|
31
|
+
isEqualObjects = false;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return isEqualObjects;
|
|
35
|
+
}
|
|
22
36
|
return a === b;
|
|
23
37
|
}
|
|
24
38
|
|