Page MenuHomePhabricator

[web] Handle unsaved changes with the UnsavedChangesModal
ClosedPublic

Authored by rohan on Jul 21 2023, 9:23 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 10, 10:32 AM
Unknown Object (File)
Sat, Nov 9, 11:21 PM
Unknown Object (File)
Sat, Nov 9, 11:05 PM
Unknown Object (File)
Sat, Nov 9, 8:27 PM
Unknown Object (File)
Sat, Nov 9, 8:09 PM
Unknown Object (File)
Sat, Nov 9, 6:56 PM
Unknown Object (File)
Sat, Nov 9, 4:19 PM
Unknown Object (File)
Thu, Nov 7, 6:00 PM
Subscribers

Details

Summary

If there are any changes in the create role screen, we want to push the UnsavedChangesModal if a user tries to click "Back" or the X button on the Modal. I had to check elements individually for the rolePermissions / pendingRolePermissions array since after selecting a permission and then deselecting it, simply using a === would no longer work on the two arrays since they would not be of the same reference.

ENG-4428

Depends on D8595

Test Plan

Tested the modal to confirm that the UnsavedChangesModal appears when it should

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

rohan edited the test plan for this revision. (Show Details)
rohan requested review of this revision.Jul 21 2023, 9:47 AM

Update check to short-circuit if array lengths are different (this is to prevent a case in the edit-role flow where a role has 3 permissions and a user deselects one, every element in the the new permissions (array size 2) is still contained in the original permissions (array size 3)

atul requested changes to this revision.Jul 26 2023, 10:49 AM

Can we go with O(n) approach instead of O(n^2)?

web/roles/create-roles-modal.react.js
60–62 ↗(On Diff #28975)

The algorithm being used here is O(n^2). Could we go with something like:

const pendingSet = new Set(pendingRolePermissions);
const roleSet = new Set(rolePermissions);
if (pendingSet.size !== roleSet.size) {
    arePermissionsEqual= false;
}
for (let permission of pendingSet) {
    if (!roleSet.has(permission)) return false;
}
arePermissionsEqual = true;

which is O(n) without much more effort? Given the number of permissions at the moment it's probably fine as is, but might as well reduce the complexity right off the bat

This revision now requires changes to proceed.Jul 26 2023, 10:49 AM

Implement O(n) feedback

web/roles/create-roles-modal.react.js
60–62 ↗(On Diff #28975)

Ah yeah that's probably a better idea anyways

Sweet, thanks for updating so quickly

This revision is now accepted and ready to land.Jul 26 2023, 11:13 AM
This revision was landed with ongoing or failed builds.Jul 31 2023, 6:15 PM
This revision was automatically updated to reflect the committed changes.