-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Conversation
@@ -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.'})}); |
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.
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
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 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, |
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.
Changing reason
to a MessageDescriptor
also let me get rid of injectIntl
here
validAddressMessage={validAddressMessage} | ||
noMatchMessage={noMatchMessage} |
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.
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
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.
Great work, just a few nitpicks.
let placeholder; | ||
let noMatchMessage; | ||
if (props.emailInvitationsEnabled) { | ||
placeholder = formatMessage({ |
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.
Not sure why we are mixing having the messages
object, and also using the identifiers directly here. 0/5
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.
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
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.
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.
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.
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
Summary
This is the first part of my mission to eradicate
t
from last week. Most of it is pretty straightforward replacement oft
withdefineMessage
/defineMessages
, and I also occasionally removed some use oflocalizeMessage
as well, but I'll comment on anything noteworthy below.Ticket Link
https://mattermost.atlassian.net/browse/MM-58324
Release Note