LG-8407: PO Search: search button shows loading state#7502
LG-8407: PO Search: search button shows loading state#7502allthesignals merged 10 commits intomainfrom
Conversation
… in address-search
aduth
left a comment
There was a problem hiding this comment.
LGTM 👍
It'd be nice to have some spec coverage for these components so that we can be more confident in these refactors.
…arch.tsx Co-authored-by: Andrew Duthie <andrew.duthie@gsa.gov>
| expect(requester.request).to.have.been.called(); | ||
| }); | ||
|
|
||
| it('fires the callback with correct input', async () => { |
There was a problem hiding this comment.
This makes me reconsider how opinionated this component should be about the return value... I don't think it's appropriate for it only return the best match, and maybe that should be dealt with on the consumer side. This component should return all results.
app/javascript/packages/document-capture/components/address-search.spec.tsx
Show resolved
Hide resolved
|
Failure likely due to leakiness in stubbing... |
| registerField: (field: string) => Ref<HTMLInputElement>; | ||
| registerField?: (field: string) => Ref<HTMLInputElement> | undefined; |
There was a problem hiding this comment.
Dunno if you deleted a comment, but I arrived here from an email notification about this type assignment. I think it might be better to defer the type to how it's defined by @18f/identity-form-steps:
import type { RegisterFieldCallback } from '@18f/identity-form-steps';
interface AddressSearchProps {
// ...
registerField?: RegisterFieldCallback;
}There was a problem hiding this comment.
(It was your comment at #7502 (comment), maybe the GitHub UI was being slow to update)
There was a problem hiding this comment.
Yeah I was interested in the difference between void and undefined, and thought they were interchangeable in TS but was wrong!
This change was made so that i could test without need to deal with the validated field provider stuff.
|
I think in order to use MSW, we'll need to rewrite some of these |
|
Sloppy workaround pushed |
There was a problem hiding this comment.
Real fetch is needed for this, but changing that in the spec_helper breaks other tests
There was a problem hiding this comment.
The useDefineProperty helper may have helped for the approach we ended up taking, as an alternative to duplicating the restored original fetch. Or something like...
let originalFetch;
before(() => {
originalFetch = window.fetch;
window.fetch = fetch;
});
after(() => {
window.fetch = originalFetch;
});But hopefully we can get native fetch working so we won't need this anyways.
80c333d to
c36ab8b
Compare
🎫 Ticket
Link to the relevant ticket.
🛠 Summary of changes
I used
<SpinnerButton/>in place of<Button/>in order to show loading state to the user.I also swapped in usage of useSWR for more declarative component style.
Note: the button only shows loading when the app is looking up an address. It does not continue to show loading when the second trip is made to query for PO locations.
^ Open to suggestions on how to organize things so that loading continues into the second request... one way is to provide the
toggleSpinnerin theonAddressFoundcallback, and call it when appropriate from the consuming end...📜 Testing Plan
Provide a checklist of steps to confirm the changes.
👀 Screenshots
If relevant, include a screenshot or screen capture of the changes.
Before:
After: