Skip to content
Open
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
15 changes: 14 additions & 1 deletion frontend/src/utils/osmchaLink.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { retrieveDefaultChangesetComment } from './defaultChangesetComment';

export function formatOSMChaLink(infoObj) {
const baseURL = 'https://osmcha.org/';
// If a custom filter id is given, ignores everything else
Expand Down Expand Up @@ -26,7 +28,7 @@ export function formatOSMChaLink(infoObj) {
}

if (infoObj.changesetComment) {
filterParams['comment'] = buildFilter(infoObj.changesetComment);
filterParams['comment'] = buildFilter(getOsmchaCommentFilter(infoObj));
}

if (typeof infoObj.usernames === 'object') {
Expand All @@ -36,6 +38,17 @@ export function formatOSMChaLink(infoObj) {
return `${baseURL}?filters=${encodeURIComponent(JSON.stringify(filterParams))}`;
}

function getOsmchaCommentFilter(infoObj) {
if (infoObj.projectId) {
const defaultProjectComment = retrieveDefaultChangesetComment(
infoObj.changesetComment,
infoObj.projectId,
);
return defaultProjectComment[0] || infoObj.changesetComment;
}
return infoObj.changesetComment;
}

function buildFilterValue(value) {
return { label: value, value: value };
}
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/utils/tests/osmchaLink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ describe('test OSMCha link to project', () => {
);
});

it('uses only the default project hashtag from a project changeset comment', () => {
const project = {
projectId: 46866,
osmchaFilterId: null,
aoiBBOX: '139.408264,-5.163437,140.252838,-4.521666',
changesetComment:
'#hotosm-project-46866 mapped buildings in Indonesia for #msf #missingmaps #indonesia25',
created: '2026-03-23T12:20:42.460024Z',
};
expect(formatOSMChaLink(project)).toBe(
`https://osmcha.org/?filters=${encodeURIComponent(
'{"in_bbox":[{"label":"139.408264,-5.163437,140.252838,-4.521666","value":"139.408264,-5.163437,140.252838,-4.521666"}],"area_lt":[{"label":2,"value":2}],"date__gte":[{"label":"2026-03-23","value":"2026-03-23"}],"comment":[{"label":"#hotosm-project-46866","value":"#hotosm-project-46866"}]}',
)}`,
);
});

it('with aoiBBOX as a list', () => {
const project = {
osmchaFilterId: null,
Expand Down