From af0a7525c87bfa1c43917f2187356c0f3797878e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Tue, 13 May 2025 17:07:13 +0200 Subject: [PATCH] Refactor Open Profile (#8746) * Refactor Open Profile * Add missing changes * Fix tests * Fix tests * Address feedback --- .../autocomplete_selector/index.tsx | 21 +++- .../draft_scheduled_post.tsx | 3 +- .../draft_and_scheduled_post_message.tsx | 3 +- .../draft_scheduled_post_container/index.tsx | 3 +- .../formatted_markdown_text/index.tsx | 3 +- .../markdown/at_mention/at_mention.tsx | 20 ++-- app/components/markdown/markdown.test.tsx | 2 +- app/components/markdown/markdown.tsx | 3 +- app/components/post_draft/archived/index.tsx | 6 +- app/components/post_draft/post_draft.tsx | 5 + .../combined_user_activity.tsx | 4 +- .../combined_user_activity/last_users.tsx | 4 +- .../post_list/post/avatar/avatar.tsx | 22 ++-- .../acknowledgements/acknowledgements.tsx | 3 +- .../users_list/user_list_item.tsx | 19 ++-- .../users_list/users_list.tsx | 3 +- .../post/body/add_members/add_members.tsx | 3 +- .../content/embedded_bindings/embed_text.tsx | 4 +- .../content/embedded_bindings/embed_title.tsx | 4 +- .../embedded_bindings/embedded_binding.tsx | 4 +- .../embedded_sub_bindings.tsx | 10 +- .../body/content/embedded_bindings/index.tsx | 3 +- .../embedded_bindings/menu_binding/index.tsx | 11 +- .../post_list/post/body/content/index.tsx | 3 +- .../message_attachments/action_menu/index.tsx | 15 ++- .../attachment_actions.tsx | 11 +- .../message_attachments/attachment_fields.tsx | 3 +- .../attachment_pretext.tsx | 3 +- .../message_attachments/attachment_text.tsx | 3 +- .../message_attachments/attachment_title.tsx | 4 +- .../content/message_attachments/index.tsx | 4 +- .../message_attachment.test.tsx | 6 +- .../message_attachment.tsx | 5 +- app/components/post_list/post/body/index.tsx | 3 +- .../post_list/post/body/message/message.tsx | 3 +- .../post_list/post/footer/footer.tsx | 3 +- .../post/header/display_name/index.tsx | 29 ++--- .../post_list/post/header/header.tsx | 3 +- app/components/post_list/post/post.tsx | 3 +- .../post/system_message/system_message.tsx | 3 +- app/components/post_list/post_list.tsx | 3 +- .../post_with_channel_info.tsx | 3 +- app/components/section_notice/index.test.tsx | 2 + app/components/section_notice/index.tsx | 6 +- app/components/server_user_list/index.tsx | 5 + app/components/settings/bool_setting.tsx | 5 + app/components/settings/footer.tsx | 10 +- .../settings/radio_setting/index.tsx | 5 + app/components/settings/text_setting.tsx | 5 + app/components/user_avatars_stack/index.tsx | 3 +- .../user_avatars_stack/users_list/index.tsx | 22 ++-- .../__snapshots__/index.test.tsx.snap | 6 +- app/components/user_list/index.test.tsx | 97 ++++++---------- app/components/user_list/index.tsx | 22 ++-- app/products/calls/actions/calls.test.ts | 1 + app/products/calls/hooks.test.ts | 13 ++- app/products/calls/hooks.ts | 11 +- app/products/calls/state/actions.test.ts | 1 + app/screens/apps_form/apps_form_component.tsx | 3 +- app/screens/apps_form/apps_form_field.tsx | 7 +- app/screens/channel/channel.tsx | 2 + .../intro/direct_channel/member/member.tsx | 16 ++- .../channel_add_members.tsx | 3 +- app/screens/component_library/hooks.tsx | 4 + app/screens/component_library/index.tsx | 5 +- .../create_direct_message.tsx | 3 +- ..._and_scheduled_post_swipe_actions.test.tsx | 12 +- ...draft_and_scheduled_post_swipe_actions.tsx | 3 +- .../global_drafts_list/global_drafts_list.tsx | 3 +- .../global_scheduled_post_list.tsx | 3 +- .../threads_list/thread/thread.tsx | 3 +- .../thread/thread_footer/thread_footer.tsx | 3 +- .../integration_selector.tsx | 3 +- .../interactive_dialog/dialog_element.tsx | 5 + .../dialog_introduction_text.tsx | 3 +- .../manage_channel_members.tsx | 1 + app/screens/navigation.test.ts | 107 ++++++++++++++++++ app/screens/navigation.ts | 22 +++- app/screens/reactions/reactions.tsx | 3 +- app/screens/reactions/reactors_list/index.tsx | 3 +- .../reactors_list/reactor/reactor.tsx | 19 ++-- .../send_test_notification_notice.tsx | 2 + app/screens/snack_bar/snack_bar.test.tsx | 1 + app/screens/thread/thread.tsx | 1 + app/screens/user_profile/options.tsx | 4 +- app/screens/user_profile/user_profile.tsx | 4 +- app/utils/draft/index.test.ts | 29 ----- test/setup.ts | 11 ++ types/utils/utils.ts | 4 + 89 files changed, 509 insertions(+), 270 deletions(-) create mode 100644 app/screens/navigation.test.ts create mode 100644 types/utils/utils.ts diff --git a/app/components/autocomplete_selector/index.tsx b/app/components/autocomplete_selector/index.tsx index 9412a3436..77cce1461 100644 --- a/app/components/autocomplete_selector/index.tsx +++ b/app/components/autocomplete_selector/index.tsx @@ -23,6 +23,7 @@ import {secureGetFromRecord} from '@utils/types'; import {displayUsername} from '@utils/user'; import type {WithDatabaseArgs} from '@typings/database/database'; +import type {AvailableScreens} from '@typings/screens/navigation'; type Selection = DialogOption | Channel | UserProfile | DialogOption[] | Channel[] | UserProfile[]; @@ -43,6 +44,7 @@ type AutoCompleteSelectorProps = { teammateNameDisplay: string; isMultiselect?: boolean; testID: string; + location: AvailableScreens; } const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => { @@ -131,8 +133,22 @@ function getTextAndValueFromSelectedItem(item: Selection, teammateNameDisplay: s } function AutoCompleteSelector({ - dataSource, disabled = false, errorText, getDynamicOptions, helpText, label, onSelected, optional = false, - options, placeholder, roundedBorders = true, selected, teammateNameDisplay, isMultiselect = false, testID, + dataSource, + disabled = false, + errorText, + getDynamicOptions, + helpText, + label, + onSelected, + optional = false, + options, + placeholder, + roundedBorders = true, + selected, + teammateNameDisplay, + isMultiselect = false, + testID, + location, }: AutoCompleteSelectorProps) { const intl = useIntl(); const theme = useTheme(); @@ -221,6 +237,7 @@ function AutoCompleteSelector({ disabled={disabled} helpText={helpText} errorText={errorText} + location={location} /> ); diff --git a/app/components/draft_scheduled_post/draft_scheduled_post.tsx b/app/components/draft_scheduled_post/draft_scheduled_post.tsx index 6a36a2989..a60fc8525 100644 --- a/app/components/draft_scheduled_post/draft_scheduled_post.tsx +++ b/app/components/draft_scheduled_post/draft_scheduled_post.tsx @@ -23,10 +23,11 @@ import type ChannelModel from '@typings/database/models/servers/channel'; import type DraftModel from '@typings/database/models/servers/draft'; import type ScheduledPostModel from '@typings/database/models/servers/scheduled_post'; import type UserModel from '@typings/database/models/servers/user'; +import type {AvailableScreens} from '@typings/screens/navigation'; type Props = { channel: ChannelModel; - location: string; + location: AvailableScreens; postReceiverUser?: UserModel; post: DraftModel | ScheduledPostModel; layoutWidth: number; diff --git a/app/components/draft_scheduled_post/draft_scheduled_post_container/draft_and_scheduled_post_message.tsx b/app/components/draft_scheduled_post/draft_scheduled_post_container/draft_and_scheduled_post_message.tsx index acdee7bca..a32a30cd0 100644 --- a/app/components/draft_scheduled_post/draft_scheduled_post_container/draft_and_scheduled_post_message.tsx +++ b/app/components/draft_scheduled_post/draft_scheduled_post_container/draft_and_scheduled_post_message.tsx @@ -16,11 +16,12 @@ import {typography} from '@utils/typography'; import type DraftModel from '@typings/database/models/servers/draft'; import type ScheduledPostModel from '@typings/database/models/servers/scheduled_post'; import type {UserMentionKey} from '@typings/global/markdown'; +import type {AvailableScreens} from '@typings/screens/navigation'; type Props = { post: DraftModel | ScheduledPostModel; layoutWidth: number; - location: string; + location: AvailableScreens; } const EMPTY_MENTION_KEYS: UserMentionKey[] = []; diff --git a/app/components/draft_scheduled_post/draft_scheduled_post_container/index.tsx b/app/components/draft_scheduled_post/draft_scheduled_post_container/index.tsx index 1934c436c..ded2c309b 100644 --- a/app/components/draft_scheduled_post/draft_scheduled_post_container/index.tsx +++ b/app/components/draft_scheduled_post/draft_scheduled_post_container/index.tsx @@ -12,10 +12,11 @@ import DraftAndScheduledPostMessage from './draft_and_scheduled_post_message'; import type DraftModel from '@typings/database/models/servers/draft'; import type ScheduledPostModel from '@typings/database/models/servers/scheduled_post'; +import type {AvailableScreens} from '@typings/screens/navigation'; type Props = { post: DraftModel | ScheduledPostModel; - location: string; + location: AvailableScreens; layoutWidth: number; } diff --git a/app/components/formatted_markdown_text/index.tsx b/app/components/formatted_markdown_text/index.tsx index 674f6d992..94b6eb946 100644 --- a/app/components/formatted_markdown_text/index.tsx +++ b/app/components/formatted_markdown_text/index.tsx @@ -14,6 +14,7 @@ import {logWarning} from '@utils/log'; import {getMarkdownBlockStyles, getMarkdownTextStyles} from '@utils/markdown'; import {concatStyles, changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; +import type {AvailableScreens} from '@typings/screens/navigation'; import type {PrimitiveType} from 'intl-messageformat'; type Props = { @@ -21,7 +22,7 @@ type Props = { channelId?: string; defaultMessage: string; id: string; - location: string; + location: AvailableScreens; onPostPress?: (e: GestureResponderEvent) => void; style?: StyleProp; values?: Record; diff --git a/app/components/markdown/at_mention/at_mention.tsx b/app/components/markdown/at_mention/at_mention.tsx index ce337d4c9..fec462ad7 100644 --- a/app/components/markdown/at_mention/at_mention.tsx +++ b/app/components/markdown/at_mention/at_mention.tsx @@ -5,28 +5,28 @@ import {useManagedConfig} from '@mattermost/react-native-emm'; import Clipboard from '@react-native-clipboard/clipboard'; import React, {useCallback, useEffect, useMemo} from 'react'; import {useIntl} from 'react-intl'; -import {type GestureResponderEvent, Keyboard, type StyleProp, StyleSheet, Text, type TextStyle, View} from 'react-native'; +import {type GestureResponderEvent, type StyleProp, StyleSheet, Text, type TextStyle, View} from 'react-native'; import {fetchUserOrGroupsByMentionsInBatch} from '@actions/remote/user'; import SlideUpPanelItem, {ITEM_HEIGHT} from '@components/slide_up_panel_item'; -import {Screens} from '@constants'; import {useServerUrl} from '@context/server'; import {useTheme} from '@context/theme'; import GroupModel from '@database/models/server/group'; import {useMemoMentionedGroup, useMemoMentionedUser} from '@hooks/markdown'; -import {bottomSheet, dismissBottomSheet, openAsBottomSheet} from '@screens/navigation'; +import {bottomSheet, dismissBottomSheet, openUserProfileModal} from '@screens/navigation'; import {bottomSheetSnapPoint} from '@utils/helpers'; import {displayUsername} from '@utils/user'; import type GroupMembershipModel from '@typings/database/models/servers/group_membership'; import type UserModelType from '@typings/database/models/servers/user'; +import type {AvailableScreens} from '@typings/screens/navigation'; type AtMentionProps = { channelId?: string; currentUserId: string; disableAtChannelMentionHighlight?: boolean; isSearchResult?: boolean; - location: string; + location: AvailableScreens; mentionKeys?: Array<{key: string }>; mentionName: string; mentionStyle: StyleProp; @@ -95,13 +95,11 @@ const AtMention = ({ return; } - const screen = Screens.USER_PROFILE; - const title = intl.formatMessage({id: 'mobile.routes.user_profile', defaultMessage: 'Profile'}); - const closeButtonId = 'close-user-profile'; - const props = {closeButtonId, location, userId: user.id, channelId}; - - Keyboard.dismiss(); - openAsBottomSheet({screen, title, theme, closeButtonId, props}); + openUserProfileModal(intl, theme, { + location, + userId: user.id, + channelId, + }); }; const handleLongPress = useCallback(() => { diff --git a/app/components/markdown/markdown.test.tsx b/app/components/markdown/markdown.test.tsx index 804a36916..db78336fa 100644 --- a/app/components/markdown/markdown.test.tsx +++ b/app/components/markdown/markdown.test.tsx @@ -19,7 +19,7 @@ describe('Markdown', () => { baseTextStyle: {}, enableInlineLatex: true, enableLatex: true, - location: 'somewhere?', + location: 'Channel', maxNodes: 2000, theme: Preferences.THEMES.denim, }; diff --git a/app/components/markdown/markdown.tsx b/app/components/markdown/markdown.tsx index e72a8a978..38f23a527 100644 --- a/app/components/markdown/markdown.tsx +++ b/app/components/markdown/markdown.tsx @@ -38,6 +38,7 @@ import type { MarkdownAtMentionRenderer, MarkdownBaseRenderer, MarkdownBlockStyles, MarkdownChannelMentionRenderer, MarkdownEmojiRenderer, MarkdownImageRenderer, MarkdownLatexRenderer, MarkdownTextStyles, SearchPattern, UserMentionKey, HighlightWithoutNotificationKey, } from '@typings/global/markdown'; +import type {AvailableScreens} from '@typings/screens/navigation'; type MarkdownProps = { autolinkedUrlSchemes?: string[]; @@ -65,7 +66,7 @@ type MarkdownProps = { isSearchResult?: boolean; layoutHeight?: number; layoutWidth?: number; - location: string; + location: AvailableScreens; maxNodes: number; mentionKeys?: UserMentionKey[]; minimumHashtagLength?: number; diff --git a/app/components/post_draft/archived/index.tsx b/app/components/post_draft/archived/index.tsx index 867e61e92..d11b9ceaf 100644 --- a/app/components/post_draft/archived/index.tsx +++ b/app/components/post_draft/archived/index.tsx @@ -16,9 +16,12 @@ import {popToRoot} from '@screens/navigation'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; import {typography} from '@utils/typography'; +import type {AvailableScreens} from '@typings/screens/navigation'; + type Props = { testID?: string; deactivated?: boolean; + location: AvailableScreens; } const getStyleSheet = makeStyleSheetFromTheme((theme) => ({ @@ -57,6 +60,7 @@ const edges: Edge[] = ['bottom']; export default function Archived({ testID, deactivated, + location, }: Props) { const theme = useTheme(); const style = getStyleSheet(theme); @@ -94,7 +98,7 @@ export default function Archived({ {...message} style={style.archivedText} baseTextStyle={style.baseTextStyle} - location='' + location={location} />