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 21 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.

Just a few tiny nitpicks!

return (
<>
{/* Only include the header if there are features to show */}
{(title === GeocoderResultsConstants.other ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
{(title === GeocoderResultsConstants.other ||
{(title === GeocoderResultsConstants.OTHER ||

typo?

@@ -113,6 +113,8 @@ export interface LocationFieldProps {
maxNearbyStops?: number;
type: string;
};
/** Order of geocoder results to display */
geocoderResultsOrder?: Array<"STATIONS" | "STOPS" | "OTHER">;
Copy link
Collaborator

Choose a reason for hiding this comment

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

There might be a fancy way to grab these from the object, but I'm not sure how. @daniel-heppner-ibigroup might now. But for now we should at least add a comment

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.

Code looks great but seeing an issue when there's no stations returned Screenshot 2024-10-14 at 12 58 36 PM

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.

Thank you!!

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.

Please try avoiding creating a new component type on each render.

bgColor,
title,
HeaderMessage,
featuresArray
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename to features? Sort props.

@@ -159,6 +160,11 @@ const LocationField = ({
GeocodedOptionIconComponent = GeocodedOptionIcon,
geocoderConfig,
getCurrentPosition,
geocoderResultsOrder = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sort props.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this prop is better than the original one.

Comment on lines +659 to +663
const Header = () => (
<S.MenuGroupHeader as={headingType} bgColor={bgColor} key={title}>
{HeaderMessage}
</S.MenuGroupHeader>
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Inline this or move this component to top level (avoid creating a new component class on each render).

let Element;
switch (result) {
case GeocoderResultsConstants.OTHER:
Element = otherFeatures.length > 0 && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename to element lower case.

/>
}
key="other-header"
featuresArray={otherFeatures}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sort props (multiple instances)

bgColor="#333"
HeaderMessage={
<FormattedMessage
id="otpUi.LocationField.other"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Default to English? (multiple instances)

// avoid displaying headers
const transitFeaturesPresent =
stopFeatures.length > 0 || stationFeatures.length > 0;
const FeaturesElements = ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this component to top level (avoid creating a new component class on each render).

currentPosition={currentPosition}
geocoderConfig={geocoderConfig}
getCurrentPosition={getCurrentPosition}
preferredLayers={["example_layer"]}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sort props

@binh-dam-ibigroup
Copy link
Collaborator

@amy-corson-ibigroup Also please update the props in the PR description...

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.

5 participants