File tree Expand file tree Collapse file tree 6 files changed +41
-3
lines changed Expand file tree Collapse file tree 6 files changed +41
-3
lines changed Original file line number Diff line number Diff line change 1
1
# Change history for stripes-authoriy-components
2
2
3
+ ## [ 5.0.1] (IN PROGRESS)
4
+
5
+ - [ UISAUTCOMP-130] ( https://issues.folio.org/browse/UISAUTCOMP-130 ) Provide a prop to ` <AcqDateRangeFilter> ` to subscribe to search form resets.
6
+
3
7
## [ 5.0.0] (https://github.com/folio-org/stripes-authority-components/tree/v5.0.0 ) (2024-10-30)
4
8
5
9
- [ UISAUTCOMP-117] ( https://issues.folio.org/browse/UISAUTCOMP-117 ) Provide deprecation notice to ` useUserTenantPermissions.js ` .
Original file line number Diff line number Diff line change 1
- import { useContext } from 'react' ;
1
+ import {
2
+ useCallback ,
3
+ useContext ,
4
+ } from 'react' ;
2
5
import { FormattedMessage } from 'react-intl' ;
3
6
4
7
import {
@@ -13,8 +16,14 @@ const FilterNavigation = () => {
13
16
const {
14
17
navigationSegmentValue,
15
18
setNavigationSegmentValue,
19
+ unsubscribeFromReset,
16
20
} = useContext ( AuthoritiesSearchContext ) ;
17
21
22
+ const handleSegmentClick = useCallback ( name => {
23
+ setNavigationSegmentValue ( name ) ;
24
+ unsubscribeFromReset ( ) ;
25
+ } , [ unsubscribeFromReset , setNavigationSegmentValue ] ) ;
26
+
18
27
return (
19
28
< ButtonGroup
20
29
fullWidth
@@ -29,7 +38,7 @@ const FilterNavigation = () => {
29
38
role = "tab"
30
39
id = { `segment-navigation-${ name } ` }
31
40
data-testid = { `segment-navigation-${ name } ` }
32
- onClick = { ( ) => setNavigationSegmentValue ( name ) }
41
+ onClick = { ( ) => handleSegmentClick ( name ) }
33
42
>
34
43
< FormattedMessage id = { `stripes-authority-components.label.${ name } ` } />
35
44
</ Button >
Original file line number Diff line number Diff line change @@ -12,11 +12,13 @@ import Harness from '../../test/jest/helpers/harness';
12
12
const mockSetNavigationSegmentValue = jest . fn ( ) ;
13
13
const mockSetSearchDropdownValue = jest . fn ( ) ;
14
14
const mockSetSearchIndex = jest . fn ( ) ;
15
+ const mockUnsubscribeFromReset = jest . fn ( ) ;
15
16
16
17
const authoritiesCtxValue = {
17
18
setNavigationSegmentValue : mockSetNavigationSegmentValue ,
18
19
setSearchDropdownValue : mockSetSearchDropdownValue ,
19
20
setSearchIndex : mockSetSearchIndex ,
21
+ unsubscribeFromReset : mockUnsubscribeFromReset ,
20
22
} ;
21
23
22
24
const renderFilterNavigation = ( ) => render (
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ const SearchFilters = ({
42
42
filters,
43
43
setFilters,
44
44
navigationSegmentValue,
45
+ subscribeOnReset,
45
46
} = useContext ( AuthoritiesSearchContext ) ;
46
47
47
48
const [ filterAccordions , { handleSectionToggle } ] = useSectionToggle ( {
@@ -138,6 +139,7 @@ const SearchFilters = ({
138
139
disabled = { isLoading }
139
140
closedByDefault
140
141
dateFormat = { DATE_FORMAT }
142
+ subscribeOnReset = { subscribeOnReset }
141
143
/>
142
144
}
143
145
{ isVisible ( FILTERS . UPDATED_DATE ) &&
@@ -150,6 +152,7 @@ const SearchFilters = ({
150
152
disabled = { isSearching }
151
153
closedByDefault
152
154
dateFormat = { DATE_FORMAT }
155
+ subscribeOnReset = { subscribeOnReset }
153
156
/>
154
157
}
155
158
</ >
Original file line number Diff line number Diff line change @@ -48,6 +48,23 @@ const AuthoritiesSearchContextProvider = ({
48
48
[ navigationSegments . search ] : null ,
49
49
[ navigationSegments . browse ] : null ,
50
50
} ) ;
51
+ const subscribers = useRef ( [ ] ) ;
52
+
53
+ const subscribeOnReset = useCallback ( cb => {
54
+ const isSubscribed = subscribers . current . some ( callback => callback === cb ) ;
55
+
56
+ if ( ! isSubscribed ) {
57
+ subscribers . current . push ( cb ) ;
58
+ }
59
+ } , [ ] ) ;
60
+
61
+ const unsubscribeFromReset = useCallback ( ( ) => {
62
+ subscribers . current = [ ] ;
63
+ } , [ ] ) ;
64
+
65
+ const publishOnReset = useCallback ( ( ) => {
66
+ subscribers . current . forEach ( cb => cb ( ) ) ;
67
+ } , [ ] ) ;
51
68
52
69
const searchParams = readParamsFromUrl
53
70
? queryString . parse ( location . search )
@@ -186,6 +203,7 @@ const AuthoritiesSearchContextProvider = ({
186
203
setIsGoingToBaseURL ( true ) ;
187
204
setAdvancedSearchDefaultSearch ( null ) ;
188
205
paramsBySegment . current [ navigationSegmentValue ] = null ;
206
+ publishOnReset ( ) ;
189
207
} ;
190
208
191
209
const contextValue = {
@@ -218,6 +236,8 @@ const AuthoritiesSearchContextProvider = ({
218
236
setIsGoingToBaseURL,
219
237
advancedSearchDefaultSearch,
220
238
setAdvancedSearchDefaultSearch,
239
+ subscribeOnReset,
240
+ unsubscribeFromReset,
221
241
} ;
222
242
223
243
return (
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @folio/stripes-authority-components" ,
3
- "version" : " 5.0.0 " ,
3
+ "version" : " 5.0.1 " ,
4
4
"description" : " Component library for Stripes Authority modules" ,
5
5
"repository" : " https://github.com/folio-org/stripes-authority-components" ,
6
6
"main" : " index.js" ,
You can’t perform that action at this time.
0 commit comments