From 7179a9d1d63a0ff3c04db1631d6324a3b6ede4fe Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Fri, 13 Dec 2024 09:49:28 -0400 Subject: [PATCH] reduce usage of Utils.localizeMessage (#29282) * reduce usage of Utils.localizeMessage As we begin to transition to react-intl's `formatjs` for extraction, our custom wrappers like `Utils.localizeMessage` prevent an adoption roadblock. This is the first in a series of PRs to begin to migrate away in favour of: * `useIntl` when inside React functional component * use `injectIntl` and use access the `intl` prop from class components * use the new `getIntl`, leveraging a memoized `createIntl` and the store outside of React components I'm pausing in this effort to get a feel from peers on both the substance of these changes and best practices in supporting them. * prefer shallowWithIntl, renderWithContext, and local injectIntl wrapping * revert unintentional whitespaces * clarify getIntl, add minor unit test * avoid triggering mmjstool * update e2e tests --------- Co-authored-by: Mattermost Build --- .../accessibility/accessibility_post_spec.js | 4 +- .../components/actions_menu/actions_menu.tsx | 5 +- .../markdown_image.test.tsx.snap | 10 +- .../__snapshots__/post_reaction.test.tsx.snap | 2 +- .../post_reaction/post_reaction.test.tsx | 10 +- .../post_view/post_reaction/post_reaction.tsx | 15 +- .../__snapshots__/sidebar.test.tsx.snap | 6 +- .../sidebar_base_channel.test.tsx.snap | 8 +- .../sidebar_channel_link.test.tsx | 16 +- .../sidebar_channel_link.tsx | 16 +- .../sidebar_direct_channel.test.tsx.snap | 8 +- .../sidebar_list/sidebar_list.test.tsx | 37 +++-- .../sidebar/sidebar_list/sidebar_list.tsx | 12 +- .../single_image_view.test.tsx.snap | 12 +- .../single_image_view.test.tsx | 2 +- .../src/components/size_aware_image.test.tsx | 59 ++++--- .../src/components/size_aware_image.tsx | 25 +-- .../status_dropdown.test.tsx.snap | 45 ++---- .../suggestion/switch_channel_provider.tsx | 16 +- .../team_members_dropdown.test.tsx.snap | 49 +++++- .../team_members_dropdown.test.tsx | 10 +- .../team_members_dropdown.tsx | 35 ++-- .../components/team_sidebar/team_sidebar.tsx | 13 +- .../user_groups_list/user_groups_list.tsx | 12 +- .../__snapshots__/submenu_item.test.tsx.snap | 152 ++++++++++++++++++ .../menu/menu_items/submenu_item.test.tsx | 32 ++-- .../widgets/menu/menu_items/submenu_item.tsx | 18 ++- .../__snapshots__/submenu_modal.test.tsx.snap | 12 +- .../submenu_modal/submenu_modal.test.tsx | 13 +- webapp/channels/src/utils/i18n.test.tsx | 29 ++++ webapp/channels/src/utils/i18n.tsx | 20 ++- 31 files changed, 475 insertions(+), 228 deletions(-) create mode 100644 webapp/channels/src/utils/i18n.test.tsx diff --git a/e2e-tests/cypress/tests/integration/channels/accessibility/accessibility_post_spec.js b/e2e-tests/cypress/tests/integration/channels/accessibility/accessibility_post_spec.js index 74a99a65d4..f74a7a5360 100644 --- a/e2e-tests/cypress/tests/integration/channels/accessibility/accessibility_post_spec.js +++ b/e2e-tests/cypress/tests/integration/channels/accessibility/accessibility_post_spec.js @@ -181,7 +181,7 @@ describe('Verify Accessibility Support in Post', () => { } // * Verify focus is on the reactions button - cy.get(`#CENTER_reaction_${postId}`).should('be.focused').and('have.attr', 'aria-label', 'add reaction'); + cy.get(`#CENTER_reaction_${postId}`).should('be.focused').and('have.attr', 'aria-label', 'Add Reaction'); cy.focused().tab(); // * Verify focus is on the save post button @@ -247,7 +247,7 @@ describe('Verify Accessibility Support in Post', () => { cy.focused().tab({shift: true}); // * Verify focus is on the reactions button - cy.get(`#RHS_COMMENT_reaction_${postId}`).should('be.focused').and('have.attr', 'aria-label', 'add reaction'); + cy.get(`#RHS_COMMENT_reaction_${postId}`).should('be.focused').and('have.attr', 'aria-label', 'Add Reaction'); cy.focused().tab({shift: true}); // * Verify focus is on most recent action diff --git a/webapp/channels/src/components/actions_menu/actions_menu.tsx b/webapp/channels/src/components/actions_menu/actions_menu.tsx index dac3f3b6db..a4a5694535 100644 --- a/webapp/channels/src/components/actions_menu/actions_menu.tsx +++ b/webapp/channels/src/components/actions_menu/actions_menu.tsx @@ -24,7 +24,6 @@ import Pluggable from 'plugins/pluggable'; import {createCallContext} from 'utils/apps'; import {Constants, Locations, ModalIdentifiers} from 'utils/constants'; import * as PostUtils from 'utils/post_utils'; -import * as Utils from 'utils/utils'; import type {ModalData} from 'types/actions'; import type {HandleBindingClick, OpenAppsModal, PostEphemeralCallResponseForPost} from 'types/apps'; @@ -395,7 +394,7 @@ export class ActionMenuClass extends React.PureComponent { key='more-actions-button' ref={this.buttonRef} id={`${this.props.location}_actions_button_${this.props.post.id}`} - aria-label={Utils.localizeMessage({id: 'post_info.actions.tooltip.actions', defaultMessage: 'Actions'}).toLowerCase()} + aria-label={formatMessage({id: 'post_info.actions.tooltip.actions', defaultMessage: 'Actions'}).toLowerCase()} className={classNames('post-menu__item', { 'post-menu__item--active': this.props.isMenuOpen, })} @@ -409,7 +408,7 @@ export class ActionMenuClass extends React.PureComponent { id={`${this.props.location}_actions_dropdown_${this.props.post.id}`} openLeft={true} openUp={this.state.openUp} - ariaLabel={Utils.localizeMessage({id: 'post_info.menuAriaLabel', defaultMessage: 'Post extra options'})} + ariaLabel={formatMessage({id: 'post_info.menuAriaLabel', defaultMessage: 'Post extra options'})} key={`${this.props.location}_actions_dropdown_${this.props.post.id}`} > {menuItems} diff --git a/webapp/channels/src/components/markdown_image/__snapshots__/markdown_image.test.tsx.snap b/webapp/channels/src/components/markdown_image/__snapshots__/markdown_image.test.tsx.snap index feb76f0ce4..cca77fe243 100644 --- a/webapp/channels/src/components/markdown_image/__snapshots__/markdown_image.test.tsx.snap +++ b/webapp/channels/src/components/markdown_image/__snapshots__/markdown_image.test.tsx.snap @@ -17,7 +17,7 @@ exports[`components/MarkdownImage should match snapshot 1`] = ` `; exports[`components/MarkdownImage should match snapshot for SizeAwareImage dimensions 1`] = ` - - - - -