Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/map-projects/MapProject.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ import { createLookupSession, LOOKUP_NOT_FOUND } from './lookupSession'
import { parseConceptKey } from './conceptKey'
import { normalizeLookupConfig } from './lookupConfigFields'
import { getDeclaredLocales, getDefaultTargetRepoVersion, getProjectTargetRepoVersion, getSavedTargetRepoVersion, getTargetRepoVersionFromUrl, getTargetRepoVersionId } from './projectTargetRepo'
import { buildBridgeTargetDownloadEntries, buildQualityRowViews, conceptBelongsToTargetRepo, conceptForMapping, findTargetRowView, formatBridgeTargetDownloadEntry, resolveAICandidateID, getScoreDetails, getAIAnalysisCandidateIDs, withCachedConcept, withCandidateNames, buildMatchEntries, restoredNote, withOwnNames, withSavedMatch } from './viewBuilders.js'
import { buildBridgeTargetDownloadEntries, buildQualityRowViews, conceptBelongsToTargetRepo, conceptForMapping, findTargetRowView, formatBridgeTargetDownloadEntry, resolveAICandidateID, getScoreDetails, getAIAnalysisCandidateIDs, getAIIndicatorTooltip, withCachedConcept, withCandidateNames, buildMatchEntries, restoredNote, withOwnNames, withSavedMatch } from './viewBuilders.js'
import { formatClockTime, getCapacityWaitLabel, mergeCapacityWaits } from './rowProgress.js'

