From 82c7787dc4d5c0ff2696e34539224c1ff9315d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Tue, 9 Sep 2025 09:53:38 +0200 Subject: [PATCH] Do not show the playbooks item on DMs/GMs (#9098) Co-authored-by: Mattermost Build --- app/screens/channel/header/header.test.tsx | 40 +++++++++++++++++++ app/screens/channel/header/header.tsx | 6 +-- .../header/quick_actions/index.test.tsx | 8 ++++ .../channel/header/quick_actions/index.tsx | 2 +- .../channel_info/options/index.test.tsx | 11 +++++ app/screens/channel_info/options/index.tsx | 2 +- 6 files changed, 64 insertions(+), 5 deletions(-) diff --git a/app/screens/channel/header/header.test.tsx b/app/screens/channel/header/header.test.tsx index 34975c7c1..4e88ace2a 100644 --- a/app/screens/channel/header/header.test.tsx +++ b/app/screens/channel/header/header.test.tsx @@ -4,6 +4,7 @@ import React, {type ComponentProps} from 'react'; import NavigationHeader from '@components/navigation_header'; +import {General} from '@constants'; import {useServerUrl} from '@context/server'; import {fetchPlaybookRunsForChannel} from '@playbooks/actions/remote/runs'; import {goToPlaybookRun, goToPlaybookRuns} from '@playbooks/screens/navigation'; @@ -75,6 +76,45 @@ describe('ChannelHeader', () => { ); }); + it('does not show playbook button when is DM or GM', () => { + const props = getBaseProps(); + props.hasPlaybookRuns = true; + props.playbooksActiveRuns = 1; + props.channelType = General.DM_CHANNEL; + const {getByTestId, rerender} = renderWithIntl(); + const navHeader = getByTestId('navigation-header'); + let rightButtons = navHeader.props.rightButtons; + expect(rightButtons).not.toEqual(expect.arrayContaining( + [ + expect.objectContaining({ + iconName: 'product-playbooks', + }), + ]), + ); + + props.channelType = General.GM_CHANNEL; + rerender(); + rightButtons = navHeader.props.rightButtons; + expect(rightButtons).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({ + iconName: 'product-playbooks', + }), + ]), + ); + + props.channelType = General.OPEN_CHANNEL; + rerender(); + rightButtons = navHeader.props.rightButtons; + expect(rightButtons).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + iconName: 'product-playbooks', + }), + ]), + ); + }); + it('shows playbook button with count when there are active runs', () => { const props = getBaseProps(); props.playbooksActiveRuns = 3; diff --git a/app/screens/channel/header/header.tsx b/app/screens/channel/header/header.tsx index 014d157bc..ebe9ad982 100644 --- a/app/screens/channel/header/header.tsx +++ b/app/screens/channel/header/header.tsx @@ -186,7 +186,7 @@ const ChannelHeader = ({ if (callsAvailable && !isDMorGM) { items += 1; } - if (hasPlaybookRuns) { + if (hasPlaybookRuns && !isDMorGM) { items += 1; } let height = CHANNEL_ACTIONS_OPTIONS_HEIGHT + SEPARATOR_HEIGHT + MARGIN + (items * ITEM_HEIGHT); @@ -224,7 +224,7 @@ const ChannelHeader = ({ const rightButtons = useMemo(() => { const buttons: HeaderRightButton[] = []; - if (playbooksActiveRuns) { + if (playbooksActiveRuns && !isDMorGM) { buttons.push({ iconName: 'product-playbooks', onPress: openPlaybooksRuns, @@ -250,7 +250,7 @@ const ChannelHeader = ({ }); return buttons; - }, [playbooksActiveRuns, onChannelQuickAction, openPlaybooksRuns]); + }, [playbooksActiveRuns, isDMorGM, onChannelQuickAction, openPlaybooksRuns]); let title = displayName; if (isOwnDirectMessage) { diff --git a/app/screens/channel/header/quick_actions/index.test.tsx b/app/screens/channel/header/quick_actions/index.test.tsx index 9d136e8cf..a1557e35d 100644 --- a/app/screens/channel/header/quick_actions/index.test.tsx +++ b/app/screens/channel/header/quick_actions/index.test.tsx @@ -54,4 +54,12 @@ describe('ChannelQuickAction', () => { expect(playbookRunsOption.props.channelId).toBe('channel-id'); expect(playbookRunsOption.props.location).toBe('quick_actions'); }); + + it('does not show playbook runs option when is DM or GM', () => { + const props = getBaseProps(); + props.isDMorGM = true; + props.hasPlaybookRuns = true; + const {queryByTestId} = renderWithEverything(, {database}); + expect(queryByTestId('playbook-runs-option')).toBeNull(); + }); }); diff --git a/app/screens/channel/header/quick_actions/index.tsx b/app/screens/channel/header/quick_actions/index.tsx index 7e3a05bb8..7ff7ad01a 100644 --- a/app/screens/channel/header/quick_actions/index.tsx +++ b/app/screens/channel/header/quick_actions/index.tsx @@ -64,7 +64,7 @@ const ChannelQuickAction = ({ showAsLabel={true} testID='channel.quick_actions.channel_info.action' /> - {hasPlaybookRuns && + {hasPlaybookRuns && !isDMorGM && { rerender(); expect(getByTestId('playbook-runs-option')).toHaveProp('channelId', 'channel-id-2'); }); + it('should not show playbook runs option when is DM or GM', () => { + const props = getBaseProps(); + props.type = General.DM_CHANNEL; + const {queryByTestId, rerender} = renderWithEverything(, {database}); + expect(queryByTestId('playbook-runs-option')).toBeNull(); + + props.type = General.GM_CHANNEL; + rerender(); + expect(queryByTestId('playbook-runs-option')).toBeNull(); + }); }); diff --git a/app/screens/channel_info/options/index.tsx b/app/screens/channel_info/options/index.tsx index 40eba982d..924142aaa 100644 --- a/app/screens/channel_info/options/index.tsx +++ b/app/screens/channel_info/options/index.tsx @@ -51,7 +51,7 @@ const Options = ({ - {isPlaybooksEnabled && + {isPlaybooksEnabled && !isDMorGM &&