Skip to content

Commit 5bbec3d

Browse files
authored
#12486 GeoNode service uses the category identifier on catalog cards (#12505)
Fix #12486 GeoNode service uses the category identifier on catalog cards
1 parent 203530b commit 5bbec3d

5 files changed

Lines changed: 109 additions & 7 deletions

File tree

web/client/api/catalog/GeoNode.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,35 @@ export const resolveTagFilterType = (service) => {
5353
return getGeoNodeDefaultTagFilterType();
5454
};
5555

56+
const getTagLabel = (tag, tagFilterType) => {
57+
if (!tag || typeof tag !== 'object') {
58+
return tag;
59+
}
60+
if (tagFilterType === 'category') {
61+
return tag.label || tag.gn_description || tag.identifier;
62+
}
63+
if (tagFilterType === 'keyword') {
64+
return tag.label || tag.name || tag.slug;
65+
}
66+
return tag.label || tag.name || tag.gn_description || tag.identifier || tag.slug;
67+
};
68+
69+
const normalizeTag = (tag, tagFilterType) => {
70+
if (!tag || typeof tag !== 'object') {
71+
return tag;
72+
}
73+
const label = getTagLabel(tag, tagFilterType);
74+
return label ? { ...tag, label } : tag;
75+
};
76+
5677
export const getCatalogRecords = (records, options) => {
5778
if (records && records.records) {
5879
const tagFilterType = resolveTagFilterType(options?.service);
5980
return records.records.map((record) => {
60-
const tags = tagFilterType === 'keyword'
81+
const tags = (tagFilterType === 'keyword'
6182
? (record.keywords || [])
62-
: (record.category ? [record.category] : []);
83+
: (record.category ? [record.category] : []))
84+
.map((tag) => normalizeTag(tag, tagFilterType));
6385
return {
6486
...record,
6587
serviceType: "geonode",

web/client/api/catalog/__tests__/GeoNode-test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,40 @@ describe('Test correctness of the GeoNode catalog APIs', () => {
3737
expect(records[0].pk).toBe(123);
3838
});
3939

40+
it('geonode catalog records mapping uses category label for tags', () => {
41+
const records = getCatalogRecords({
42+
records: [{
43+
title: 'Title',
44+
category: {
45+
identifier: 'boundaries',
46+
gn_description: 'Boundaries'
47+
},
48+
pk: 123
49+
}]
50+
});
51+
expect(records[0].tags).toEqual([{
52+
identifier: 'boundaries',
53+
gn_description: 'Boundaries',
54+
label: 'Boundaries'
55+
}]);
56+
});
57+
58+
it('geonode catalog records mapping falls back to category identifier for tag label', () => {
59+
const records = getCatalogRecords({
60+
records: [{
61+
title: 'Title',
62+
category: {
63+
identifier: 'boundaries'
64+
},
65+
pk: 123
66+
}]
67+
});
68+
expect(records[0].tags).toEqual([{
69+
identifier: 'boundaries',
70+
label: 'boundaries'
71+
}]);
72+
});
73+
4074
it('geonode catalog records returns null with no records', () => {
4175
expect(getCatalogRecords()).toBe(null);
4276
expect(getCatalogRecords({})).toBe(null);

web/client/components/catalog/__tests__/CatalogCard-test.jsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ReactDOM from 'react-dom';
1111
import expect from 'expect';
1212
import TestUtils from 'react-dom/test-utils';
1313
import CatalogCard from '../datasets/CatalogCard';
14+
import { GEONODE_CATEGORY_FILTER } from '../../../api/catalog/GeoNode';
1415

1516
describe('CatalogCard component', () => {
1617
const record = {
@@ -136,4 +137,44 @@ describe('CatalogCard component', () => {
136137
const card = document.querySelector('.ms-catalog-card.disabled');
137138
expect(card).toBeTruthy();
138139
});
140+
141+
it('renders GeoNode category tag label while preserving identifier as filter value', () => {
142+
const actions = {
143+
onTagClick: () => {}
144+
};
145+
const spyOnTagClick = expect.spyOn(actions, 'onTagClick');
146+
const geonodeRecord = {
147+
...record,
148+
tagFilterType: 'category',
149+
tags: [{
150+
identifier: 'boundaries',
151+
label: 'Boundaries'
152+
}]
153+
};
154+
155+
ReactDOM.render(<CatalogCard
156+
includeAddToMap={false}
157+
multiSelect={false}
158+
loadingRecords={false}
159+
filters={{
160+
[GEONODE_CATEGORY_FILTER]: ['boundaries']
161+
}}
162+
record={geonodeRecord}
163+
onToggle={() => {}}
164+
onAdd={() => {}}
165+
onTagClick={actions.onTagClick}
166+
/>, document.getElementById('container'));
167+
168+
const tagButton = document.querySelector('.ms-resource-card-tag-button');
169+
expect(tagButton).toBeTruthy();
170+
expect(tagButton.textContent).toBe('Boundaries');
171+
expect(tagButton.getAttribute('title')).toBe('Boundaries');
172+
expect(tagButton.className.includes('selected')).toBe(true);
173+
174+
TestUtils.Simulate.click(tagButton, { stopPropagation: () => {} });
175+
176+
expect(spyOnTagClick).toHaveBeenCalled();
177+
expect(spyOnTagClick.calls[0].arguments[0]).toBe('boundaries');
178+
expect(spyOnTagClick.calls[0].arguments[1]).toEqual(geonodeRecord);
179+
});
139180
});

web/client/components/catalog/datasets/CatalogCard.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ const CatalogCard = ({
236236
filter: activeFilterKey,
237237
itemColor: 'color',
238238
itemValue: activeFilterProp,
239+
itemLabel: 'label',
239240
itemSelected: 'selected',
240241
onClick: onTagClick
241242
? (tagValue) => onTagClick(tagValue, record)

web/client/components/catalog/resources/ResourceCard.jsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,18 @@ const ResourceCardMetadataValue = tooltip(({
129129

130130
const getProperties = () => {
131131
if (isObject(value)) {
132+
const itemValue = value[entry.itemValue];
133+
const itemLabel = entry.itemLabel ? value[entry.itemLabel] : null;
132134
return {
133-
value: value[entry.itemValue],
135+
value: itemValue,
136+
label: itemLabel || itemValue || '',
134137
color: value[entry.itemColor],
135138
selected: !!value?.[entry.itemSelected]
136139
};
137140
}
138141
return {
139-
value
142+
value,
143+
label: value
140144
};
141145
};
142146

@@ -158,13 +162,13 @@ const ResourceCardMetadataValue = tooltip(({
158162
{...props}
159163
className={`ms-tag ms-resource-card-tag-button${properties.selected ? ' selected' : ''}`}
160164
style={getTagColorVariables(properties.color)}
161-
title={properties.value}
165+
title={properties.label}
162166
onClick={(event) => {
163167
event.stopPropagation();
164168
entry.onClick(properties.value, event);
165169
}}
166170
>
167-
{properties.value}
171+
{properties.label}
168172
</Button>
169173
);
170174
}
@@ -184,7 +188,7 @@ const ResourceCardMetadataValue = tooltip(({
184188
>
185189
{entry.type === 'date' && entry.format && properties.value
186190
? moment(properties.value).format(entry.format)
187-
: properties.value}
191+
: properties.label}
188192
</ALink>
189193
);
190194
});

0 commit comments

Comments
 (0)