Skip to content

LG-7720: IPP: PO Search SWR refactor and enhancements#7468

Merged
allthesignals merged 18 commits intomainfrom
wmg/7720-swr-integration
Dec 15, 2022
Merged

LG-7720: IPP: PO Search SWR refactor and enhancements#7468
allthesignals merged 18 commits intomainfrom
wmg/7720-swr-integration

Conversation

@allthesignals
Copy link
Contributor

@allthesignals allthesignals commented Dec 11, 2022

🎫 Ticket

Link to the relevant ticket.

🛠 Summary of changes

Refactors much of the in-person-location component by:

  1. Splitting out the locations view log
  2. Implementing SWR to simplify state management

Feature work:

  1. Avoid firing request on load

👀 Screenshots

If relevant, include a screenshot or screen capture of the changes.

Before:

Initial load, blank page:

Screen Shot 2022-12-13 at 8 13 15 PM

No results found (locally):

Screen Shot 2022-12-13 at 8 13 20 PM
After:

Initial load (shows pilots):
image

No results found (in dev env):
image

@allthesignals allthesignals changed the title Wmg/7720 swr integration IPP: PO Search SWR refactor and enhancements Dec 11, 2022
@allthesignals
Copy link
Contributor Author

A lot of tension here around naming... switching around between: 1) In-Person-Locations to 2) PostOffices to 2) UspsLocations?

Most naming is some format of "In-Person Location" or some derivation of In-Person Proofing... so let's go with that? Although "Post Office" is most accurate, it's a specific kind of Post Office, one that performs ID proofing...

@allthesignals
Copy link
Contributor Author

This Step component is more like an "InPersonLocationSelectionStep" rather than

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Location should be renamed too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like the wrong name... it's in Address form before it becomes a query for in person locations...

@allthesignals allthesignals requested review from a team and NavaTim December 12, 2022 23:23
@allthesignals
Copy link
Contributor Author

A little confused by this failure:

$ is-es5-safe 'public/packs?(-test)/js/*.js'
public/packs/js/39-c364e100.js SyntaxError: The keyword 'const' is reserved (2:135043)
    at Parser.pp$4.raise (/builds/lg/identity-idp/app/javascript/packages/es5-safe/node_modules/acorn/dist/acorn.js:2825:15)
    at Parser.pp$3.checkUnreserved (/builds/lg/identity-idp/app/javascript/packages/es5-safe/node_modules/acorn/dist/acorn.js:2752:12)
    at Parser.pp$3.parseIdent (/builds/lg/identity-idp/app/javascript/packages/es5-safe/node_modules/acorn/dist/acorn.js:2781:12)
    at Parser.pp$3.parseExprAtom (/builds/lg/identity-idp/app/javascript/packages/es5-safe/node_modules/acorn/dist/acorn.js:2198:21)
    at Parser.pp$3.parseExprSubscripts (/builds/lg/identity-idp/app/javascript/packages/es5-safe/node_modules/acorn/dist/acorn.js:2089:21)
    at Parser.pp$3.parseMaybeUnary (/builds/lg/identity-idp/app/javascript/packages/es5-safe/node_modules/acorn/dist/acorn.js:2066:19)
    at Parser.pp$3.parseExprOps (/builds/lg/identity-idp/app/javascript/packages/es5-safe/node_modules/acorn/dist/acorn.js:2010:21)
    at Parser.pp$3.parseMaybeConditional (/builds/lg/identity-idp/app/javascript/packages/es5-safe/node_modules/acorn/dist/acorn.js:1993:21)
    at Parser.pp$3.parseMaybeAssign (/builds/lg/identity-idp/app/javascript/packages/es5-safe/node_modules/acorn/dist/acorn.js:1968:21)
    at Parser.pp$3.parseExpression (/builds/lg/identity-idp/app/javascript/packages/es5-safe/node_modules/acorn/dist/acorn.js:1933:21) {
  pos: 135112,
  loc: Position { line: 2, column: 135043 },
  raisedAt: 135119
}
error Command failed with exit code 1.

It's a lint step...

Further: we need to duplicate/modify the IPP Rails test to get the full coverage needed (I think?)

Copy link
Contributor

@NavaTim NavaTim left a comment

Choose a reason for hiding this comment

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

Would you post desktop/mobile screenshots or an animated GIF to compare w/ the mockup?

@NavaTim
Copy link
Contributor

NavaTim commented Dec 13, 2022

$ is-es5-safe 'public/packs?(-test)/js/*.js'

@allthesignals Looks to me like a test for IE11 support.

A lot of tension here around naming... switching around between: 1) In-Person-Locations to 2) PostOffices to 2) UspsLocations?

Yeah, makes sense to consolidate the naming.

@aduth
Copy link
Contributor

aduth commented Dec 13, 2022

A little confused by this failure:

That check is to help prevent the introduction of non-IE11-compatible JavaScript. It's flagging const as being ES6 that would not run in IE11†. My guess is that swr may not explicitly support IE11.

At least for the syntax, we can add the package to our existing allowlist of dependencies to be processed by Babel.

I would also want to either test or check explicit support guarantees to see whether IE11 will work with it, in case it's relying on some other newer features.

FWIW, IE11 support will conclude at the end of the month, so it may not be an issue starting in January.


