yardz opened a new pull request #13497:
URL: https://github.com/apache/superset/pull/13497


   ### SUMMARY
   The DatabaseSelector component was very complex and had several 
responsibilities, in addition to developing several rerenders that were not 
necessary.
   
   #### First Step
   The first step was to separate the functions that were inside the component 
into hooks. Leaving this out we have some direct improvements:
   - Improved readability (principle of single responsibility and cleaner code)
   - Allow use of useRef to prevent unnecessary rerenders
   - Test possibility
   
   For the functions, the same structure is followed. There is a factory, which 
takes as an argument functions that will be used within the original function 
(usually the "setSomething") and returns a function with the same input and 
behavior as the original function. This factory is used to initialize a 
`useRef` and has a `useEffect` to update the refs when any prop is changed.
   This way, the component only renders again when there is a need to update 
the UI, but the functions are always with the current props and states.
   
   #### Second step
   There were still 4 components inside `DatabaseSelector`, using names like 
`renderDatabaseSelect`.
   Each of these has been separated into a single component. Facilitating 
testing, making the code cleaner, and facilitating future maintenance.
   Even by separating the components of the behavior it was maintained and the 
interface was kept as similar as possible.
   
   
   ### TEST PLAN
   No behavior change in the application. All tests must pass correctly.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to