From 30b2bf6df01cae6cfd12de5b728bb1ab6647c79b Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Wed, 11 Nov 2026 19:42:48 -0700 Subject: [PATCH] Any Tag alone searches the library, and Zim search does not offer it (#960) On the search page, choosing Any Tag without a search string left the Dashboard showing: the page, the Files results and the Files count all waited for a search string or tag names. Zim search has no "any tag" search, and its tag picker's Any button left no filter applied, so the picker no longer offers it. Zim and Other counts are only requested when there is a search string or tag names to count by. Co-authored-by: Claude Opus 5.5 --- app/src/DashboardPage.js | 4 +- app/src/components/Search.js | 15 +++++--- app/src/components/SearchSuggestions.test.js | 20 ++++++++++ app/src/components/Zim.js | 3 +- app/src/components/Zim.test.js | 19 +++++++++- app/src/hooks/customHooks.js | 2 +- app/src/hooks/customHooks.test.js | 39 +++++++++++++++++++- 7 files changed, 92 insertions(+), 10 deletions(-) diff --git a/app/src/DashboardPage.js b/app/src/DashboardPage.js index 0a32b0ee..3f757ce4 100644 --- a/app/src/DashboardPage.js +++ b/app/src/DashboardPage.js @@ -432,6 +432,8 @@ export function DashboardPage() { } else if (activeTags && activeTags.length > 1) { const tagNames = activeTags.join(' & '); title = `Tags: ${tagNames} - Dashboard`; + } else if (anyTag) { + title = 'Any Tag - Dashboard'; } useTitle(title); @@ -444,7 +446,7 @@ export function DashboardPage() { ; - if (searchStr || (activeTags && activeTags.length > 0)) { + if (searchStr || (activeTags && activeTags.length > 0) || anyTag) { // User has submitted and wants full search. body = ; } diff --git a/app/src/components/Search.js b/app/src/components/Search.js index 6d76b1c7..a50d3c76 100644 --- a/app/src/components/Search.js +++ b/app/src/components/Search.js @@ -91,7 +91,9 @@ export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false // archive/video/doc/etc. const model_ = searchParams.get('model') || model; - const anySearch = (!datesIsEmpty) || searchStr || (activeTags && activeTags.length > 0) || filter || model; + const anyTag = searchParams.get('anyTag') === 'true'; + const anySearch = (!datesIsEmpty) || searchStr || (activeTags && activeTags.length > 0) || anyTag || filter + || model; const isEmpty = !anySearch; const setSearchStr = (value) => { @@ -121,7 +123,6 @@ export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false setTags(newTags); } - const anyTag = searchParams.get('anyTag') === 'true'; const setAnyTag = (value) => { updateQuery({tag: [], anyTag: value ? 'true' : null}); } @@ -163,7 +164,8 @@ export function useSuggestions(searchStr, tagNames, filter, anyTag) { const {data: mapData, sendRequest: sendMapRequest, loading: mapLoading} = useLatestRequest(500); React.useEffect(() => { - if (searchStr || (tagNames && tagNames.length > 0)) { + const hasTags = tagNames && tagNames.length > 0; + if (searchStr || hasTags || anyTag) { const mimetypes = filterToMimetypes(filter); setSuggestions(defaultSuggestions); if (searchStr && searchStr.length > 0) { @@ -173,8 +175,11 @@ export function useSuggestions(searchStr, tagNames, filter, anyTag) { } // The files estimate always uses deep search server-side, so users know results are possible. sendFilesRequest(async () => await searchEstimateFiles(searchStr, tagNames, mimetypes, months, dateRange, anyTag)); - sendZimRequest(async () => await searchEstimateZims(searchStr, tagNames)); - sendOtherRequest(async () => await searchEstimateOthers(tagNames, searchStr)); + if (searchStr || hasTags) { + // Zims and the Other tab have no "any tag" search; they need a search string or tag names. + sendZimRequest(async () => await searchEstimateZims(searchStr, tagNames)); + sendOtherRequest(async () => await searchEstimateOthers(tagNames, searchStr)); + } } }, [ searchStr, diff --git a/app/src/components/SearchSuggestions.test.js b/app/src/components/SearchSuggestions.test.js index 12cfa575..5568b6a2 100644 --- a/app/src/components/SearchSuggestions.test.js +++ b/app/src/components/SearchSuggestions.test.js @@ -137,3 +137,23 @@ test('no Repos group when none match', async () => { }); expect(results().repos).toBeUndefined(); }); + +function AnyTagProbe() { + hook = useSearchSuggestions('', [], true); + return null; +} + +test('Any Tag alone counts the tagged files, without a search string', () => { + render(, { + contexts: [[TagsContext, tagsContextFixture({fuzzyMatchTagsByName: () => []})]], + }); + act(() => { + jest.advanceTimersByTime(DEBOUNCE); + }); + expect(searchEstimateFiles).toHaveBeenCalledTimes(1); + expect(searchEstimateFiles.mock.calls[0][5]).toBe(true); + // Zims and the Other tab cannot search by "any tag"; without a search string they have nothing to count. + expect(searchEstimateZims).not.toHaveBeenCalled(); + expect(searchEstimateOthers).not.toHaveBeenCalled(); + expect(searchSuggestions).not.toHaveBeenCalled(); +}); diff --git a/app/src/components/Zim.js b/app/src/components/Zim.js index 8d5421e3..21f7ef66 100644 --- a/app/src/components/Zim.js +++ b/app/src/components/Zim.js @@ -282,7 +282,8 @@ export const ZimSearchView = ({suggestions, loading}) => { } return <> - setTags(i)}/> + {/* Zim search filters by specific tags only; it has no "any tag" search. */} + setTags(i)}/> {body} } diff --git a/app/src/components/Zim.test.js b/app/src/components/Zim.test.js index a4b1c092..b0599139 100644 --- a/app/src/components/Zim.test.js +++ b/app/src/components/Zim.test.js @@ -1,6 +1,8 @@ import React from 'react'; import {render, screen} from '../test-utils'; -import {ZimCatalogItemRow} from './Zim'; +import {ZimCatalogItemRow, ZimSearchView} from './Zim'; +import {TagsContext} from '../Tags'; +import {tagsContextFixture} from '../test-fixtures'; import {Table} from './ui'; /* @@ -113,3 +115,18 @@ describe('the outdated Zims banner', () => { expect(screen.getByText('zims/wikipedia_en_all_maxi_2024-01.zim')).toBeInTheDocument(); }); }); + +/* + * The Zim search tab's tag picker. Zim search can filter by specific tags but has no "any tag" search, and + * picking "Any" there left no filter applied -- so the picker must not offer it. + */ +describe('the Zim search tag picker', () => { + it('does not offer Any', async () => { + render(, { + contexts: [[TagsContext, tagsContextFixture({tags: [{name: 'one'}]})]], + }); + fireEvent.click(screen.getByLabelText('Add tag')); + expect(await screen.findByText('Applied Tags')).toBeInTheDocument(); + expect(screen.queryByRole('button', {name: 'Any'})).toBeNull(); + }); +}); diff --git a/app/src/hooks/customHooks.js b/app/src/hooks/customHooks.js index 67ae2bde..6fb3e05c 100644 --- a/app/src/hooks/customHooks.js +++ b/app/src/hooks/customHooks.js @@ -1050,7 +1050,7 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) => }, 1000); useEffect(() => { - if (searchStr || (activeTags && activeTags.length > 0)) { + if (searchStr || (activeTags && activeTags.length > 0) || anyTag) { setLoading(true); debouncedLocalSearchFiles(); } diff --git a/app/src/hooks/customHooks.test.js b/app/src/hooks/customHooks.test.js index 035ab041..7d1259ed 100644 --- a/app/src/hooks/customHooks.test.js +++ b/app/src/hooks/customHooks.test.js @@ -3,13 +3,14 @@ import {act, renderHook} from '@testing-library/react'; import {render, screen} from '../test-utils'; import { useBrowseFiles, usePages, useDriveTemperature, useDriveHealth, useSearchArchives, useSearchChannels, - useSearchDocs, useSearchRecentFiles, useSearchVideos, useSettings, useStatistics, useStatus, useVideoExtras, + useSearchDocs, useSearchFiles, useSearchRecentFiles, useSearchVideos, useSettings, useStatistics, useStatus, useVideoExtras, } from './customHooks'; import { ApiDownError, fetchDomains, filesSearch, getFiles, getSettings, getStatistics, getStatus, getVideoComments, getVideoDescription, searchArchives, searchChannels, searchDocs, searchVideos, } from '../api'; import {getControllerStats} from '../api/controller'; +import {MemoryRouter} from 'react-router'; import {QueryContext, StatusContext} from '../contexts/contexts'; import {Paginator} from '../components/Common'; @@ -805,3 +806,39 @@ describe('module searches send the Any Tag filter', () => { expect(search.mock.calls.at(-1).at(-1)).toBe(false); }); }); + +describe('useSearchFiles', () => { + beforeEach(() => { + jest.useFakeTimers(); + filesSearch.mockResolvedValue([[], 0]); + }); + + afterEach(() => { + jest.useRealTimers(); + jest.clearAllMocks(); + }); + + // `useSearch` navigates, so the hook needs a router as well as the QueryContext. + const routed = (params) => { + const Query = makeWrapper(params); + return ({children}) => {children}; + }; + + it('searches by Any Tag without a search string', async () => { + renderHook(() => useSearchFiles(), {wrapper: routed({anyTag: 'true'})}); + await act(async () => { + jest.advanceTimersByTime(1000); + }); + expect(filesSearch).toHaveBeenCalledTimes(1); + // `anyTag` is the eleventh argument of filesSearch. + expect(filesSearch.mock.calls[0][10]).toBe(true); + }); + + it('does not search without a search string, tags, or Any Tag', async () => { + renderHook(() => useSearchFiles(), {wrapper: routed({})}); + await act(async () => { + jest.advanceTimersByTime(1000); + }); + expect(filesSearch).not.toHaveBeenCalled(); + }); +});