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
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7aed84c
feat(location-field): make location group order configurable
amy-corson-ibigroup Sep 5, 2024
4781771
Add "renderOtherFirst" story
amy-corson-ibigroup Sep 9, 2024
f1e412b
Finish OtherFeaturesHeader text description
amy-corson-ibigroup Sep 9, 2024
992d76a
update snapshots
amy-corson-ibigroup Sep 9, 2024
0c62fb1
fix(map-popup): fix type error in stories
amy-corson-ibigroup Sep 9, 2024
6380c4c
update internal deps
amy-corson-ibigroup Sep 10, 2024
8b1259f
Merge branch 'master' into reorder-other-to-first
amy-corson-ibigroup Sep 10, 2024
6c0293a
Merge branch 'master' into reorder-other-to-first
amy-corson-ibigroup Sep 10, 2024
8ee7f11
update yarn.lock
amy-corson-ibigroup Sep 10, 2024
b83918d
Merge branch 'reorder-other-to-first' of https://github.com/ibi-group…
amy-corson-ibigroup Sep 10, 2024
6443942
Merge branch 'master' into reorder-other-to-first
amy-corson-ibigroup Sep 10, 2024
d19c297
Update yarn.lock
amy-corson-ibigroup Sep 10, 2024
048c899
Add a11yOverrideParams
amy-corson-ibigroup Sep 10, 2024
03c02ac
Change configuration from boolean to other first, instead to array of…
amy-corson-ibigroup Sep 30, 2024
5f30a19
Cleanup
amy-corson-ibigroup Oct 2, 2024
39cc6e7
change key to title
amy-corson-ibigroup Oct 2, 2024
e2b352e
Add GeocoderResultsConstants and clean up results headers
amy-corson-ibigroup Oct 3, 2024
2e7b01b
refactor: better incooperate GeocoderResultsConstants
amy-corson-ibigroup Oct 4, 2024
fd64616
clean up comments and capitalization
amy-corson-ibigroup Oct 14, 2024
fa7dadb
only render features if there are features
amy-corson-ibigroup Oct 24, 2024
1508e95
update snapshots
amy-corson-ibigroup Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions packages/location-field/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const LocationField = ({
onTextInputClick = null,
operatorIconMap = {},
preferredLayers = [],
renderOtherFirst = false,
sessionOptionIcon = <Search size={ICON_SIZE} />,
sessionSearches = [],
showClearButton = true,
Expand Down Expand Up @@ -644,8 +645,25 @@ const LocationField = ({
const transitFeaturesPresent =
stopFeatures.length > 0 || stationFeatures.length > 0;

const OtherFeaturesHeader = () => (
<S.MenuGroupHeader as={headingType} bgColor="#333" key="other-header">
<FormattedMessage
description="Text for header above the 'other' category of geocoder results"
id="otpUi.LocationField.other"
/>
</S.MenuGroupHeader>
);

const otherFeaturesElements = otherFeatures.map(feature =>
renderFeature(itemIndex++, feature)
);

// Iterate through the geocoder results
menuItems = menuItems.concat(
renderOtherFirst &&
transitFeaturesPresent &&
otherFeatures.length > 0 && <OtherFeaturesHeader />,
renderOtherFirst && otherFeaturesElements,
stationFeatures.length > 0 && (
<S.MenuGroupHeader
as={headingType}
Expand Down Expand Up @@ -673,16 +691,10 @@ const LocationField = ({
</S.MenuGroupHeader>
),
stopFeatures.map(feature => renderFeature(itemIndex++, feature)),

transitFeaturesPresent && otherFeatures.length > 0 && (
<S.MenuGroupHeader as={headingType} bgColor="#333" key="other-header">
<FormattedMessage
description="Text for header above the 'other'"
id="otpUi.LocationField.other"
/>
</S.MenuGroupHeader>
),
otherFeatures.map(feature => renderFeature(itemIndex++, feature))
!renderOtherFirst &&
transitFeaturesPresent &&
otherFeatures.length > 0 && <OtherFeaturesHeader />,
!renderOtherFirst && otherFeaturesElements
);
}

Expand Down
34 changes: 33 additions & 1 deletion packages/location-field/src/stories/Desktop.story.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import { ComponentMeta } from "@storybook/react";

import { Ship } from "@styled-icons/fa-solid/Ship";
Expand Down Expand Up @@ -251,3 +251,35 @@ export const WithUserSettings = (): JSX.Element => (
userLocationsAndRecentPlaces={userLocationsAndRecentPlaces}
/>
);

export const WithOtherFirst = (): JSX.Element => {
const [otherControl, setOtherControl] = useState(false);
return (
<>
<label htmlFor="other-input">
renderOtherFirst?
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.

<input
id="other-input"
type="checkbox"
checked={otherControl}
onChange={() => setOtherControl(!otherControl)}
/>
</label>
<LocationField
currentPosition={currentPosition}
geocoderConfig={geocoderConfig}
getCurrentPosition={getCurrentPosition}
preferredLayers={["example_layer"]}
initialSearchResults={mockedGeocoderResponse.features}
inputPlaceholder="Select from location"
layerColorMap={layerColorMap}
locationType="from"
onLocationSelected={onLocationSelected}
renderOtherFirst={otherControl}
sortByDistance
style={{ fontFamily: "sans-serif" }}
/>
</>
);
};
WithOtherFirst.parameters = a11yOverrideParameters;
Loading
Loading