Skip to content

Conversation

binh-dam-ibigroup
Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup commented Oct 13, 2025

This PR introduces a Distance component with support of imperial and metric units. A new app config option is also introduced to display units as metric or imperial.

This PR should result in a new minor version number for the following packages:

  • types
  • humanize-distance
  • itinerary-body
  • printable-itinerary

Fix #116

Copy link
Contributor

@daniel-heppner-ibigroup daniel-heppner-ibigroup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some opinions on how the configuration of these parameters is passed around, but I think it might be a bit pedantic, since what you have is maybe fine. Maybe a second opinion will be good.

@@ -0,0 +1,39 @@
export interface DistanceParams {
unit: "meter" | "kilometer" | "foot" | "mile";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this union type its own type? It could be useful for a consumer to have access to that type in case a component is built around this that accepts the unit on its own for some reason.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing now that this is only used internally and isn't exposed in any props, so this is actually fine!

import MapillaryButton from "./mapillary-button";

interface Props {
imperial: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure it makes the most sense to make this the prop, rather than and optional metric prop? Since we defaulted to imperial before, we could avoid this being a breaking change right?

};

export const isImperial = (config: Config): boolean =>
!config.units || config.units === "imperial";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding my previous comment about using a metric boolean rather than imperial, maybe it would be better to just pass the string from config.units around instead, instead of creating an intermediate format that gets passed around? Stylistically I'm not sure which is better. I'd probably have just passed the string around personally.

{leg.steps.map((step, k) => (
<S.LegDetail key={k}>
<S.AccessLegStep step={step} />
<S.AccessLegStep imperial={imperial} step={step} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like, this line could just be units={config.units} and then the string comparison can be done once inside AccessLegStep.

* The preferred unit system to use, either metric or imperial.
* The default is 'imperial' so that existing visuals with distances in feet/miles don't break.
*/
units?: "metric" | "imperial";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this union type is the one that should be made into its own type and used instead of the boolean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support distance display in metric units

2 participants