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
49 changes: 49 additions & 0 deletions frontend/src/__tests__/components/SearchResults.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,55 @@ describe('SearchResults Component', () => {
screen.getByText('Tufts University, Cambridge Grid')
).toBeInTheDocument();
});

it('displays resource types and themes as filter chips instead of subjects', () => {
const resultWithChips: GeoDocument = {
...mockFixtureData[0],
attributes: {
ogm: {
...mockFixtureData[0].attributes.ogm,
gbl_resourceType_sm: ['Topographic maps', 'Digital maps'],
dcat_theme_sm: ['Elevation'],
dct_subject_sm: ['A long, unnormalized subject heading'],
dct_subjects_sm: ['Another subject heading'],
},
},
};

render(
<TestWrapper>
<SearchResults
results={[resultWithChips]}
isLoading={false}
totalResults={1}
currentPage={1}
/>
</TestWrapper>
);

expect(
screen.getByRole('link', { name: 'Topographic maps' })
).toHaveAttribute(
'href',
'/search?include_filters%5Bgbl_resourceType_sm%5D%5B%5D=Topographic+maps'
);
expect(
screen.getByRole('link', { name: 'Digital maps' })
).toHaveAttribute(
'href',
'/search?include_filters%5Bgbl_resourceType_sm%5D%5B%5D=Digital+maps'
);
expect(screen.getByRole('link', { name: 'Elevation' })).toHaveAttribute(
'href',
'/search?include_filters%5Bdcat_theme_sm%5D%5B%5D=Elevation'
);
expect(
screen.queryByText('A long, unnormalized subject heading')
).not.toBeInTheDocument();
expect(
screen.queryByText('Another subject heading')
).not.toBeInTheDocument();
});
});

describe('Links and Navigation', () => {
Expand Down
45 changes: 17 additions & 28 deletions frontend/src/components/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,17 @@ export function SearchResults({
) : null}
</div>

{/* Subject and Theme tags */}
{/* Resource Type and Theme tags */}
{!isCompact && (
<>
<div className="hidden md:flex flex-col gap-4 flex-1">
{(() => {
// Get subjects from dct_subjects_sm or dct_subject_sm
const subjects =
(ogm?.dct_subjects_sm &&
Array.isArray(ogm.dct_subjects_sm) &&
ogm.dct_subjects_sm.length > 0
? ogm.dct_subjects_sm
: null) ||
(ogm?.dct_subject_sm &&
Array.isArray(ogm.dct_subject_sm) &&
ogm.dct_subject_sm.length > 0
? ogm.dct_subject_sm
: null);
const resourceTypes =
ogm?.gbl_resourceType_sm &&
Array.isArray(ogm.gbl_resourceType_sm) &&
ogm.gbl_resourceType_sm.length > 0
? ogm.gbl_resourceType_sm
: null;

// Get themes from dcat_theme_sm
const themes =
Expand All @@ -317,33 +311,28 @@ export function SearchResults({
return `/search?${params.toString()}`;
};

// Determine which field name to use for subjects
const subjectField = ogm?.dct_subjects_sm
? 'dct_subjects_sm'
: 'dct_subject_sm';

return (subjects && subjects.length > 0) ||
return (resourceTypes && resourceTypes.length > 0) ||
(themes && themes.length > 0) ? (
<div className="flex flex-wrap gap-2">
{subjects?.map((subject, index) => {
const subjectValue =
typeof subject === 'string'
? subject
: String(subject);
{resourceTypes?.map((resourceType, index) => {
const resourceTypeValue =
typeof resourceType === 'string'
? resourceType
: String(resourceType);
return (
<Link
key={`subject-${index}`}
key={`resource-type-${index}`}
to={createTagSearchUrl(
subjectField,
subjectValue
'gbl_resourceType_sm',
resourceTypeValue
)}
className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800 hover:bg-blue-200 transition-colors"
onClick={(e) => {
// Prevent navigation if clicking on the result link
e.stopPropagation();
}}
>
{subjectValue}
{resourceTypeValue}
</Link>
);
})}
Expand Down
Loading