Technically, const itself is compatible, though I'd suspect there's other syntax which would not be.

@allthesignals
Copy link
Contributor Author

A little confused by this failure:

That check is to help prevent the introduction of non-IE11-compatible JavaScript. It's flagging const as being ES6 that would not run in IE11†. My guess is that swr may not explicitly support IE11.

At least for the syntax, we can add the package to our existing allowlist of dependencies to be processed by Babel.

I would also want to either test or check explicit support guarantees to see whether IE11 will work with it, in case it's relying on some other newer features.

FWIW, IE11 support will conclude at the end of the month, so it may not be an issue starting in January.

Technically, const itself is compatible, though I'd suspect there's other syntax which would not be.

I see. Diff might be:
/node_modules\/(?!@18f\/identity-|identity-style-guide|uswds|receptor|elem-dataset|swr)/,

@allthesignals allthesignals force-pushed the wmg/7720-swr-integration branch from 1082f35 to 9f7a41c Compare December 14, 2022 01:01
return;
}
const addressCandidates = await request(ADDRESS_SEARCH_URL, {
const addressCandidates = await request<Location>(ADDRESS_SEARCH_URL, {
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 changed the request library so that responses need to be typed

Comment on lines +71 to +74
<>
<br />
{addressQuery.address}
</>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Todo: implement copy!

Copy link
Contributor

Choose a reason for hiding this comment

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

Todo: implement copy!

Just to clarify, are you planning to do that here, or in a follow-up pull request?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aduth this one, just added.

Comment on lines 59 to 64
const transformKeys = (location: object, predicate = snakeCase) => {
const sendObject = {};
Object.keys(location).forEach((key) => {
sendObject[snakeCase(key)] = location[key];
sendObject[predicate(key)] = location[key];
});
return sendObject;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactor here improves the naming a bit so it's more generic

Comment on lines +67 to +74
const requestUspsLocations = async (address: LocationQuery): Promise<FormattedLocation[]> => {
const response = await request<PostOffice[]>(LOCATIONS_URL, {
method: 'post',
json: { address: transformKeys(address) },
});

return formatLocation(response);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an extraction of "fetcher" logic from the previous hook for useEffect. This follows the pattern for SWR.

Comment on lines -106 to +100
const selectedLocation = locationData[id];
const selectedLocation = locationResults![id]!;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not great because locationResults can potentially be null!

@allthesignals
Copy link
Contributor Author

Hey @NavaTim — I've shortened this PR a little bit so that it's doing less... updating the PR description accordingly...

@allthesignals allthesignals changed the title IPP: PO Search SWR refactor and enhancements LG-7720: IPP: PO Search SWR refactor and enhancements Dec 14, 2022
city: string;
state: string;
zipCode: string;
address: string;
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 so that we can use the full address in messages

Comment on lines -205 to -206
{arcgisSearchEnabled && (
<AddressSearch onAddressFound={handleFoundAddress} registerField={registerField} />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is redundant due to this PR, so removed it.

poste américain proche.
search_button: Chercher
search_button: Rechercher
none_found:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awaiting corrected french translation here cc @kellular (lemme know if i'm wrong)

@allthesignals allthesignals force-pushed the wmg/7720-swr-integration branch from a3c6a0b to c751036 Compare December 14, 2022 15:51
Copy link
Contributor Author

Choose a reason for hiding this comment

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

CC @kellular sorry, not sure how to read the translation doc for this... sounds like we're still trying to determine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This only existed in order to display on screen

@allthesignals allthesignals force-pushed the wmg/7720-swr-integration branch from b6b02f6 to caeb20a Compare December 14, 2022 16:31
@allthesignals allthesignals requested a review from aduth December 14, 2022 16:48
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

I found this difficult to test locally since I don't have credentials for the address geocoder. Is there a ticket where we plan to stub out a fake geocoder service? I assume once this becomes more generally available in the application we'd want the flow to be minimally functional for a default application configuration.

Copy link
Contributor

@NavaTim NavaTim left a comment

Choose a reason for hiding this comment

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

The screenshots differ significantly from the mockup, particularly the bolded result text and the address showing after the button. Was the latter temporary?

address_search_hint: 'Exemple : 1960 W Chelsea Ave Allentown PA 18104'
address_search_label: Entrez une adresse pour trouver un bureau de poste près de chez vous.
none_found:
none_found: Placeholder %{address}
Copy link
Contributor

Choose a reason for hiding this comment

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

Best to actually translate this before merging (or mark as draft for now) since this is what a user would see in production.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess if there's an outstanding story it may be fine since this is behind a FF.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me do some cleanup on the screenshots and styling. Thanks for checking that. One of those screenshots shows intermediate progress on this and needs updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated screenshots.

@allthesignals
Copy link
Contributor Author

I found this difficult to test locally since I don't have credentials for the address geocoder. Is there a ticket where we plan to stub out a fake geocoder service? I assume once this becomes more generally available in the application we'd want the flow to be minimally functional for a default application configuration.

Ticket created.

@allthesignals allthesignals merged commit d5aeb2a into main Dec 15, 2022
@allthesignals allthesignals deleted the wmg/7720-swr-integration branch December 15, 2022 19:07
@aduth aduth mentioned this pull request Dec 19, 2022
@aduth aduth mentioned this pull request Sep 11, 2023
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.

3 participants