Skip to content

Commit a1c0df2

Browse files
otAAAhJenkins
authored andcommitted
fix(mon-pages): clear search on reset filters
"Reset all filters" only dropped the filter conditions, leaving the search query in place, so the listing stayed narrowed by whatever was typed in the search box. Clear the query along with the conditions and refetch explicitly: with no condition set, the filter node does not change, so its watcher would not fire and the cleared query would never reach the backend. CMK-37779 Change-Id: I98c758807f3fd0e36300748a1b371816bd2ca885
1 parent 6981756 commit a1c0df2

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

packages/cmk-frontend-vue/src/monitoring/shared/services/MonitoringService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,9 @@ export abstract class MonitoringService<T> extends ServiceBase {
445445
}
446446

447447
clearAllFilters(): void {
448+
this.searchQuery.value = ''
448449
this.filters.clearAllFilters()
450+
this.updateFilters(undefined)
449451
}
450452

451453
stopPolling(): void {

packages/cmk-frontend-vue/tests/monitoring/shared/services/MonitoringService.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,52 @@ describe('MonitoringService', () => {
592592
service.stopPolling()
593593
})
594594

595+
it('clearAllFilters drops the search query along with the conditions', async () => {
596+
const fetchBatch = vi.fn().mockResolvedValue(makeResponse([], 0, 0))
597+
const service = new TestService(fetchBatch, {
598+
quickFilters: [
599+
{
600+
label: 'Down',
601+
filter: { type: 'condition', field: 'acknowledged', op: 'eq', value: false }
602+
}
603+
]
604+
})
605+
606+
await vi.advanceTimersByTimeAsync(0)
607+
608+
service.updateSearch('web')
609+
service.activateQuickFilter(service.filters.quickFilters[0]!)
610+
await vi.advanceTimersByTimeAsync(0)
611+
612+
service.clearAllFilters()
613+
await vi.advanceTimersByTimeAsync(0)
614+
615+
expect(service.searchQuery.value).toBe('')
616+
expect(service.committedSearchQuery.value).toBe('')
617+
expect(service.filterState.value).toBeUndefined()
618+
619+
service.stopPolling()
620+
})
621+
622+
it('clearAllFilters refetches when only the search query was set', async () => {
623+
const fetchBatch = vi.fn().mockResolvedValue(makeResponse([], 0, 0))
624+
const service = new TestService(fetchBatch)
625+
626+
await vi.advanceTimersByTimeAsync(0)
627+
628+
service.updateSearch('web')
629+
await vi.advanceTimersByTimeAsync(0)
630+
const callsBeforeClear = fetchBatch.mock.calls.length
631+
632+
service.clearAllFilters()
633+
await vi.advanceTimersByTimeAsync(0)
634+
635+
expect(fetchBatch.mock.calls.length).toBeGreaterThan(callsBeforeClear)
636+
expect(service.committedSearchQuery.value).toBe('')
637+
638+
service.stopPolling()
639+
})
640+
595641
it('destruct() removes the focus-search callback so it is no longer dispatched', () => {
596642
let shortcutCallback: (() => void) | undefined
597643
const shortCutService = {

0 commit comments

Comments
 (0)