fix: match cluster custom names by both cluster_id and name keys

- API returns cluster_id as integer (1, 2) but localStorage saves with string keys
- Now tries matching by both cluster_id and original name
- Fixes rename persistence not being applied after page refresh
This commit is contained in:
2026-10-30 22:07:47 +08:00
parent f23124a157
commit 1f3bb31b2d

View File

@@ -382,8 +382,10 @@ export function setClusterResults(fileUuid: string, results: any[]) {
const savedCache = JSON.parse(saved)
const existing = savedCache[fileUuid] || []
for (const r of existing) {
if (r.cluster_id && r.name && !r.name.startsWith('Person_') && !r.name.startsWith('Trace ') && !r.name.startsWith('Face Trace ')) {
existingNames[r.cluster_id] = r.name
// Use cluster_id as key (can be integer or string like "Person_0")
const key = r.cluster_id ?? r.name
if (key && r.name && !r.name.startsWith('Person_') && !r.name.startsWith('Trace ') && !r.name.startsWith('Face Trace ')) {
existingNames[String(key)] = r.name
}
}
console.log('[setClusterResults] Loaded custom names from localStorage:', existingNames)
@@ -395,10 +397,13 @@ export function setClusterResults(fileUuid: string, results: any[]) {
// Create new objects to trigger Vue reactivity
const newResults = results.map(r => {
const newR = { ...r, trace_ids: [...(r.trace_ids || [])] }
// Apply custom names to new results
if (r.cluster_id && existingNames[r.cluster_id]) {
newR.name = existingNames[r.cluster_id]
console.log('[setClusterResults] Applied custom name:', existingNames[r.cluster_id], 'for cluster:', r.cluster_id)
// Apply custom names - try matching by cluster_id first, then by original name
const cidKey = String(r.cluster_id ?? '')
const nameKey = r.name || ''
const customName = existingNames[cidKey] || existingNames[nameKey]
if (customName) {
newR.name = customName
console.log('[setClusterResults] Applied custom name:', customName, 'for cluster:', r.cluster_id, '(name:', r.name, ')')
}
return newR
})