Skip to content

Commit f8d6fbb

Browse files
AryanBVclaude
andcommitted
fix: Always show grade qualifiers in coffee classification options
The first option in a group was missing its grade qualifier (e.g., "Arabica plantation" instead of "Arabica plantation - A Grade"). Root cause: generateUniqueLabel() returned base label if unique, before checking if there was a meaningful grade qualifier to show. Fix: Detect grade patterns (A/B/C/AB/PB/AAA/B/B/B Grade) and always include them in the label, ensuring users see the full grade info. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent db1f67e commit f8d6fbb

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

backend/src/services/llm-navigator.service.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,23 @@ function generateUniqueLabel(
831831
baseLabel = cleanDesc;
832832
}
833833

834-
// Step 3: Try base label first (but NOT if it's a generic "Other" - those need qualifiers)
834+
// Step 3: Check if we have a meaningful qualifier that should ALWAYS be shown
835+
// Grade indicators should always be displayed (A Grade, B Grade, AB Grade, PB Grade, etc.)
836+
const gradePatterns = /\b([A-C]|AB|PB|B\/B\/B|AAA|AA)\s*(Grade)?\b/i;
837+
const hasGradeQualifier = qualifier && gradePatterns.test(qualifier);
838+
839+
// If there's a grade qualifier, always include it (don't just return base label)
840+
if (hasGradeQualifier) {
841+
const labelWithGrade = `${baseLabel} - ${qualifier}`;
842+
if (!existingLabels.has(labelWithGrade)) {
843+
existingLabels.add(labelWithGrade);
844+
return labelWithGrade;
845+
}
846+
}
847+
848+
// For non-grade qualifiers, try base label first (only if unique)
835849
const isGenericBase = baseLabel.toLowerCase() === 'other';
836-
if (!isGenericBase && !existingLabels.has(baseLabel) && baseLabel.length > 0) {
850+
if (!isGenericBase && !existingLabels.has(baseLabel) && baseLabel.length > 0 && !hasGradeQualifier) {
837851
existingLabels.add(baseLabel);
838852
return baseLabel;
839853
}

0 commit comments

Comments
 (0)