From 8f5275cc59189c0f853468e6c403497b233235d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Tamargo?= Date: Tue, 21 Feb 2023 12:52:37 +0200 Subject: [PATCH] MBS-12932: Always show [No lyrics] in work languages Before this, [No lyrics] worked on the main list, but it regressed to No linguistic content for recent entities. This also means languages in the dropdown are actually translated also when they're in recent entities, which they were not before. --- .../common/components/Autocomplete2/recentItems.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/root/static/scripts/common/components/Autocomplete2/recentItems.js b/root/static/scripts/common/components/Autocomplete2/recentItems.js index ec826db4847..62c55c5935f 100644 --- a/root/static/scripts/common/components/Autocomplete2/recentItems.js +++ b/root/static/scripts/common/components/Autocomplete2/recentItems.js @@ -10,6 +10,7 @@ import * as Sentry from '@sentry/browser'; import {MAX_RECENT_ENTITIES} from '../../constants.js'; +import localizeLanguageName from '../../i18n/localizeLanguageName.js'; import linkedEntities from '../../linkedEntities.mjs'; import isDatabaseRowId from '../../utility/isDatabaseRowId.js'; import isGuid from '../../utility/isGuid.js'; @@ -162,8 +163,14 @@ export function getRecentItems<+T: EntityItemT>( return _recentItemsCache.get(key) ?? []; } -function getEntityName(entity: EntityItemT): string { +function getEntityName( + entity: EntityItemT, + isLanguageForWorks?: boolean, +): string { switch (entity.entityType) { + case 'language': { + return localizeLanguageName(entity, isLanguageForWorks); + } case 'link_type': { return formatLinkTypePhrases(entity); } @@ -190,6 +197,8 @@ export async function getOrFetchRecentItems<+T: EntityItemT>( } if (ids.size) { + const isLanguageForWorks = key === 'language-lyrics'; + // Convert ids to an array since we delete in the loop. for (const id of Array.from(ids)) { const entity: ?T = linkedEntities[entityType]?.[id]; @@ -197,7 +206,7 @@ export async function getOrFetchRecentItems<+T: EntityItemT>( cachedList.push({ entity: entity, id: String(entity.id) + '-recent', - name: getEntityName(entity), + name: getEntityName(entity, isLanguageForWorks), type: 'option', }); ids.delete(id);