-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
composebox_typeahead: Convert module to typescript. #29783
composebox_typeahead: Convert module to typescript. #29783
Conversation
8cdf63e
to
f0bc166
Compare
Most recent push includes a bunch of changes in test files to get all node tests passing. The next thing I'll do is probably try to separate out more prep commits, and probably read over the big change to find things I can clean up or make more legible. This is a really big change. |
77992e6
to
2ad7836
Compare
2ad7836
to
3b05fbc
Compare
174acb7
to
cf43a97
Compare
web/shared/src/typeahead.ts
Outdated
@@ -44,6 +46,10 @@ type UnicodeEmoji = { | |||
emoji_code: string; | |||
reaction_type: "unicode_emoji"; | |||
is_realm_emoji: false; | |||
emoji_url?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like emoji_url
was used in this file, but it will be used by future code that uses EmojiSuggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is unlikely to be properly an optional field; either we are setting this value for every UnicodeEmoji
this file interacts with, or none of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for making this optional came from update_emoji_data
-- the type EmojiDict
has an optional url
field, and emoji_collection
which is type Emoji
is pushed an object without the emoji_url
when emoji_dict.is_realm_emoji
is `false.
I added console.log(emoji_dict.is_realm_emoji, emoji_dict.url, emoji_dict.name)
to the for loop of this function and got false undefined
for all the non-realm emoji, and this for the two realm emojis in the dev environment:
true /user_avatars/2/emoji/images/1.png green_tick
true /static/generated/emoji/images/emoji/unicode/zulip.png zulip
This confirms my understanding that what I put is the correct type given the way the code is currently set up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK there's probably something to clean up there but I'm not sure what.
2a34c60
to
831334d
Compare
|
||
type PillItem = | ||
| UserGroupPillData | ||
| UserOrMentionPillData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit torn on how to name this. I feel like they're not really pills for this typeahead, since it often just inserts text after. So I was thinking of calling them Suggestion
s. But then would it make sense to rename the types used in the pill typeahead to be Suggestion?
web/src/composebox_typeahead.ts
Outdated
const filtered_candidates = candidates; | ||
// TypeScript doesn't understand that filtering a list that is one of several times | ||
// cannot return a list of mixed types. | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed on CZO here
// TODO(evy) look into removing the delivery email check | ||
if ( | ||
(person.type === "user" || person.is_broadcast === undefined) && | ||
Boolean(person.delivery_email) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to remove this Boolean
check and just check email for every User
but that actually changes the behavior of this slightly and I'm not yet sure if that's okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth starting a little follow-up thread on this detail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
831334d
to
4fc6815
Compare
4fc6815
to
387685e
Compare
In the most recent push: I've now created all the prep commits I was considering creating, and this PR is fully ready for review. @andersk can you take a look? |
387685e
to
48a25a5
Compare
48a25a5
to
9cf02aa
Compare
21318d7
to
3a90d7b
Compare
3a90d7b
to
9fb6961
Compare
9fb6961
to
0908744
Compare
Test failures look unrelated. @andersk ready for your review again! |
0908744
to
1a1edef
Compare
6c1b0a9
to
3020b1a
Compare
const val = $(this).val(); | ||
const recipients = typeahead_helper.get_cleaned_pm_recipients(val); | ||
$(this).val(recipients.join(", ")); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment on the commit message -- it's not relevant that the block was introduced 10 years ago -- most code introduced at that date does something important -- but more that it should have been removed when we migrated this input to use pills.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, I meant to mention it should have been removed when we moved to pills. Thanks for calling this out.
web/src/composebox_typeahead.ts
Outdated
if (!stream_id) { | ||
return []; | ||
} | ||
|
||
// Fetch topic history from the server, in case we will need it soon. | ||
stream_topic_history_util.get_server_history(stream_id, () => {}); | ||
stream_topic_history_util.get_server_history(stream_id, () => { | ||
/* Don't do anything with the results for now. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better comment would be "We'll use these extended results in the next keypress, but we don't try to live-update what's already shown, which can be annoying if one was about to select/click a visible option."
This will be used for when we suggest emojis in the composebox typeahead.
Since #private_message_recipient is a <div contenteditable>, not an <input> or <textarea>, it doesn’t make sense to call .val() (it will always give the empty string). It looks like this line is from over 10 years ago (zulip@09deef9#diff-f2b22549dc2fb4824b37e787d964a2c9f4f580e767f86b6d7ded1d0ff37d5a62R291) and probably before we had pills here. We can just remove this whole block.
This simplifies some of the logic and will make it easier to convert to TypeScript.
3020b1a
to
96c9950
Compare
Merged, after adding a comment as suggested in #29783 (comment). Huge thanks for slogging through this @evykassirer and @andersk! |
Fully ready for review!