Files
FabledCurator/frontend/src/components/modal/SuggestionsPanel.vue
T
bvandeusen a444cf82d1
CI / backend-lint-and-test (push) Successful in 36s
CI / lint (push) Successful in 3s
CI / frontend-build (push) Successful in 20s
CI / integration (push) Successful in 3m45s
refactor(tags): unify suggestion source — one canonical DB-tag dropdown, drop dead raw/alias machinery (#154)
Every tag suggestion is a canonical DB tag now (tagging-v2 #114: heads + CCIP
score EXISTING concept tags). The pre-heads apparatus for model-predicted tags
that didn't exist in the DB — creates_new_tag / raw_name / via_alias, the
/suggestions/alias endpoint + add_alias_and_accept, AliasPickerDialog, and the
store's aliasAccept/removeAlias — was dead and is removed.

The type-to-add dropdown was TWO row sources (server autocomplete + the image's
ML suggestions) merged with a dedup that dropped the %-bearing suggestion row
when the debounced server hit landed — the operator's "confidence % flickers
then vanishes". Now it's ONE list of DB-tag matches, each annotated with the
model's confidence (join by canonical_tag_id) when the tag was scored for this
image. No dedup, no flicker; picking a suggested tag still records acceptance
via TagPanel.findPending.

Single per-image fetch: score_image now reports above_threshold per row
(computed vs the head's own suggest cut, separate from the inclusion floor), so
the rail makes ONE min=0 request and derives the panel (above_threshold) and the
dropdown (all, text-filtered) client-side — the two /suggestions calls collapse
to one. Manual "Create 'X' as <kind>" (novel typed names) is unchanged; the
alias table + tag-side alias admin + auto-apply alias matching are untouched.

Tests: gate/serializer assertions updated (above_threshold; dropped dead-field
+ alias-endpoint checks); frontend spec seeds via the single load and covers the
byCategory/aboveByCategory split.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CgZP9v2otxVJymiYsnVuMy
2026-07-10 15:22:51 -04:00

157 lines
6.1 KiB
Vue

<template>
<section class="fc-suggestions" aria-label="Tag suggestions">
<h3 class="fc-suggestions__title">Suggestions</h3>
<div v-if="store.loading" class="fc-suggestions__skeleton">
<div v-for="i in 4" :key="i" class="fc-suggestions__skel-row" />
</div>
<v-alert v-else-if="store.error" type="error" variant="tonal" density="compact">
{{ store.error }}
</v-alert>
<div v-else-if="isEmpty" class="text-caption">
No suggestions above threshold.
</div>
<!-- Flows in the rail's main scroll area; Related is pinned to the bottom
of the rail (ImageViewer side layout), so a long suggestion set no
longer needs an internal scroll cap to keep Related reachable. -->
<div v-else class="fc-suggestions__list">
<!-- System hygiene tags (wip/banner/editor) surface in their own group,
first, so false positives are easy to spot and reject (reject-to-train
for these heads). Small set collapsible, open by default. -->
<SuggestionsCategoryGroup
v-if="store.aboveByCategory.system && store.aboveByCategory.system.length"
label="System" :items="store.aboveByCategory.system"
collapsible :default-open="true"
@accept="onAccept"
@dismiss="onDismiss" @undismiss="onUndismiss"
@reject-all="onRejectAll('system')"
/>
<SuggestionsCategoryGroup
v-for="cat in peopleCats" :key="cat"
v-show="store.aboveByCategory[cat] && store.aboveByCategory[cat].length"
:label="labelFor(cat)" :items="store.aboveByCategory[cat] || []"
@accept="onAccept"
@dismiss="onDismiss" @undismiss="onUndismiss"
@reject-all="onRejectAll(cat)"
/>
<SuggestionsCategoryGroup
v-if="store.aboveByCategory.general && store.aboveByCategory.general.length"
label="General" :items="store.aboveByCategory.general"
collapsible :default-open="true"
@accept="onAccept"
@dismiss="onDismiss" @undismiss="onUndismiss"
@reject-all="onRejectAll('general')"
/>
</div>
</section>
</template>
<script setup>
import { toast } from '../../utils/toast.js'
import { computed, watch } from 'vue'
import { useSuggestionsStore, CATEGORY_LABELS } from '../../stores/suggestions.js'
import { useModalStore } from '../../stores/modal.js'
import SuggestionsCategoryGroup from './SuggestionsCategoryGroup.vue'
const props = defineProps({
imageId: { type: Number, required: true },
// The tagging host whose chip rail to refresh after an accept. Defaults to
// the modal store (image modal); the Explore workspace passes its anchor host
// so the same panel refreshes the right surface. See TagPanel.
host: { type: Object, default: null },
})
// 'accepted'/'dismissed' let the parent return focus to the tag input after a
// suggestion is accepted OR rejected, so the operator keeps the keyboard flow on
// the input without re-clicking (operator-asked 2026-06-08, 2026-06-30).
const emit = defineEmits(['accepted', 'dismissed'])
// Reject (✗) / un-reject (↶): apply the store change, then signal the parent to
// re-focus the tag input — same return-to-input behaviour as accept.
function onDismiss (s) { store.dismiss(s); emit('dismissed') }
function onUndismiss (s) { store.undismiss(s); emit('dismissed') }
// Section-level "Reject rest": dismiss every still-unhandled suggestion in the
// category, then return focus to the input like a single reject does.
async function onRejectAll (category) {
try {
await store.dismissRemaining(category)
emit('dismissed')
} catch (e) {
toast({ text: `Reject failed: ${e.message}`, type: 'error' })
}
}
const store = useSuggestionsStore()
const modalStore = useModalStore()
const host = props.host || modalStore
// 'artist' (FC-2d-vii-c) and 'copyright' (2026-06-01) retired as
// suggestion categories. Only 'character' remains as a people-style
// category alongside the general bucket.
const peopleCats = ['character']
function labelFor(c) { return CATEGORY_LABELS[c] || c }
const isEmpty = computed(() =>
Object.values(store.aboveByCategory).every(list => !list || list.length === 0)
)
watch(() => props.imageId, (id) => {
if (id == null) return
// One fetch (min=0) backs both surfaces: the panel reads aboveByCategory, the
// typed tag-input dropdown reads the full set. No second request.
store.load(id)
}, { immediate: true })
// After a successful accept/alias-accept, refresh the modal's current
// tag list so TagPanel's chip rail reflects the newly-attached tag.
// Operator-flagged 2026-06-01: the suggestion store dropped the
// suggestion (correct) but didn't propagate the new tag back into the
// modal store, so the chip rail looked unchanged even though the
// backend had recorded the application. Mirrors the addExistingTag /
// createAndAdd flows which already call reloadTags() after applying.
async function onAccept(s) {
try {
await store.accept(s)
await host.reloadTags()
emit('accepted')
} catch (e) {
toast({ text: `Accept failed: ${e.message}`, type: 'error' })
}
}
</script>
<style scoped>
.fc-suggestions {
margin-top: 16px;
padding-top: 12px;
border-top: 1px solid rgb(var(--v-theme-surface-light));
}
.fc-suggestions__title {
font-family: 'Fraunces', Georgia, serif;
font-size: 16px; font-weight: 500;
color: rgb(var(--v-theme-on-surface));
margin-bottom: 8px;
}
.fc-suggestions__list {
/* No internal scroll cap: the rail now scrolls suggestions in its single
main scroll area while Related is pinned to the bottom (ImageViewer side
layout), so suggestions flow naturally without a nested scrollbar. */
padding-right: 4px;
}
.fc-suggestions__skeleton { display: flex; flex-direction: column; gap: 8px; }
.fc-suggestions__skel-row {
height: 18px; border-radius: 4px;
background: linear-gradient(
90deg,
rgb(var(--v-theme-surface)) 0%,
rgb(var(--v-theme-surface-light)) 50%,
rgb(var(--v-theme-surface)) 100%
);
background-size: 200% 100%;
animation: fc-shimmer 1.4s infinite;
}
@keyframes fc-shimmer {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
</style>