Only files that have been tagged will be returned when new 'Any' tag button is used to filter file search results.

This commit is contained in:
Roland 2024-07-22 16:36:57 -06:00
parent f3439c2bd5
commit 53d2402d32
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
31 changed files with 303 additions and 146 deletions

View file

@ -263,7 +263,11 @@ function ArchivePage() {
</Segment>
<Segment>
<TagsSelector selectedTagNames={archiveFile['tags']} onAdd={localAddTag} onRemove={localRemoveTag}/>
<TagsSelector
selectedTagNames={archiveFile['tags']}
onAdd={localAddTag}
onRemove={localRemoveTag}
/>
</Segment>
<Tab menu={tabMenu} panes={tabPanes}/>
@ -497,14 +501,16 @@ function ArchivesPage() {
</div>;
const {body, paginator, selectButton, viewButton, limitDropdown, tagQuerySelector} = FilesView(
archives,
activePage,
totalPages,
selectElm,
selectedArchives,
onSelect,
setPage,
!!searchStr,
{
files: archives,
activePage: activePage,
totalPages: totalPages,
selectElem: selectElm,
selectedKeys: selectedArchives,
onSelect: onSelect,
setPage: setPage,
headlines: !!searchStr
},
);

View file

@ -488,14 +488,6 @@ export function ChannelDownloadForm({channel_id, afterSave, closeModal, download
}
};
const handleAddTag = (tagName) => {
setTagNames([...tagNames, tagName]);
}
const handleUntag = (tagName) => {
setTagNames(tagNames.filter(i => i !== tagName));
}
const deleteDownloadButton = <APIButton
color='red'
floated='left'
@ -571,7 +563,7 @@ export function ChannelDownloadForm({channel_id, afterSave, closeModal, download
</Grid.Row>
<Grid.Row columns={1}>
<Grid.Column>
<TagsSelector selectedTagNames={tagNames} onAdd={handleAddTag} onRemove={handleUntag}/>
<TagsSelector selectedTagNames={tagNames} onChange={(i, j) => setTagNames(i)}/>
</Grid.Column>
</Grid.Row>
<Grid.Row columns={1}>

View file

@ -77,7 +77,7 @@ class Downloader extends React.Component {
}
}
handleSelectedTags = (tagNames) => {
handleTagsChange = (tagNames, newAnyTag) => {
this.setState({tagNames});
}
@ -119,7 +119,7 @@ class Downloader extends React.Component {
let tagsSelector;
if (withTags) {
tagsSelector = <TagsSelector selectedTagNames={tagNames} onToggle={this.handleSelectedTags}/>;
tagsSelector = <TagsSelector selectedTagNames={tagNames} onChange={this.handleTagsChange}/>;
}
const advancedAccordion = <Accordion>

View file

@ -32,7 +32,6 @@ import {
useTitle
} from "./Common";
import {
useAllQuery,
useFilesProgressInterval,
usePages,
useSearchFiles,
@ -66,6 +65,7 @@ import {refreshFiles} from "../api";
import {useSubscribeEventName} from "../Events";
import {TagsSelector} from "../Tags";
import {Headlines} from "./Headline";
import {useSearch} from "./Search";
function EbookCard({file}) {
const {s} = useContext(ThemeContext);
@ -311,15 +311,18 @@ export function SearchLimitDropdown({limits = []}) {
}
export function FilesView(
files,
activePage,
totalPages,
selectElem,
selectedKeys,
onSelect,
setPage,
headlines = false,
limitOptions = [12, 24, 48, 96],
{
files,
activePage,
totalPages,
selectElem,
selectedKeys,
onSelect,
setPage,
headlines = false,
limitOptions = [12, 24, 48, 96],
showAnyTag = false,
},
) {
const {view} = useSearchView();
@ -360,7 +363,7 @@ export function FilesView(
const viewButton = <SearchViewButton headlines={headlines}/>
const limitDropdown = <SearchLimitDropdown limits={limitOptions}/>;
const tagQuerySelector = <TagsQuerySelector/>;
const tagQuerySelector = <TagsQuerySelector showAny={showAnyTag}/>;
return {
body,
@ -432,22 +435,28 @@ export function SearchFilter({filters = [], modalHeader, size = 'medium'}) {
return <></>
}
export function TagsQuerySelector({onChange}) {
// Creates modal that the User can use to manipulate the tag query.
const [activeTags, setActiveTags] = useAllQuery('tag');
export function TagsQuerySelector({onChange, showAny = true}) {
// Creates modal that the User can use to manipulate the tag query params.
const {activeTags, anyTag, setTags, setAnyTag} = useSearch();
const localOnChange = (tagNames) => {
setActiveTags(tagNames);
const localOnChange = (tagNames, newAnyTag) => {
if (newAnyTag) {
setAnyTag(true);
} else {
setTags(tagNames);
}
if (onChange) {
onChange(tagNames);
onChange(tagNames, newAnyTag);
}
}
return <TagsSelector hideGroup={true}
hideEdit={true}
active={activeTags && activeTags.length > 0}
showAny={showAny}
active={anyTag || activeTags && activeTags.length > 0}
selectedTagNames={activeTags}
onToggle={localOnChange}
anyTag={anyTag}
onChange={localOnChange}
style={{marginLeft: '0.3em', marginTop: '0.3em'}}
/>
}
@ -479,14 +488,17 @@ export function FilesSearchView({
const {searchFiles, pages} = useSearchFiles(24, emptySearch, model);
const {body, paginator, selectButton, viewButton, limitDropdown, tagQuerySelector} = FilesView(
searchFiles,
pages.activePage,
pages.totalPages,
null,
null,
null,
pages.setPage,
true,
{
files: searchFiles,
activePage: pages.activePage,
totalPages: pages.totalPages,
selectElem: null,
selectedKeys: null,
onSelect: null,
setPage: pages.setPage,
headlines: true,
showAnyTag: true,
},
);
return <>

View file

@ -82,7 +82,7 @@ export const useSearch = (defaultLimit = 48, totalPages = 0, emptySearch = false
}
const setTags = (tags) => {
updateQuery({tag: tags});
updateQuery({tag: tags, anyTag: null});
}
const addTag = (name) => {
@ -95,24 +95,26 @@ 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});
}
return {
activeTags,
addTag,
activeTags, addTag, removeTag, anyTag, setAnyTag, setTags,
filter,
model: model_,
pages,
removeTag,
searchParams,
searchStr,
setSearchStr,
clearSearch,
setTags,
months, dateRange, setDateRange, setDates,
anySearch, isEmpty,
}
}
export function useSuggestions(searchStr, tagNames, filter) {
export function useSuggestions(searchStr, tagNames, filter, anyTag) {
const defaultSuggestions = {
fileGroups: [],
channels: [],
@ -135,7 +137,7 @@ export function useSuggestions(searchStr, tagNames, filter) {
// We can't search Channels/Domains without some string to filter by.
sendGeneralReqeust(async () => await searchSuggestions(searchStr));
}
sendFilesRequest(async () => await searchEstimateFiles(searchStr, tagNames, mimetypes, months, dateRange));
sendFilesRequest(async () => await searchEstimateFiles(searchStr, tagNames, mimetypes, months, dateRange, anyTag));
sendZimRequest(async () => await searchEstimateZims(searchStr, tagNames));
}
}, [
@ -146,6 +148,7 @@ export function useSuggestions(searchStr, tagNames, filter) {
JSON.stringify(months),
JSON.stringify(dateRange),
filter,
anyTag,
]);
React.useEffect(() => {
@ -180,14 +183,14 @@ export function useSuggestions(searchStr, tagNames, filter) {
}
export function useSearchSuggestions(defaultSearchStr, defaultTagNames) {
export function useSearchSuggestions(defaultSearchStr, defaultTagNames, anyTag) {
const navigate = useNavigate();
const {filter} = useSearchFilter();
const [searchStr, setSearchStr] = React.useState(defaultSearchStr || '');
const [searchTags, setSearchTags] = React.useState(defaultTagNames);
const {SingleTag, fuzzyMatchTagsByName} = React.useContext(TagsContext);
const {dateRange, months, setDates, clearDate} = useSearchDate();
const {suggestions, loading} = useSuggestions(searchStr, searchTags, filter);
const {suggestions, loading} = useSuggestions(searchStr, searchTags, filter, anyTag);
const {getLocationStr} = React.useContext(QueryContext);
// The results that will be displayed by <Search>.
@ -239,6 +242,8 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames) {
return {type: 'channel', title: i['name'], id: i['id'], location: `/videos/channel/${i.id}/video`}
})
}
} else if (newSuggestions.channels && newSuggestions.channels.length === 0) {
results.channels = {name: 'Channels', results: noResults};
}
if (newSuggestions.domains && newSuggestions.domains.length > 0) {
results.domains = {
@ -339,7 +344,7 @@ export function SearchView({suggestions, suggestionsSums, loading}) {
const zimsTabName = <span>Zims <Label>{normalizeEstimate(suggestionsSums?.zims)}</Label></span>;
const links = [
{text: filesTabName, to: '/search', key: 'filesSearch', end: true},
{text: filesTabName, to: '/search', key: 'filesSearch_', end: true},
{text: zimsTabName, to: '/search/zim', key: 'zimsSearch'},
];

View file

@ -31,6 +31,7 @@ import {
CardDescription,
CardHeader,
Container,
Dimmer,
Image,
PlaceholderHeader,
PlaceholderLine,
@ -74,7 +75,7 @@ function VideosPage() {
searchOrder = defaultSearchOrder;
}
const {searchStr, setSearchStr, videos, activePage, setPage, totalPages, fetchVideos} =
const {searchStr, setSearchStr, videos, activePage, setPage, totalPages, fetchVideos, loading} =
useSearchVideos(null, channelId, searchOrder);
const {channel} = useChannel(channelId);
@ -165,14 +166,17 @@ function VideosPage() {
</div>;
const {body, paginator, selectButton, viewButton, limitDropdown, tagQuerySelector} = FilesView(
videos,
activePage,
totalPages,
selectElm,
selectedVideos,
onSelect,
setPage,
!!searchStr,
{
files: videos,
activePage: activePage,
totalPages: totalPages,
selectElem: selectElm,
selectedKeys: selectedVideos,
onSelect: onSelect,
setPage: setPage,
headlines: !!searchStr,
loading: loading,
},
);
const [localSearchStr, setLocalSearchStr] = React.useState(searchStr || '');

View file

@ -320,7 +320,7 @@ export const ZimSearchView = ({suggestions, loading}) => {
}
return <>
<TagsQuerySelector onChange={setTags}/>
<TagsQuerySelector onChange={(i, j) => setTags(i)}/>
<Accordion>
{body}
</Accordion>
@ -533,7 +533,7 @@ class ManageZim extends React.Component {
}
}
function ZimViewer({src = ZIM_VIEWER_URI, style=null}) {
function ZimViewer({src = ZIM_VIEWER_URI, style = null}) {
const fallback = <Segment>
<Header as='h3'>Failed to fetch Zim service.</Header>
<p>You may need to give permission to access the page: <a href={src}>{src}</a></p>