Skip to content

Support alternate term names for facet terms #730

@NoopDog

Description

@NoopDog

Summary

Add support for alternate term names (alternateName) for faceted search terms in the UI filtering system.

Background

Currently, facet terms are represented by the Term interface:

export interface Term {
  count: number;
  name: string;
  selected: boolean;
}

There is a need to support alternate display names for facet terms. Example scenarios include synonyms, UI localization, or projects with more user-friendly phrasing.

Requirements

  • Model: Add an alternateName?: string property to the Term interface.
  • Population:
    • The alternate term names map shall be loaded by the app from a file at /fe-api/alternateTermNames.json in the /public folder, if it exists in the app (not in this repo).
    • This file is optional and may be absent or empty in some apps. The system must be robust to the file not existing, being empty, or not containing certain facets/terms.
    • The alternate term names map should be loaded once on app load (not per facet) and cached in memory for the duration of the session.
    • Loading and storage must be handled by a high-level provider, such as AppStateProvider or a similar top-level provider, and injected/provided throughout the app.
  • Integration:
    • When creating Term objects (in bindFacetTerms in src/hooks/useFileManifest/common/utils.ts), look up the alternateName (if available) by facet and term name from the in-memory alternate term name map.
    • If not found or file is missing, default to normal name.
  • Display:
    • Update the facet display code so that wherever term labels are rendered for facets, use term.alternateName ?? term.name.
    • Do not update data row/table mappers for results display—only the facet selection UI should use alternateName.

Example implementation summary and changes

1. Term Interface

export interface Term {
  count: number;
  name: string;
  selected: boolean;
  alternateName?: string;
}

2. Loading alternate term names (sample pattern)

// In AppStateProvider or similar top-level provider
const [alternateTermNames, setAlternateTermNames] = useState<Record<string, Record<string, string>> | null>(null);

useEffect(() => {
  fetch('/fe-api/alternateTermNames.json')
    .then(response => response.ok ? response.json() : {})
    .then(data => setAlternateTermNames(data))
    .catch(() => setAlternateTermNames({})); // fallback: empty map
}, []);

Then inject this map/context to wherever bindFacetTerms or its caller needs to reference alternate names.

3. Completing bindFacetTerms

accum.push({
  count: responseTerm.count,
  name,
  selected,
  alternateName: getAlternateName(facetName, name) // look up from injected/loaded alternate names map
});

getAlternateName should check the in-memory map for [facetName][name] and return undefined if missing.

4. Facet Display

Wherever facet terms are rendered, use:

{term.alternateName ?? term.name}

Notes

  • The alternate term names file is NOT managed in this repo; it is app-specific and may be unavailable.
  • All network/file loading for alternate names must be done once, on app load, without retries or repeated requests.
  • The system must operate without errors, warnings, or visible problems if the alternate names file is missing or incomplete.
  • Do not change result row/record mappers or result/table display—facet selection UI only.
  • Apps with custom result row/record displays should open their own tickets as needed.
  • Provide a robust fallback to always display term.name if alternateName is missing.

Acceptance criteria

  • Alternate term names are loaded from the optional public/fe-api/alternateTermNames.json file by the app, once, and stored in memory.
  • Facet terms can display alternate names in the filter UI.
  • If the alternateName file or value is not found, fallback to the original name.
  • No errors, warnings, or unnecessary fetches/retries if the file is missing.
  • All requirements are validated via code review, UI verification, and tests.
  • Includes tests for:
    • Fallback behavior if no file or key is present.
    • Proper use of alternateName in the facet UI when present.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions