From 0f920d7c619bacf3d033ec551a9194fd075cd909 Mon Sep 17 00:00:00 2001 From: Nathan Pixodeo Date: Fri, 26 Jun 2026 09:22:30 +0200 Subject: [PATCH] Use project hashtag for OSMCha filters --- frontend/src/utils/osmchaLink.js | 15 ++++++++++++++- frontend/src/utils/tests/osmchaLink.test.js | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/frontend/src/utils/osmchaLink.js b/frontend/src/utils/osmchaLink.js index 7d3dc7bbfd..e517781f90 100644 --- a/frontend/src/utils/osmchaLink.js +++ b/frontend/src/utils/osmchaLink.js @@ -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 @@ -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') { @@ -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 }; } diff --git a/frontend/src/utils/tests/osmchaLink.test.js b/frontend/src/utils/tests/osmchaLink.test.js index a3d3940848..e15847c6e1 100644 --- a/frontend/src/utils/tests/osmchaLink.test.js +++ b/frontend/src/utils/tests/osmchaLink.test.js @@ -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,