mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 14:36:22 -05:00
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 <noreply@anthropic.com>
This commit is contained in:
parent
f1d344d8a2
commit
30b2bf6df0
7 changed files with 92 additions and 10 deletions
|
|
@ -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() {
|
|||
<DashboardCalculators/>
|
||||
<DashboardRecentFiles/>
|
||||
</React.Fragment>;
|
||||
if (searchStr || (activeTags && activeTags.length > 0)) {
|
||||
if (searchStr || (activeTags && activeTags.length > 0) || anyTag) {
|
||||
// User has submitted and wants full search.
|
||||
body = <SearchView suggestions={suggestions} suggestionsSums={suggestionsSums} loading={loading}/>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(<AnyTagProbe/>, {
|
||||
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();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -282,7 +282,8 @@ export const ZimSearchView = ({suggestions, loading}) => {
|
|||
}
|
||||
|
||||
return <>
|
||||
<TagsQuerySelector onChange={(i, j) => setTags(i)}/>
|
||||
{/* Zim search filters by specific tags only; it has no "any tag" search. */}
|
||||
<TagsQuerySelector showAny={false} onChange={(i) => setTags(i)}/>
|
||||
{body}
|
||||
</>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(<ZimSearchView suggestions={{zimsEstimates: []}} loading={false}/>, {
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}) => <MemoryRouter><Query>{children}</Query></MemoryRouter>;
|
||||
};
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue