Enable list save button when a collection is selected. #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Previously, when editing a list, the save button was only enabled when a book was added from a search. Now, the save button is enabled when either a source collection is selected, or a book is added from a search.
The logic to determine if the save button should be enabled didn't really make sense to me -- possibly some stuff was left over from older versions, and isn't relevant now -- so I rewrote it to be much simpler.
When writing new tests, I ran into some places where there were missing null checks on variables, so I fixed those.
Note: I don't like the implementation of the list editing component. It has a lot of internal state that makes it very hard to test without directly setting the state in tests, which breaks the encapsulation. I don't have time to refactor the component to be stateless now, but I'd like to in the future.
Motivation and Context
The implementation team sometimes needs to create lists that automatically add from collections, and do not specify any additional books from a search. This is a valid way to create a list, but the admin UI doesn't allow the list to be saved without having any books added from a search.
Notion: https://www.notion.so/lyrasis/Cannot-save-a-list-without-an-item-in-it-on-Collection-Manager-665bc3d28d9c451ba778ff0558f81133
How Has This Been Tested?
The save button should be disabled.
The save button should be disabled.
The save button should be enabled.
The save button should be disabled.
The save button should be enabled.
The save button should be enabled only when there is a non-blank title, and either a collection is selected, or a book is added.
Unit tests are included.
Checklist: