@@ -10,6 +10,13 @@ import { ResponseTenant } from '../components/pages/tenant'
1010import { ResponseNamespace } from '../components/pages/namespace'
1111import { ResponseTopic } from '../components/pages/topic'
1212
13+ export type HierarchyInPulsar =
14+ | 'cluster'
15+ | 'tenant'
16+ | 'namespace'
17+ | 'topic'
18+ | 'message'
19+
1320export type FilterState = {
1421 cluster : string [ ]
1522 tenant : string [ ]
@@ -23,15 +30,17 @@ export type FilterState = {
2330 allTopics : string [ ]
2431 allMessages : string [ ]
2532 }
33+ view : UpdateSingleFilter [ 'filterName' ]
2634}
2735
28- type UpdateSingleFilter = {
29- filterName : 'cluster' | 'tenant' | 'namespace' | 'topic' | 'message'
36+ export type UpdateSingleFilter = {
37+ filterName : HierarchyInPulsar
3038 id : string
3139}
3240
3341type UpdateDisplayedOptions = {
34- topologyLevel : 'cluster' | 'tenant' | 'namespace' | 'topic' | 'message'
42+ // topologyLevel: 'cluster' | 'tenant' | 'namespace' | 'topic' | 'message'
43+ topologyLevel : HierarchyInPulsar
3544 options : string [ ]
3645}
3746
@@ -48,6 +57,7 @@ const initialState: FilterState = {
4857 allTopics : [ ] ,
4958 allMessages : [ ] ,
5059 } ,
60+ view : 'cluster' ,
5161}
5262
5363const backendInstance = axios . create ( {
@@ -168,6 +178,35 @@ const filterSlice = createSlice({
168178 state . topic = initialState . topic
169179 state . message = initialState . message
170180 } ,
181+ // the filtering of lower views do not apply to higher views,
182+ // those filters shall be reset when the user "goes up".
183+ updateFilterAccordingToNav : (
184+ state ,
185+ action : PayloadAction < UpdateSingleFilter [ 'filterName' ] >
186+ ) => {
187+ const lastView = state . view
188+ const currentView = action . payload
189+ const pulsarHierarchyArr : UpdateSingleFilter [ 'filterName' ] [ ] = [
190+ 'cluster' ,
191+ 'tenant' ,
192+ 'namespace' ,
193+ 'topic' ,
194+ 'message' ,
195+ ]
196+ const currentViewLevel = pulsarHierarchyArr . indexOf ( currentView )
197+ const lastViewLevel = pulsarHierarchyArr . indexOf ( lastView )
198+ // If the user goes to upper level in the pulasr hierarchy,
199+ // reset all filters below that "upper level".
200+ if ( currentViewLevel < lastViewLevel ) {
201+ const filtersToReset = pulsarHierarchyArr . slice ( currentViewLevel + 1 )
202+ // Resets all filters bellow the current view level.
203+ filtersToReset . forEach ( ( filterName ) => {
204+ console . log ( filterName )
205+ state [ filterName ] = initialState [ filterName ]
206+ } )
207+ }
208+ state . view = currentView
209+ } ,
171210 } ,
172211 extraReducers ( builder ) {
173212 builder . addCase ( clusterOptionThunk . fulfilled , ( state , action ) => {
@@ -257,6 +296,7 @@ export const {
257296 deleteFilter,
258297 addFilterByDrillDown,
259298 resetAllFilters,
299+ updateFilterAccordingToNav,
260300} = filterSlice . actions
261301
262302export default filterSlice . reducer
0 commit comments