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

feat(location-field): make location group order configurable #771

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

amy-corson-ibigroup
Copy link
Contributor

Allows configuration of the order of the returned location group results, so that if you pass renderOtherFirst through the config, it puts the "other" category first in the results, above stops and stations.

renderOtherFirst !renderOtherFirst
image image

Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

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

Code looks fine, but could you add in one of the stories a control to toggle on/off the new renderOtherFirst prop? Also, please update the snapshots.

const OtherFeaturesHeader = () => (
<S.MenuGroupHeader as={headingType} bgColor="#333" key="other-header">
<FormattedMessage
description="Text for header above the 'other'"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Description looks unfinished, could you fix please?

@amy-corson-ibigroup
Copy link
Contributor Author

Blocked by #774

@amy-corson-ibigroup amy-corson-ibigroup added the BLOCKERS Blockers exist outside of otp-ui (e.g., backend, service, etc...) label Sep 10, 2024
@amy-corson-ibigroup amy-corson-ibigroup removed the BLOCKERS Blockers exist outside of otp-ui (e.g., backend, service, etc...) label Sep 10, 2024
Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup left a comment

Choose a reason for hiding this comment

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

Can you please use Storybook controls to illustrate renderOtherFirst?

const [otherControl, setOtherControl] = useState(false);
return (
<>
<label htmlFor="other-input">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you make Storybook create the controls using argTypes instead? (Storybook will add that to its "Controls" tab - I should have mentioned that in my previous review but somehow thought you knew) Do that for this story only. Refer to e.g.

for an example.

Copy link
Collaborator

@miles-grant-ibigroup miles-grant-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 don't think an explicit boolean to push a specific category to the top is a good idea

/**
* If true, make "Other" category (addresses, POIs, etc.) first in the results container.
*/
renderOtherFirst?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this an array instead? Where we can manually set an order of categories to prioritize (and those will be displayed first). This might require a bigger refactor but I think it's worth it. Let me know if you'd like to discuss in more detail offline

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so like ["STOPS", "STATIONS", "OTHER"] as the config item?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update in 03c02ac!!

Copy link
Collaborator

@miles-grant-ibigroup miles-grant-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 like it much better now! Still a few cleanup suggestsion

description="Text for header above Stations"
id="otpUi.LocationField.stations"
description="Text for header above the 'other' category of geocoder results"
id={`otpUi.LocationField.${titleId}`}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume this breaks the i18n string checks? Also we've spent a lot of effort and time elsewhere to not do this, are we ok with doing it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there's a way to skip any ids we're dynamically generating in the i18n check, but it doesn't feel worth it here so I passed the entire i18n id instead!

packages/location-field/src/index.tsx Outdated Show resolved Hide resolved
packages/location-field/src/index.tsx Outdated Show resolved Hide resolved
layerColorMap={layerColorMap}
locationType="from"
onLocationSelected={onLocationSelected}
geocoderResultsOrder={["OTHER", "STATIONS", "STOPS"]}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bit of a nit, but could we put the strings into an object so they're more consistent? Similar to how we do the view ids in otp-rr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you clarify where in OTP-RR to look for this? Also, we're using a lot of array methods here, what's the benefit of making this an object?

Copy link
Collaborator

Choose a reason for hiding this comment

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

lib/actions/ui-constants.js!

Really this should be an enum but we can't do that in JS so an object with keys that are strings is the cleanest way to do it. Using an enum is good practice, prevents silly mistakes, and prevents us from having to copy paste strings aroudn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in e2b352e!

Comment on lines 664 to 665
description="Text for header above the 'other' category of geocoder results"
id={`otpUi.LocationField.${titleId}`}
id={title118nId}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is pretty messy. Can we just pass in JSX and have the calling function call FormattedMessage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in e2b352e, but let me know if this is not what you meant!

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.

4 participants