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

Fix collaborators modal (add + delete editors) #3058

Merged
merged 2 commits into from
Mar 9, 2023

Conversation

rbennettcw
Copy link
Contributor

@rbennettcw rbennettcw commented Mar 8, 2023

Fixes issue where the thread collaborators modal did not properly add editors. Also ensures that it can properly delete editors.

Link to Issue

Closes: #3008

Description of Changes

  • Updates the request body shape in addEditor and deleteEditor endpoints
  • Updates the collaborators modal UI to send a properly shaped request body
  • Updates the collaborators modal UI to update the UI after collaborators have been updated

Test Plan

  • Create a thread
  • Add a collaborator, confirm that the UI is updated to show the new collaborator
  • Remove the collaborator, confirm that the UI is updated to show no collaborators

Deployment Plan

N/A

Other Considerations

I noticed that when updating partial state, there are instances of mutating the state directly like this:

thread.foo = 'bar';
setThread(thread);

It's generally not good practice to mutate state directly, but since Thread is a class and not a plain object, we can't use the spread operator. As a result, we'll need to continue applying the mutation pattern. Just an FYI though I'm sure we all know this already.

@jnaviask jnaviask added the React label Mar 9, 2023
@jnaviask jnaviask linked an issue Mar 9, 2023 that may be closed by this pull request
Comment on lines +745 to +746
thread.collaborators = newEditors;
setThread(thread);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not good. We are now in the transition between handling global state from mithrill world and handling local react state. This mixes two approaches but we should strive to follow react approach. In this case this would be the approach which hopefully works:

const newThread = {...thread, collaborators: newEditors};
setThread(newThread)

Copy link
Contributor

@masvelio masvelio left a comment

Choose a reason for hiding this comment

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

We should definitely move away from mutating => this is a legacy and we cant write new code in the legacy approach. Other than that, looks great!

@rbennettcw rbennettcw merged commit adf647f into react Mar 9, 2023
@rbennettcw rbennettcw deleted the ryan.fix-collaborators-modal branch March 9, 2023 16:55
@rbennettcw rbennettcw restored the ryan.fix-collaborators-modal branch March 9, 2023 16:58
rbennettcw added a commit that referenced this pull request Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix addEditors Route so edit collaborators modal works as expected
3 participants