Page MenuHomePhabricator

[web] Move `onChangeName` up from `ThreadSettingsModal` to `ConnectedThreadSettingsModal`
ClosedPublic

Authored by atul on Apr 18 2022, 2:34 PM.
Tags
None
Referenced Files
F3174402: D3765.id11741.diff
Thu, Nov 7, 4:32 PM
F3173329: D3765.id11574.diff
Thu, Nov 7, 3:11 PM
F3173277: D3765.id11646.diff
Thu, Nov 7, 3:03 PM
Unknown Object (File)
Tue, Nov 5, 5:19 AM
Unknown Object (File)
Sun, Nov 3, 6:04 PM
Unknown Object (File)
Sun, Nov 3, 6:03 PM
Unknown Object (File)
Wed, Oct 23, 8:44 PM
Unknown Object (File)
Sun, Oct 20, 7:21 PM

Details

Summary

Move onChangeName out from inner class component to outer "Connected" functional component.

As part of the work to refactor ThreadSettingsModal... specifically to turn it into a functional component.


Depends on D3764

Test Plan
  1. Open ThreadSettingsModal
  2. Change the thread name a bunch
  3. Log values in onChangeName to ensure that they continue to be as expected

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

atul requested review of this revision.Apr 18 2022, 2:39 PM
web/modals/threads/thread-settings-modal.react.js
438 ↗(On Diff #11574)

Is this invariant for testing purposes? It looks like we handle the case when threadInfo is null or undefined on line 450.

web/modals/threads/thread-settings-modal.react.js
438 ↗(On Diff #11574)

invariant is always for Flow. @atul is using it here so that Flow won't complain when he dereferences threadInfo.name. Flow doesn't realize that there's no way for onChangeName to be called when threadInfo is falsey, so @atul explicitly annotates this to Flow using invariant

tomek requested changes to this revision.Apr 21 2022, 3:04 AM
tomek added inline comments.
web/modals/threads/thread-settings-modal.react.js
444–450

Do we really need an invariant here? When threadInfo.name is not present, we have undefined... maybe we can do the same when threadInfo is not present? Additional benefit would be that the callback will depend on threadInfo?.name instead of the whole threadInfo.

This revision now requires changes to proceed.Apr 21 2022, 3:04 AM
atul planned changes to this revision.Apr 21 2022, 9:09 AM
atul added inline comments.
web/modals/threads/thread-settings-modal.react.js
444–450

I think if the onChangeName callback were to stay here it would make sense, but it's going to be pushed down to the ThreadSettingsGeneral tab where existence of threadInfo is guaranteed.

With either the invariant or the optional chaining we'll need to revert after pushing the functionality down, and the invariant seems like an easier thing to find and revert?

Still open to making the change to optional chaining though

atul requested review of this revision.Apr 21 2022, 9:10 AM
tomek added inline comments.
web/modals/threads/thread-settings-modal.react.js
444–450

Ok, so up to you.

My preference is to avoid invariants and use them only when there's no other way. We're going to move this code, so when pasting, we will read it and verify that it's correct - so searching shouldn't be needed, I guess. But as I said, up to you.

If you prefer keeping the invariant, we can have threadInfo?.name in it, so that the dependencies are as narrow as possible.

This revision is now accepted and ready to land.Apr 21 2022, 9:44 AM

address feedback: remove invariant and use optional chaining

Object.freeze() for consistency