From 1913755db5165b181dba99353e7be1476b4f56a6 Mon Sep 17 00:00:00 2001 From: Roland Date: Sat, 7 Mar 2026 10:29:05 -0700 Subject: [PATCH] Adding tags filter input on tags selector, adding frequently used tags to suggest tags that are used together. --- app/src/Tags.js | 56 +++++++++++++++++++-- app/src/api.js | 20 ++++++++ wrolpi/root_api.py | 18 +++++++ wrolpi/tags.py | 40 +++++++++++++++ wrolpi/test/test_tags.py | 105 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 236 insertions(+), 3 deletions(-) diff --git a/app/src/Tags.js b/app/src/Tags.js index e51f5cbd..c9296ded 100644 --- a/app/src/Tags.js +++ b/app/src/Tags.js @@ -1,6 +1,6 @@ import React, {useEffect} from "react"; -import {ApiDownError, deleteTag, getTags, saveTag} from "./api"; -import {Dimmer, Divider, Grid, GridColumn, GridRow, Label, TableCell, TableRow,} from "semantic-ui-react"; +import {ApiDownError, deleteTag, getCooccurringTags, getRecentTags, getTags, saveTag} from "./api"; +import {Dimmer, Divider, Grid, GridColumn, GridRow, Input, Label, TableCell, TableRow,} from "semantic-ui-react"; import { APIButton, contrastingColor, @@ -410,12 +410,32 @@ export function AddTagsButton({ const [open, setOpen] = React.useState(false); const [loading, setLoading] = React.useState(false); const [localTags, setLocalTags] = React.useState(selectedTagNames); + const [filterText, setFilterText] = React.useState(''); + const [frequentTags, setFrequentTags] = React.useState([]); + const [frequentTagsLabel, setFrequentTagsLabel] = React.useState('Recent Tags'); + const [hasSelectedTag, setHasSelectedTag] = React.useState(false); + const filterInputRef = React.useRef(null); // Sync localTags with selectedTagNames when it changes from parent React.useEffect(() => { setLocalTags(selectedTagNames); }, [selectedTagNames]); + React.useEffect(() => { + if (open) { + setFilterText(''); + setHasSelectedTag(false); + setFrequentTagsLabel('Recent Tags'); + getRecentTags().then(names => setFrequentTags(names)); + const timeout = setTimeout(() => { + if (filterInputRef.current && window.innerWidth >= 700) { + filterInputRef.current.focus(); + } + }, 100); + return () => clearTimeout(timeout); + } + }, [open]); + const active = anyTag || (selectedTagNames && selectedTagNames.length > 0); const handleOpen = (e) => { @@ -433,8 +453,18 @@ export function AddTagsButton({ return; } setLocalTags(newTags); + setFilterText(''); onAdd(name); onChange(newTags, null); + if (!hasSelectedTag && newTags.length === 1) { + setHasSelectedTag(true); + getCooccurringTags(name).then(coTags => { + if (coTags && coTags.length > 0) { + setFrequentTags(coTags); + setFrequentTagsLabel('Frequent Tags'); + } + }); + } if (closeAfterLimit && newTags && limit && newTags.length >= limit) { setOpen(false); } @@ -475,8 +505,12 @@ export function AddTagsButton({ const selectedTagsGroup = ; const unusedTags = _.difference(tagNames, localTags); - const unusedTagsGroup = ; + const filteredUnusedTags = filterText + ? unusedTags.filter(name => name.toLowerCase().includes(filterText.toLowerCase())) + : unusedTags; + const unusedTagsGroup = ; const emptySelectedTags = limit === 1 ? 'Add only one tag below' : 'Add one or more tags below'; + const visibleFrequentTags = frequentTags.filter(name => !(localTags || []).includes(name)); return <>