fix(modal): accept-by-known-id keeps the raw suggestion row identity for the drop
CI / lint (push) Successful in 4s
CI / frontend-build (push) Successful in 29s
CI / backend-lint-and-test (push) Successful in 1m6s
CI / integration (push) Successful in 4m31s

Spreading canonical_tag_id onto a raw suggestion changed its _keyOf
identity, so _dropEverywhere missed the actual list row and the panel
kept showing an already-accepted suggestion. Pass the resolved id as an
option instead; pinned with a raw-suggestion spec.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CDgx8bQS5YrGRK76v8HUnM
This commit is contained in:
2026-07-02 22:02:24 -04:00
parent 6d314d662f
commit 581b778528
3 changed files with 35 additions and 11 deletions
+2 -5
View File
@@ -131,10 +131,7 @@ async function onPickExisting(hit) {
// (operator-asked 2026-07-03).
const pending = suggestions.findPending(hit.kind, hit.name, hit.id)
if (pending) {
await suggestions.accept({
...pending,
canonical_tag_id: pending.canonical_tag_id ?? hit.id,
})
await suggestions.accept(pending, { tagId: hit.id })
await host.reloadTags()
} else {
await host.addExistingTag(hit.id)
@@ -156,7 +153,7 @@ async function onPickNew(payload) {
if (created && host.currentImageId === imageId) {
const pending = suggestions.findPending(payload.kind, payload.name, created.id)
if (pending) {
await suggestions.accept({ ...pending, canonical_tag_id: created.id })
await suggestions.accept(pending, { tagId: created.id })
}
}
focusTagInput()
+7 -2
View File
@@ -97,7 +97,12 @@ export const useSuggestionsStore = defineStore('suggestions', () => {
}
}
async function accept(suggestion) {
// opts.tagId: the tag's known id, when the caller already created/resolved
// it (TagPanel's manual-add-matches-suggestion path). Passed separately —
// NOT spread onto the suggestion — because _dropEverywhere keys off the
// suggestion object, and mutating canonical_tag_id on a raw suggestion
// would stop it matching its own row in the lists.
async function accept(suggestion, { tagId: knownTagId = null } = {}) {
// Capture imageId so a mid-flight prev/next can't reroute the
// accept POST to a different image AND push the tag to that
// image's allowlist.
@@ -106,7 +111,7 @@ export const useSuggestionsStore = defineStore('suggestions', () => {
// Raw tags (creates_new_tag) have no canonical_tag_id; the backend's
// accept endpoint needs a tag_id, so for raw tags we create the tag
// first via the existing /api/tags endpoint, then accept by id.
let tagId = suggestion.canonical_tag_id
let tagId = knownTagId ?? suggestion.canonical_tag_id
if (tagId == null) {
const created = await api.post('/api/tags', {
body: { name: suggestion.display_name, kind: suggestion.category }
+26 -4
View File
@@ -78,13 +78,35 @@ describe('suggestions store: accept with a known tag id', () => {
calls.push({ url, method: init?.method })
return { status: 200, body: { accepted: true, tag_id: 7 } }
})
// TagPanel routes a manual pick that matches a pending suggestion through
// accept, filling canonical_tag_id from the picked hit when the
// suggestion is raw — no /api/tags create must fire in that case.
await s.accept({ ...s.byCategory.character[0], canonical_tag_id: 7 })
await s.accept(s.byCategory.character[0], { tagId: 7 })
expect(calls).toHaveLength(1)
expect(calls[0].url).toContain('/api/images/1/suggestions/accept')
expect(s.byCategory.character).toHaveLength(0)
expect(s.allByCategory.character).toHaveLength(0)
})
it('a RAW suggestion accepted with a known tagId skips create AND still drops its row', async () => {
// TagPanel's manual-create path: the tag was just created by
// host.createAndAdd, so accept must not create again — and the drop must
// key off the original raw suggestion object, not the resolved id
// (regression: spreading canonical_tag_id onto the suggestion changed its
// identity key and left the panel row behind).
const s = useSuggestionsStore()
const raw = sugg({
canonical_tag_id: null, display_name: 'Holding Sword',
category: 'general', creates_new_tag: true,
})
await seed(s, { general: [raw] })
const calls = []
stubFetch((url, init) => {
calls.push({ url, body: init?.body })
return { status: 200, body: { accepted: true, tag_id: 42 } }
})
await s.accept(s.byCategory.general[0], { tagId: 42 })
expect(calls).toHaveLength(1)
expect(calls[0].url).toContain('/api/images/1/suggestions/accept')
expect(JSON.parse(calls[0].body)).toEqual({ tag_id: 42 })
expect(s.byCategory.general).toHaveLength(0)
expect(s.allByCategory.general).toHaveLength(0)
})
})