Skip to content

Commit

Permalink
MBS-12932: Always show [No lyrics] in work languages (#2857)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
reosarevok authored Feb 21, 2023
1 parent 99b0fff commit 25999f1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions root/static/scripts/common/components/Autocomplete2/recentItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
Expand All @@ -190,14 +197,16 @@ 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];
if (entity) {
cachedList.push({
entity: entity,
id: String(entity.id) + '-recent',
name: getEntityName(entity),
name: getEntityName(entity, isLanguageForWorks),
type: 'option',
});
ids.delete(id);
Expand Down

0 comments on commit 25999f1

Please sign in to comment.