Prevent deletion of the last mod component in a mod and enforce editor slice invariants
What does this PR do?
- :bug: The
DeleteandMove from modmod component actions are now disabled for the last mod component in a mod. This avoids the bug where a mod "disappears" when you remove the last component for the mod- If we wanted to allow "Move from mod" we could show a confirmation modal that continuing will deactivate the mod. (We'd have to deactivate to handle the case where it's an activated mod with a single mod component)
- Adds
editorInvariantMiddlewareinDEBUGmode to verify that invariant. 😱 TheselectGetCleanComponentsAndDirtyFormStatesForModincluded deleted states inmodComponentFormStatesin the test setup - Editor slice refactoring/cleanup:
- Drops redundant
selectNotDeletedModComponentFormStatesselector. It will always just be the mod component form states, because deleted form states are placed ondeletedModComponentFormStatesByModId - Drops
selectFirstModComponentFormStateForActiveModbecause it was only being used to calculate dirty mod metadata and there's already a selector for that purpose - Moves editor slice helpers that are only used in 1 place back into the slice for readability
- Re-use selectors in
createSelectordefinition where possible - Modify selectors to require mod id vs. producing an empty value when mod id is null
- Drops redundant
Reviewer Notes
- The thing I'm most unsure about is whether the invariant between
deletedModComponentFormStatesByModIdandmodComponentFormStatesactually held as expected in the past or if there are invalid persisted editor slice states in the wild
For more information on our expectations for the PR process, see the code review principles doc
Playwright test results
144 passed
2 skipped
Details
Open report ↗︎
146 tests across 47 suites
9 minutes, 23 seconds
6088392
For more information on how to debug and view this report, see our readme
Skipped tests
chrome › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options msedge › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options
Codecov Report
Attention: Patch coverage is 83.91608% with 23 lines in your changes missing coverage. Please review.
Project coverage is 75.30%. Comparing base (
8318d74) to head (6088392). Report is 428 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #9360 +/- ##
==========================================
+ Coverage 74.24% 75.30% +1.06%
==========================================
Files 1332 1374 +42
Lines 40817 41873 +1056
Branches 7634 7766 +132
==========================================
+ Hits 30306 31534 +1228
+ Misses 10511 10339 -172
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.
Do not edit this comment manually.
If we wanted to allow "Move from mod" we could show a confirmation modal that continuing will deactivate the mod. (We'd have to deactivate to handle the case where it's an activated mod with a single mod component)
If it's an activated mod, we should delete the mod (and tell the user that continuing will deactivate and delete the mod).
I think we also want to allow moving from unsaved mods regardless (just make sure we clear any weird leftover state). I can see developers not realizing they need to use the mod menu to add a second mod component and instead using new mod + move from mod
If it's an activated mod, we should delete the mod (and tell the user that continuing will deactivate and delete the mod). I think we also want to allow moving from unsaved mods regardless (just make sure we clear any weird leftover state). I can see developers not realizing they need to use the mod menu to add a second mod component and instead using new mod + move from mod
I agree with both of these. My main concern is the corner case where the user might lose their work if they had updated the mod metadata. So I'd generally be in favor of the confirmation modal