Page MenuHomePhabricator

[lib] Support pending threads in `URLInfo` calculation
ClosedPublic

Authored by jacek on Jul 5 2022, 4:30 AM.
Tags
None
Referenced Files
F3359971: D4443.id14744.diff
Sun, Nov 24, 11:47 AM
Unknown Object (File)
Tue, Nov 12, 1:08 AM
Unknown Object (File)
Tue, Nov 12, 1:08 AM
Unknown Object (File)
Tue, Nov 12, 1:08 AM
Unknown Object (File)
Tue, Nov 12, 1:08 AM
Unknown Object (File)
Tue, Nov 12, 1:08 AM
Unknown Object (File)
Tue, Nov 12, 1:08 AM
Unknown Object (File)
Fri, Nov 8, 3:02 PM

Details

Summary

Introduce support for calculating URL info for pending threads, as currently it could only parse URLs containing thread/<numbers>.
Because pending threads can have different forms of IDs, I added regular expression that recongnizes pending threads and correctly identifies pending ID returning it in URLInfo.

Test Plan

Tested manually by refreshing page in different pending threads (after introducing modifications in next diffs, it doesn't work now because of no mechanism for pending threads creation in nav reducer as for now).
Tested automatically with different examples using: https://regexr.com/6q7os

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

lib/shared/thread-utils.js
272 ↗(On Diff #14174)

I'm a bit confused what "locally unique" means. It seems like this is just a RegExp for a pending threadID?

lib/shared/thread-utils.js
260 ↗(On Diff #14174)

Oh, I guess that term started here. Looks like D2294 has some relevant context, but to be honest I'm having trouble recalling the reason we had for using this term instead of something simple like "pending". Can you help remind me?

Looks good, but not experienced w/ regex so probably good for someone else to take a look.. adding @ashoat as blocking

lib/shared/thread-utils.js
273 ↗(On Diff #14174)

should we be escape some of the special characters in this?

(I have minimum experience with regex, so take with grain of salt)

This revision is now accepted and ready to land.Jul 6 2022, 9:26 AM
This revision now requires review to proceed.Jul 6 2022, 9:26 AM
lib/shared/thread-utils.js
273 ↗(On Diff #14174)

I don't think it's necessary, since the RegExp object automatically escapes slashes:

image.png (1×1 px, 115 KB)

However, I do it since I think it's considered good style/practice. Also Regxr complains:
image.png (2×1 px, 440 KB)

ashoat requested changes to this revision.Jul 6 2022, 9:58 AM

Based on @yayabosh's analysis, it might be good to add the escapes, but I'm not 100% sure

lib/shared/thread-utils.js
260 ↗(On Diff #14174)

Requesting changes for a response to my question

This revision now requires changes to proceed.Jul 6 2022, 9:58 AM
lib/shared/thread-utils.js
273 ↗(On Diff #14174)

Yes, you are right. I also did the escapes at first. However, both eslint and prettier complained about escaping characters:

Screenshot_Code_2022-07-08_084203@2x.png (292×1 px, 80 KB)

So I followed the suggested version without escapes.

lib/shared/thread-utils.js
260 ↗(On Diff #14174)

Yes, I also needed to recall what was the reason why the name was changed.
The reason seems to be described with details here: https://www.notion.so/commapp/InlineSidebar-doesn-t-appear-for-sidebar-promoted-to-subthread-6d7b6970a5594987a0f28e719f563e4c

If I understand correctly, we just wanted to use this function (inside locallyUniqueToRealizedThreadIDsSelector) to calculate "pending names" also for thread types that in app never can exist pending state (like subthreads). As a result, we concluded that the name getPendingThreadID doesn't cover this case.

Looking at the code now, I suppose keeping using pendingThreadID instead of LocallyUniqueThreadID would have made the code more readable.

lib/shared/thread-utils.js
273 ↗(On Diff #14174)

Hey @jacek, I've included a video here showing how to attach images to Phabricator now because they changed some permissions. Now, whenever copying and pasting an image in or uploading an image through the file upload system, you have to manually grant permissions for everyone else to be able to see the image. That is why currently I cannot see the image you attached.

image.png (950×2 px, 305 KB)

abosh added inline comments.
lib/shared/thread-utils.js
273 ↗(On Diff #14174)

Looking at the code now, I suppose keeping using pendingThreadID instead of LocallyUniqueThreadID would have made the code more readable.

Awesome – what do you think the best way to follow up is? Maybe we should create a separate Linear task for it, since it seems like this change will touch a lot of files.

ashoat added 1 blocking reviewer(s): abosh.

Accepting, but please make sure to create a Linear task for the naming follow-up before landing!! Adding @yayabosh as blocking to make sure the RegExp escape question gets resolved, but seems like if ESLint / Prettier don't want the escapes we can leave them out

Adding @yayabosh as blocking to make sure the RegExp escape question gets resolved, but seems like if ESLint / Prettier don't want the escapes we can leave them out

Yup, I agree with this assessment. I defer to ESLint / Prettier, and also JavaScript seems to automatically add escaping characters based on playing around with the console.

This revision is now accepted and ready to land.Jul 10 2022, 10:16 AM

Looking at the code now, I suppose keeping using pendingThreadID instead of LocallyUniqueThreadID would have made the code more readable.

Awesome – what do you think the best way to follow up is? Maybe we should create a separate Linear task for it, since it seems like this change will touch a lot of files.

I created the rename task: https://linear.app/comm/issue/ENG-1374/rename-locallyuniquethreadid-to-pendingthreadid

lib/shared/thread-utils.js
273 ↗(On Diff #14174)

Oh, I didn't know that. Thanks a lot for the info!

tomek added inline comments.
lib/shared/thread-utils.js
273 ↗(On Diff #14174)

Not sure how closely we would like this regex to match our logic, but currently something like pending/type0/++++ is valid

lib/utils/url-utils.js
60 ↗(On Diff #14174)

Maybe add a comment near the regex definition telling that we're using groups and any change to the regex would require updating this logic?

lib/utils/url-utils.js
60 ↗(On Diff #14174)

Good idea!

add comment in code as Tomek suggested

Updated the Regex to prevent empty IDs between '+' chars.

jacek added inline comments.
lib/shared/thread-utils.js
273 ↗(On Diff #14744)

Basing on https://phab.comm.dev/D4446#inline-28924 i changed the regex so it doesn't support URLs like pending/type6/123+++1.

I don't know if there is any better way, but double escape "...\\+..." was the only solution I found, that makes the regex to work properly

Defer to @tomek on the RegEx

lib/shared/thread-utils.js
273 ↗(On Diff #14744)

It is strange that in the earlier regex we didn't need to escape the + - pending/(type[0-9]+/[0-9+]+|sidebar/[0-9]+) (it was a part of range [0-9+]) but now we have to. But if escaping works fine, we can use it.

This revision is now accepted and ready to land.Jul 22 2022, 1:29 AM