Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distance constraint add on frontend #2084

Open
wants to merge 15 commits into
base: development
Choose a base branch
from

Conversation

NSUWAL123
Copy link
Contributor

What type of PR is this? (check all applicable)

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation
  • πŸ§‘β€πŸ’» Refactor
  • βœ… Test
  • πŸ€– Build or CI
  • ❓ Other (please specify)

Related Issue

Describe this PR

Validate the distance between user location and entity if the distance constraint is true.
If the distance constant is set to true, the user must enable their device location & must be within the distance constraint set.

Screenshots

  1. Geolocation must be enabled if the distance constant set
    image_720

  2. Show a message if the user now within the range
    image_720

@NSUWAL123 NSUWAL123 requested a review from spwoodcock January 13, 2025 11:21
@github-actions github-actions bot added the enhancement New feature or request label Jan 13, 2025
@spwoodcock spwoodcock force-pushed the feat/distance-constraint branch from 3d81fa2 to 3c9f4c5 Compare January 13, 2025 15:57
@spwoodcock
Copy link
Member

spwoodcock commented Jan 13, 2025

I updated the logic to be:

// Check if drawn geometry is within set distance constraints from user
const isDistanceConstaintValid = (): boolean => {
const coordTo = entitiesStore.selectedEntityCoordinate?.coordinate;
const coordFrom = entitiesStore.userLocationCoord;

// Geolocation not enabled, warn user
if (!coordFrom) {
	alertStore.setAlert({
		message:
			'This project has a distance constraint set. Please enable device geolocation for optimal functionality',
		variant: 'warning',
	});
	return false;
}

const entityDistance = distance(coordFrom as Coord, coordTo as Coord, { units: 'kilometers' }) * 1000;
if (entityDistance && entityDistance > projectData?.geo_restrict_distance_meters) {
	// Feature is far away from user, warn user
	alertStore.setAlert({
		message: `The feature must be within ${projectData?.geo_restrict_distance_meters} meters of your location`,
		variant: 'warning',
	});
	if (projectData?.geo_restrict_force_error) {
		// Not valid coord, prevent user from continuing
		return false;
	}
	// Valid coord: it's outside of range, but only 'warn' user
	return true;
}

// Valid coord
return true;
};

The goal is to:

  • Warn the user if geo_restrict_force_error=False
  • Error / stop the user if geo_restrict_force_error=True

Hope this makes sense! Please check it works as intended, then merge πŸ™

@NSUWAL123
Copy link
Contributor Author

So do we want user's to restrict map the feature if their device location is turned off?
If yes then we shall update the toast message and let the user map the feature else we shall only update the toast message to Please enable device geolocation to map this feature.
image

@spwoodcock
Copy link
Member

I didn't test the logic, so perhaps made a mistake.

But you make a good point.
We can't force users to enable geolocation, hence its impossible to actually enforce this constraint.

Anyway, this should happen:

  • No geolocation, no force geo constraint: ignore / do not show warning.
  • No geolocation, force geo constraint: prompt to enable geolocation.
  • Geolocation, no force geo constraint: warning if triggered.
  • Geolocation, force geo constraint: error if triggered.

Does that sound right?

@spwoodcock
Copy link
Member

I'm really hesitant to block the user from mapping if they don't have location on (where I imagine this is what the Tokha team want @manjitapandey ?).

This would mean if there is a problem with the users geolocation, like they accidentally blocked access and can't work out how to enable access, they can't use FMTM (not ideal if they have been transported to the field and are now stuck and can't do anything)

@manjitapandey
Copy link
Contributor

Yes the conditions above sounds right.

also In such cases, For Tokha projects, field managers and monitoring team will always be available on call to assist mappers in field. For other project this may not be relevant so only warnings and prompt to enable geolocation should work but this case is different.

@spwoodcock
Copy link
Member

spwoodcock commented Jan 15, 2025

Thanks!

Let's block the mapping if geolocation is not enabled then @NSUWAL123 πŸ‘

@NSUWAL123
Copy link
Contributor Author

Updated logic to:

  • No geolocation, no force geo constraint: ignore / do not show warning
  • No geolocation, force geo constraint: prompt to enable geolocation
  • Geolocation, no force geo constraint: ignore / do not show warning
  • Geolocation, force geo constraint: error if triggered

@NSUWAL123 NSUWAL123 requested a review from spwoodcock January 16, 2025 07:31
@spwoodcock
Copy link
Member

So sorry to be a pain, but for the third option, do we not still want to show a warning?

Not a blocking error, but something like: 'The selected feature is far from your current location. Are you sure?'

@NSUWAL123
Copy link
Contributor Author

Sure! It makes sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants