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

composebox_typeahead: Convert module to typescript. #29783

Merged
merged 8 commits into from
May 16, 2024

Conversation

evykassirer
Copy link
Collaborator

@evykassirer evykassirer commented Apr 18, 2024

Fully ready for review!

@evykassirer evykassirer added the area: typescript migration Issues for migrating Zulip to TypeScript label Apr 18, 2024
@evykassirer evykassirer force-pushed the composebox-typeahead-typescript branch 3 times, most recently from 8cdf63e to f0bc166 Compare April 24, 2024 18:12
@evykassirer
Copy link
Collaborator Author

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.

@evykassirer evykassirer force-pushed the composebox-typeahead-typescript branch 2 times, most recently from 77992e6 to 2ad7836 Compare April 24, 2024 18:45
@evykassirer evykassirer force-pushed the composebox-typeahead-typescript branch from 2ad7836 to 3b05fbc Compare April 25, 2024 17:39
@evykassirer evykassirer force-pushed the composebox-typeahead-typescript branch 2 times, most recently from 174acb7 to cf43a97 Compare April 25, 2024 22:36
@@ -44,6 +46,10 @@ type UnicodeEmoji = {
emoji_code: string;
reaction_type: "unicode_emoji";
is_realm_emoji: false;
emoji_url?: string;
Copy link
Collaborator Author

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

Copy link
Sponsor Member

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.

Copy link
Collaborator Author

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.

Copy link
Sponsor Member

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.

@evykassirer evykassirer force-pushed the composebox-typeahead-typescript branch 2 times, most recently from 2a34c60 to 831334d Compare April 25, 2024 22:43

type PillItem =
| UserGroupPillData
| UserOrMentionPillData
Copy link
Collaborator Author

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 Suggestions. But then would it make sense to rename the types used in the pill typeahead to be Suggestion?

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
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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.

Copy link
Sponsor Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@evykassirer evykassirer force-pushed the composebox-typeahead-typescript branch from 831334d to 4fc6815 Compare April 25, 2024 22:56
@evykassirer evykassirer force-pushed the composebox-typeahead-typescript branch from 4fc6815 to 387685e Compare May 3, 2024 04:21
@evykassirer evykassirer marked this pull request as ready for review May 3, 2024 04:22
@evykassirer
Copy link
Collaborator Author

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?

@evykassirer evykassirer force-pushed the composebox-typeahead-typescript branch from 48a25a5 to 9cf02aa Compare May 9, 2024 05:03
@evykassirer
Copy link
Collaborator Author

Test failures look unrelated. @andersk ready for your review again!

@evykassirer evykassirer force-pushed the composebox-typeahead-typescript branch from 0908744 to 1a1edef Compare May 15, 2024 23:39
@andersk andersk force-pushed the composebox-typeahead-typescript branch 4 times, most recently from 6c1b0a9 to 3020b1a Compare May 16, 2024 16:57
@andersk andersk added the integration review Added by maintainers when a PR may be ready for integration. label May 16, 2024
const val = $(this).val();
const recipients = typeahead_helper.get_cleaned_pm_recipients(val);
$(this).val(recipients.join(", "));
});
Copy link
Sponsor Member

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.

Copy link
Collaborator Author

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.

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. */
Copy link
Sponsor Member

@timabbott timabbott May 16, 2024

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.
@timabbott timabbott force-pushed the composebox-typeahead-typescript branch from 3020b1a to 96c9950 Compare May 16, 2024 21:53
@timabbott timabbott merged commit 96c9950 into zulip:main May 16, 2024
5 of 6 checks passed
@timabbott
Copy link
Sponsor Member

Merged, after adding a comment as suggested in #29783 (comment).

Huge thanks for slogging through this @evykassirer and @andersk!

@evykassirer evykassirer deleted the composebox-typeahead-typescript branch May 16, 2024 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: typescript migration Issues for migrating Zulip to TypeScript integration review Added by maintainers when a PR may be ready for integration. size: XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants