table sources provide table options as sorted typeahead #2939
Conversation
eb32edd
to
d8bb9f3
Compare
d8bb9f3
to
4137dc3
Compare
onChange(selected[0]?.key); | ||
updateOption(opt.key, selected[0]?.key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling both react-hook-form
's onChange
and our updateOption
<Controller | ||
control={control} | ||
name={`source.options.${opt.key}`} | ||
render={({ field: { onChange } }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because Typeahead
's props aren't compatible with the props react-hook-form
's register
function returns, we need to wrap it in a Controller
with a custom render function
@@ -537,6 +551,7 @@ const Page: NextPage<Props> = ({ | |||
placeholder={opt.placeholder} | |||
name={`source.options.${opt.key}`} | |||
{...register(`source.options.${opt.key}`, { | |||
shouldUnregister: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the first few renders until we get back the connectionOptions response, it falls back to a disabled text input. This was causing problems because register by default does not unregister on unmount, so sometimes the custom onChange
function passed here stuck around and was still getting called whenever we changed the value on the typeahead. Passing shouldUnregister: true
here correctly cleans up the old onChange on unmount as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think you could write a test to test this? I feel like this is a touchy part of the codebase and could use the support.
Maybe it's worth putting this logic into its own component so it's more easily testable?
@krishnaglick separated out this react-hook-form + react-bootstrap-typeahead integration into its own component and added some tests for it. I was able to reuse it in both the Source Edit and App Edit pages- the destination edit page also has a typeahead in it, but the page doesn't use react-hook-form. We can probably move to using this component later when we go all-in react-hook-form. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really love what you did here, nice job!
Change description
Provides better experience for configuring the source when users have lots of tables in their database.
Also fixes typeaheads on the source edit page to play nicely alongside react-hook-form.
Checklists
Development
Impact
Please explain any security, performance, migration, or other impacts if relevant:
Code review