import './MapProject.scss'
Expand Down Expand Up @@ -1100,6 +1100,7 @@ const MapProject = () => {
return {
status,
latestAnalysis,
primaryCandidateId,
isPrimaryMatch: Boolean(targetCode && primaryCandidateId && targetCode === primaryCandidateId),
isAlternateMatch: Boolean(targetCode && alternateCandidateIds.includes(targetCode)),
}
Expand Down Expand Up @@ -1203,7 +1204,7 @@ const MapProject = () => {
</IconButton>
</Tooltip> :
aiMeta?.latestAnalysis ?
<Tooltip title={aiMeta.isPrimaryMatch ? t('map_project.ai_recommended') : (aiMeta.isAlternateMatch ? t('map_project.ai_alternate') : t('map_project.ai_analysis'))}>
<Tooltip title={getAIIndicatorTooltip(aiMeta, t)}>
<span style={{display: 'inline-flex', paddingTop: '7px'}}>
<AssistantIcon color={aiMeta.isPrimaryMatch ? 'primary' : 'warning'} fontSize='small' />
</span>
Expand Down
32 changes: 31 additions & 1 deletion src/components/map-projects/__tests__/viewHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
* - conceptForMapping (the tuple -> legacy concept projection at the
* onMap / isSelectedForMap boundary)
* - resolveAICandidateID (AI Assistant response resolution chain)
* - getAIIndicatorTooltip (the AI icon's tooltip in the Target Code cell)
*
* Run with: npm test
*/

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import i18next from 'i18next'

import {
conceptBelongsToTargetRepo,
getScoreDetails,
conceptForMapping,
resolveAICandidateID,
getLatestAnalysisEntry,
getAIAnalysisCandidateIDs
getAIAnalysisCandidateIDs,
getAIIndicatorTooltip
} from '../viewBuilders.js'

const candidatesScore = { recommended: 80, available: 60 }
Expand Down Expand Up @@ -258,3 +262,29 @@ test('getAIAnalysisCandidateIDs: resolves primary + alternate ids from latest an
assert.deepEqual(out.alternateCandidateIds, ['ALT-1', 'ALT-2'])
assert.equal(out.latestAnalysis, analysis[1])
})

// ---------- getAIIndicatorTooltip (OpenConceptLab/ocl_issues#2934) ----------

const translator = async locale => {
const catalog = JSON.parse(readFileSync(new URL(`../../../i18n/locales/${locale}/translations.json`, import.meta.url), 'utf8'))
const i18n = i18next.createInstance()
await i18n.init({lng: locale, resources: {[locale]: {translations: catalog}}, ns: ['translations'], defaultNS: 'translations', interpolation: {escapeValue: false}})
return i18n.t
}

test('getAIIndicatorTooltip: orange names the AI\'s pick; the alternate, purple and no-pick cases keep their wording', async () => {
const t = await translator('en')
const tooltip = meta => getAIIndicatorTooltip({isPrimaryMatch: false, isAlternateMatch: false, primaryCandidateId: 'BA00.Z', ...meta}, t)
assert.equal(tooltip({}), 'The AI recommends BA00.Z')
assert.equal(tooltip({isAlternateMatch: true}), 'AI Alternate Candidate Suggestion')
assert.equal(tooltip({isPrimaryMatch: true}), 'AI Recommended')
assert.equal(tooltip({primaryCandidateId: null}), 'AI Analysis')
})

test('getAIIndicatorTooltip: every catalog names the recommended code', async () => {
for (const locale of ['en', 'es', 'pt-BR', 'zh']) {
const t = await translator(locale)
const tooltip = getAIIndicatorTooltip({isPrimaryMatch: false, isAlternateMatch: false, primaryCandidateId: 'BA00.Z'}, t)
assert.ok(tooltip.includes('BA00.Z'), `${locale}: ${tooltip}`)
}
})
8 changes: 8 additions & 0 deletions src/components/map-projects/viewBuilders.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,11 @@ export const getAIAnalysisCandidateIDs = (analysisProp, conceptCache) => {
alternateCandidateIds
}
}

// The AI icon's tooltip in the grid's Target Code cell; the orange one names the AI's pick (OpenConceptLab/ocl_issues#2934).
export const getAIIndicatorTooltip = ({isPrimaryMatch, isAlternateMatch, primaryCandidateId}, t) => {
if(isPrimaryMatch) return t('map_project.ai_recommended')
if(isAlternateMatch) return t('map_project.ai_alternate')
if(primaryCandidateId) return t('map_project.ai_recommends_code', {code: primaryCandidateId})
return t('map_project.ai_analysis')
}
1 change: 1 addition & 0 deletions src/i18n/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
"source": "Source",
"ai_recommended": "AI Recommended",
"ai_alternate": "AI Alternate Candidate Suggestion",
"ai_recommends_code": "The AI recommends {{code}}",
"ai_assistant": "OCL AI Assistant",
"ai_prompt_template_unavailable": "OCL AI Assistant prompt template is not available",
"view_raw_json": "View Raw JSON",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/es/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@
"source": "Fuente",
"ai_recommended": "Recomendado por IA",
"ai_alternate": "Sugerencia de candidato alternativo de IA",
"ai_recommends_code": "La IA recomienda {{code}}",
"ai_assistant": "Asistente de IA de OCL",
"ai_prompt_template_unavailable": "La plantilla de prompt del asistente de IA de OCL no está disponible",
"view_raw_json": "Ver JSON Sin Procesar",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/pt-BR/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
"source": "Source",
"ai_recommended": "Recomendado por IA",
"ai_alternate": "Sugestão de Candidato Alternativo por IA",
"ai_recommends_code": "A IA recomenda {{code}}",
"ai_assistant": "Assistente de IA do OCL",
"ai_prompt_template_unavailable": "O modelo de prompt do Assistente de IA do OCL não está disponível",
"view_raw_json": "Ver JSON Bruto",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/zh/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
"source": "来源",
"ai_recommended": "AI 推荐",
"ai_alternate": "AI 备选候选建议",
"ai_recommends_code": "AI 推荐的是 {{code}}",
"ai_assistant": "OCL AI 助手",
"ai_prompt_template_unavailable": "OCL AI 助手提示模板不可用",
"view_raw_json": "查看原始 JSON",
Expand Down
Loading