Skip to content

Commit

Permalink
fix(frontend): correctly pass the entity id when loading by intent url
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed May 24, 2024
1 parent b11a908 commit db74663
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/frontend/src/components/DialogTaskActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ export default function Dialog({ taskId, feature, map, view }) {
type="submit"
className="fmtm-font-bold !fmtm-rounded fmtm-text-sm !fmtm-py-2 !fmtm-w-full fmtm-flex fmtm-justify-center"
onClick={() => {
// XForm name is constructed from lower case project title with underscores
const projectName = projectInfo.title.toLowerCase().split(' ').join('_');
const projectCategory = projectInfo.xform_category;
const formName = `${projectName}_${projectCategory}`;
document.location.href = `odkcollect://form/${formName}?task_id=${taskId}`;
// TODO add this to each feature popup to pre-load a selected entity
// document.location.href = `odkcollect://form/${formName}?${geomFieldName}=${entityId}`;
const xformId = projectInfo.xform_id;

try {
document.location.href = `odkcollect://form/${xformId}?task_id=${taskId}`;
} catch (error) {
document.location.href = 'https://play.google.com/store/apps/details?id=org.odk.collect.android';
}
}}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ type TaskFeatureSelectionProperties = {
};

type TaskFeatureSelectionPopupPropType = {
taskId: number;
featureProperties: TaskFeatureSelectionProperties | null;
};

const TaskFeatureSelectionPopup = ({ featureProperties }: TaskFeatureSelectionPopupPropType) => {
const TaskFeatureSelectionPopup = ({ taskId, featureProperties }: TaskFeatureSelectionPopupPropType) => {
const dispatch = CoreModules.useAppDispatch();
const taskModalStatus = CoreModules.useAppSelector((state) => state.project.taskModalStatus);
const projectInfo = CoreModules.useAppSelector((state) => state.project.projectInfo);
Expand Down Expand Up @@ -84,19 +85,20 @@ const TaskFeatureSelectionPopup = ({ featureProperties }: TaskFeatureSelectionPo
type="submit"
className="fmtm-font-bold !fmtm-rounded fmtm-text-sm !fmtm-py-2 !fmtm-w-full fmtm-flex fmtm-justify-center"
onClick={() => {
// XForm name is constructed from lower case project title with underscores
const projectName = projectInfo.title.toLowerCase().split(' ').join('_');
const projectCategory = projectInfo.xform_category;
const formName = `${projectName}_${projectCategory}`;
const xformId = projectInfo.xform_id;

const entity = entityOsmMap.find((x) => x.osm_id === featureProperties?.osm_id);
const entityUuid = entity ? entity.id : null;

if (!formName || !entityUuid) {
if (!xformId || !entityUuid) {
return;
}

document.location.href = `odkcollect://form/${formName}?existing=${entityUuid}`;
try {
document.location.href = `odkcollect://form/${xformId}?task_id=${taskId}&existing=${entityUuid}`;
} catch (error) {
document.location.href = 'https://play.google.com/store/apps/details?id=org.odk.collect.android';
}
}}
/>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/src/views/ProjectDetailsV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ const Home = () => {
}
/>
)}
{selectedTaskFeature != undefined && <FeatureSelectionPopup featureProperties={selectedFeatureProps} />}
{selectedTaskFeature != undefined && (
<FeatureSelectionPopup taskId={selectedTask} featureProperties={selectedFeatureProps} />
)}
</div>
);
};
Expand Down

0 comments on commit db74663

Please sign in to comment.