Skip to content

Commit

Permalink
fix: format lat/long, use 2 decimal places [PT-188059329]
Browse files Browse the repository at this point in the history
  • Loading branch information
pjanik committed Aug 22, 2024
1 parent 7f54fdd commit fc59395
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export const App: React.FC = () => {
);
}
}
console.log("|| App: dataContextChange", values);
}, [handleCaseSelectionInCodap]);

useEffect(() => {
Expand Down
12 changes: 10 additions & 2 deletions src/components/location-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { LocationPicker } from "./location-picker";

import "../assets/scss/location-tab.scss";

function formatLatLng(latOrLng: number | string): string {
// Convert the number to a string with up to 2 decimal places
const formatted = Number(latOrLng).toFixed(2);
// Remove trailing zeros after the decimal point
const trimmed = formatted.replace(/(\.\d*?[1-9])0+$/, "$1").replace(/\.0+$/, "");
return trimmed;
}

interface LocationTabProps {
latitude: string;
longitude: string;
Expand Down Expand Up @@ -63,8 +71,8 @@ export const LocationTab: React.FC<LocationTabProps> = ({
};

const handleLocationSelect = (selectedLocation: ILocation) => {
setLatitude(selectedLocation.latitude.toString());
setLongitude(selectedLocation.longitude.toString());
setLatitude(formatLatLng(selectedLocation.latitude));
setLongitude(formatLatLng(selectedLocation.longitude));
setLocationSearch(selectedLocation.name);
};

Expand Down
4 changes: 2 additions & 2 deletions src/grasp-seasons/components/seasons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ body {
border-radius: 3px;
border: solid 1px rgba(23, 121, 145, 0.75);
background-color: #fff;
width: 37px;
width: 45px;
height: 24px;
padding: 3px 10px;
padding: 3px 6px;
}
}
}
Expand Down

0 comments on commit fc59395

Please sign in to comment.