Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-12932: Always show [No lyrics] in work languages #2857

Merged
merged 1 commit into from
Feb 21, 2023
Merged
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
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