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

Remove t from invite-related code #27053

Merged
merged 6 commits into from
May 24, 2024
Merged

Remove t from invite-related code #27053

merged 6 commits into from
May 24, 2024

Conversation

hmhealey
Copy link
Member

Summary

This is the first part of my mission to eradicate t from last week. Most of it is pretty straightforward replacement of t with defineMessage/defineMessages, and I also occasionally removed some use of localizeMessage as well, but I'll comment on anything noteworthy below.

Ticket Link

https://mattermost.atlassian.net/browse/MM-58324

Release Note

NONE

@hmhealey hmhealey added the 2: Dev Review Requires review by a developer label May 17, 2024
@mm-cloud-bot mm-cloud-bot added the release-note-none Denotes a PR that doesn't merit a release note. label May 17, 2024
@@ -34,9 +35,9 @@ export function sendMembersInvites(teamId: string, users: UserProfile[], emails:
for (const user of users) {
const member = getTeamMember(state, teamId, user.id);
if (isGuest(user.roles)) {
notSent.push({user, reason: localizeMessage('invite.members.user-is-guest', 'Contact your admin to make this guest a full member.')});
notSent.push({user, reason: defineMessage({id: 'invite.members.user-is-guest', defaultMessage: 'Contact your admin to make this guest a full member.'})});
Copy link
Member Author

Choose a reason for hiding this comment

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

To get rid of localizeMessage here, I made reason contain a MessageDescriptor instead of the translated string so that the UI can translate it once it reaches there.

I also made the conscious decision here to repeatedly call defineMessage here instead of grouping these together in a big defineMessages below because leaving it this way made the diff so much easier to read. Ideally, I think we'd rewrite this a bit to avoid the deeply nested objects and repeated calls to defineMessage for repeated strings, but I decided not to do that at this time

Copy link
Member Author

Choose a reason for hiding this comment

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

I had to partly revert that because we still had code that set reason to be an error string from the server in some cases. Unfortunately, I didn't catch that earlier because I assumed that the type check would fail when I made it not possible for it to be a string, but because response.error is an any, it wasn't reported

id: 'invitation-modal.confirm.not-valid-user-or-email',
defaultMessage: 'Does not match a valid user or email.',
}),
reason: messages.notValidUserOrEmail,
Copy link
Member Author

Choose a reason for hiding this comment

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

Changing reason to a MessageDescriptor also let me get rid of injectIntl here

Comment on lines +230 to +231
validAddressMessage={validAddressMessage}
noMatchMessage={noMatchMessage}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is one of a few places where we went from passing in separate ID/default props and now we just pass in a single MessageDescriptor for each piece of text

Copy link
Contributor

@larkox larkox left a comment

Choose a reason for hiding this comment

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

Great work, just a few nitpicks.

webapp/channels/src/actions/invite_actions.ts Outdated Show resolved Hide resolved
webapp/channels/src/actions/invite_actions.ts Outdated Show resolved Hide resolved
let placeholder;
let noMatchMessage;
if (props.emailInvitationsEnabled) {
placeholder = formatMessage({
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why we are mixing having the messages object, and also using the identifiers directly here. 0/5

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we haven't really standardized on passing around strings vs message descriptors. For this, I tried to keep them as-is to reduce the scope of these changes.

I've been thinking about if I'd prefer passing around descriptors or strings/components in more places if we were consistent everywhere. My gut reaction would be that passing descriptors would be better, but it makes passing values into those trickier values isn't part of MessageDescriptor. It's also less idiomatic than passing a FormattedMessage when you're rendering something, but some people also avoid FormattedMessage even when it should arguably be used

Copy link
Contributor

Choose a reason for hiding this comment

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

We could make things more complicated and create a "valued message descriptor" that we would have to process where it is used to get the proper string and values. Something like type VMessageDescriptor = MessageDescriptor & {values?: ValuesType}. Then we will have something like function renderValuedDescriptor(vd, intl) { return intl.formatMessage({id: vd.id, defaultMessage: vd.defaultMessage}, vd.values);}.

But 0/5 on that approach. Maybe we can figure out something in the middle that make sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

There's a few places we have done that, but I'm not sure if I'd want to do that everywhere because it is nice to encourage people to not overuse values in cases where they should just have two separate strings. Values also don't always work when the message is being used for an aria-label or something else that needs text.

For now, I'll leave it -as-is, but I'm going to keep thinking about this since it would be nice if there was a good solution for this that worked everywhere

@hmhealey hmhealey added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a developer labels May 24, 2024
@hmhealey hmhealey merged commit 38b5974 into master May 24, 2024
24 checks passed
@hmhealey hmhealey deleted the hh_may17-t-1 branch May 24, 2024 16:04
@amyblais amyblais added Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation labels May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation release-note-none Denotes a PR that doesn't merit a release note.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants