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

fix: Workflows - Street doesn't get automatically filled out for a specific address. #55996

Merged
merged 5 commits into from
Feb 3, 2025
Merged
Changes from 3 commits
Commits
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
10 changes: 8 additions & 2 deletions src/components/AddressSearch/index.tsx
Original file line number Diff line number Diff line change
@@ -162,15 +162,21 @@ function AddressSearch(

// Make sure that the order of keys remains such that the country is always set above the state.
// Refer to https://github.com/Expensify/App/issues/15633 for more information.
const {country: countryFallbackLongName = '', state: stateAutoCompleteFallback = '', city: cityAutocompleteFallback = ''} = getPlaceAutocompleteTerms(autocompleteData?.terms ?? []);
const {
country: countryFallbackLongName = '',
state: stateAutoCompleteFallback = '',
city: cityAutocompleteFallback = '',
street: streetAutocompleteFallback,
Copy link
Collaborator

@mananjadhav mananjadhav Jan 30, 2025

Choose a reason for hiding this comment

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

Any reason we shouldn't be setting the default value for the fallback here and the next line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No reason for that, I just added default value.

streetNumber: streetNumberAutocompleteFallback,
} = getPlaceAutocompleteTerms(autocompleteData?.terms ?? []);

const countryFallback = Object.keys(CONST.ALL_COUNTRIES).find((country) => country === countryFallbackLongName);

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const country = countryPrimary || countryFallback || '';

const values = {
street: `${streetNumber} ${streetName}`.trim(),
street: `${streetNumber || streetNumberAutocompleteFallback} ${streetName || streetAutocompleteFallback}`.trim(),
name: details.name ?? '',
// Autocomplete returns any additional valid address fragments (e.g. Apt #) as subpremise.
street2: subpremise,
4 changes: 2 additions & 2 deletions src/libs/GooglePlacesUtils.ts
Original file line number Diff line number Diff line change
@@ -33,15 +33,15 @@ function getAddressComponents(addressComponents: AddressComponent[], fieldsToExt
}

type AddressTerm = {value: string};
type GetPlaceAutocompleteTermsResultKey = 'country' | 'state' | 'city' | 'street';
type GetPlaceAutocompleteTermsResultKey = 'country' | 'state' | 'city' | 'street' | 'streetNumber';
type GetPlaceAutocompleteTermsResult = Partial<Record<GetPlaceAutocompleteTermsResultKey, string>>;

/**
* Finds an address term by type, and returns the value associated to key. Note that each term in the address must
* conform to the following ORDER: <street, city, state, country>
*/
function getPlaceAutocompleteTerms(addressTerms: AddressTerm[]): GetPlaceAutocompleteTermsResult {
const fieldsToExtract: GetPlaceAutocompleteTermsResultKey[] = ['country', 'state', 'city', 'street'];
const fieldsToExtract: GetPlaceAutocompleteTermsResultKey[] = ['country', 'state', 'city', 'street', 'streetNumber'];
const result: GetPlaceAutocompleteTermsResult = {};
fieldsToExtract.forEach((fieldToExtract, index) => {
const fieldTermIndex = addressTerms.length - (index + 1);
1 change: 1 addition & 0 deletions tests/unit/GooglePlacesUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@ describe('GooglePlacesUtilsTest', () => {
state: 'Bangladesh Border Road',
city: '',
street: '',
streetNumber: '',
});
});
});