Skip to content

Commit 75f605f

Browse files
iheziqinikkite99
authored andcommitted
BUGFIX: #118 fix navbar does not cleanup filter
Signed-off-by: Ziqi He <heziqi4399@gmail.com>
1 parent d0bd072 commit 75f605f

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

frontend/src/components/NavBar.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import logo from '../assets/images/team-logo-light.png'
2020
// import { Input } from '@mui/material'
2121
import { InfoModal } from './InfoModal'
2222
import { useLocation, useNavigate } from 'react-router-dom'
23+
import {
24+
updateFilterAccordingToNav,
25+
HierarchyInPulsar,
26+
} from '../store/filterSlice'
2327

2428
//Removed 'Message' from this array for now
2529
const pages = ['Cluster', 'Tenant', 'Namespace', 'Topic', 'Message']
@@ -142,6 +146,11 @@ function NavBar() {
142146
disabled={page.toLowerCase() == location.pathname.slice(1)}
143147
onClick={() => {
144148
handleClickOnNav(page)
149+
dispatch(
150+
updateFilterAccordingToNav(
151+
page.toLowerCase() as HierarchyInPulsar
152+
)
153+
)
145154
}}
146155
sx={{ my: 2, color: 'white', display: 'block' }}
147156
>

frontend/src/components/custom/CustomFilter.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ const CustomFilter: React.FC<CustomFilterProps> = ({
1616
messages,
1717
currentView,
1818
}) => {
19+
// Options are what we've got from apis so far.
1920
const options = useAppSelector(selectOptions)
21+
// filters are displayed in filters.
2022
const filters = useAppSelector(selectAllFilters)
2123
const [clusterSearchQuery, setClusterSearchQuery] = useState('')
2224
const [namespaceSearchQuery, setNamespaceSearchQuery] = useState('')

frontend/src/store/filterSlice.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import { ResponseTenant } from '../components/pages/tenant'
1010
import { ResponseNamespace } from '../components/pages/namespace'
1111
import { ResponseTopic } from '../components/pages/topic'
1212

13+
export type HierarchyInPulsar =
14+
| 'cluster'
15+
| 'tenant'
16+
| 'namespace'
17+
| 'topic'
18+
| 'message'
19+
1320
export 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

3341
type 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

5363
const 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

262302
export default filterSlice.reducer

0 commit comments

Comments
 (0)