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

Refactor CustomListEditor and related components. #31

Merged
merged 2 commits into from
Aug 3, 2022

Conversation

ray-lee
Copy link
Contributor

@ray-lee ray-lee commented Jul 21, 2022

Description

This refactors the CustomListEditor, CustomListEntriesEditor, and CustomListSearch components to:

  • Make them stateless.†
  • Remove data manipulation functions that are better implemented outside of the view layer.

The state that was being kept by these components is now lifted up into the Redux store. Several new action creators have been added to represent the actions users can perform on the custom list editor form. A new customListEditor reducer handles these actions, and updates the state accordingly. The view components are now pure functions that accept props (pulled from the Redux state), and return a rendered DOM.

† There is still one tiny bit of state in CustomListEntriesEditor, the source of a drag while a drag-and-drop is in progress. This can be moved later, if we ever need to generalize drag-and-drop.

This presentation contains an overview of the refactoring: https://docs.google.com/presentation/d/1v-0KdPXHT_fe6suydnUhTeY_NrVFt_lYqFLbPEH9JZc

Motivation and Context

This greatly simplifies the view components, makes them more testable, and reduces the chance of introducing bugs. It was originally motivated by trying to fix the Save and Cancel buttons being enabled before any changes to a list had been made (https://www.notion.so/lyrasis/Custom-List-Manager-has-active-Save-Cancel-buttons-before-anything-has-been-changed-06ae75f1e064469da0e70bd662396059). This was caused by a confusing interaction between the props and state of CustomListEditor. Refactoring these components to remove state allows us to fix this issue, and makes it easier to add new features.

Notion: https://www.notion.so/lyrasis/Refactor-list-editing-components-to-be-stateless-1e9dbc5af08643b99867d4bdabdcb536

How Has This Been Tested?

Checklist:

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@ray-lee ray-lee requested a review from a team July 21, 2022 19:00
@ray-lee ray-lee marked this pull request as ready for review July 21, 2022 19:00
Copy link
Contributor

@dbernstein dbernstein left a comment

Choose a reason for hiding this comment

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

@ray-lee: very impressive work. It looks good to me, but I must admit I am not familiar with React.

@ray-lee ray-lee merged commit 4a13d53 into main Aug 3, 2022
@ray-lee ray-lee deleted the refactor-list-editor branch August 3, 2022 02:23
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.

2 participants