Skip to content

Commit

Permalink
MM-59835: Prevent unnecessary channel bookmarks request causing conso…
Browse files Browse the repository at this point in the history
…le 404 (#27745)

* hoist feature flag check

* fix test

* fix test

---------

Co-authored-by: Mattermost Build <[email protected]>
  • Loading branch information
calebroseland and mattermost-build authored Jul 24, 2024
1 parent caff13c commit 27dfedd
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styled from 'styled-components';

import BookmarkItem from './bookmark_item';
import PlusMenu from './channel_bookmarks_plus_menu';
import {useChannelBookmarkPermission, useChannelBookmarks, useIsChannelBookmarksEnabled, MAX_BOOKMARKS_PER_CHANNEL, useCanUploadFiles} from './utils';
import {useChannelBookmarkPermission, useChannelBookmarks, MAX_BOOKMARKS_PER_CHANNEL, useCanUploadFiles} from './utils';

import './channel_bookmarks.scss';

Expand All @@ -17,13 +17,12 @@ type Props = {
const ChannelBookmarks = ({
channelId,
}: Props) => {
const show = useIsChannelBookmarksEnabled();
const {order, bookmarks} = useChannelBookmarks(channelId);
const canUploadFiles = useCanUploadFiles();
const canAdd = useChannelBookmarkPermission(channelId, 'add');
const hasBookmarks = Boolean(order?.length);

if (!show || (!hasBookmarks && !canAdd)) {
if (!hasBookmarks && !canAdd) {
return null;
}

Expand Down
4 changes: 0 additions & 4 deletions webapp/channels/src/components/channel_bookmarks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import {canUploadFiles, isPublicLinksEnabled} from 'utils/file_utils';

export const MAX_BOOKMARKS_PER_CHANNEL = 50;

export const useIsChannelBookmarksEnabled = () => {
return useSelector(getIsChannelBookmarksEnabled);
};

const {OPEN_CHANNEL, PRIVATE_CHANNEL, GM_CHANNEL, DM_CHANNEL} = Constants as {OPEN_CHANNEL: 'O'; PRIVATE_CHANNEL: 'P'; GM_CHANNEL: 'G'; DM_CHANNEL: 'D'};

type TAction = 'add' | 'edit' | 'delete' | 'order';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports[`components/channel_view Should match snapshot if channel is archived 1`
enableWebSocketEventScope={false}
goToLastViewedChannel={[MockFunction]}
history={Object {}}
isChannelBookmarksEnabled={false}
isCloud={false}
isFirstAdmin={false}
location={Object {}}
Expand All @@ -28,9 +29,6 @@ exports[`components/channel_view Should match snapshot if channel is archived 1`
teamUrl="/team"
viewArchivedChannels={false}
/>
<ChannelBookmarks
channelId="channelId"
/>
<DeferredRenderWrapper
channelId="channelId"
/>
Expand Down Expand Up @@ -76,6 +74,7 @@ exports[`components/channel_view Should match snapshot if channel is deactivated
enableWebSocketEventScope={false}
goToLastViewedChannel={[MockFunction]}
history={Object {}}
isChannelBookmarksEnabled={false}
isCloud={false}
isFirstAdmin={false}
location={Object {}}
Expand All @@ -88,9 +87,6 @@ exports[`components/channel_view Should match snapshot if channel is deactivated
teamUrl="/team"
viewArchivedChannels={false}
/>
<ChannelBookmarks
channelId="channelId"
/>
<DeferredRenderWrapper
channelId="channelId"
/>
Expand Down Expand Up @@ -135,6 +131,7 @@ exports[`components/channel_view Should match snapshot with base props 1`] = `
enableWebSocketEventScope={false}
goToLastViewedChannel={[MockFunction]}
history={Object {}}
isChannelBookmarksEnabled={false}
isCloud={false}
isFirstAdmin={false}
location={Object {}}
Expand All @@ -147,9 +144,6 @@ exports[`components/channel_view Should match snapshot with base props 1`] = `
teamUrl="/team"
viewArchivedChannels={false}
/>
<ChannelBookmarks
channelId="channelId"
/>
<DeferredRenderWrapper
channelId="channelId"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('components/channel_view', () => {
goToLastViewedChannel: jest.fn(),
isFirstAdmin: false,
enableWebSocketEventScope: false,
isChannelBookmarksEnabled: false,
};

it('Should match snapshot with base props', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default class ChannelView extends React.PureComponent<Props, State> {
>
<FileUploadOverlay overlayType='center'/>
<ChannelHeader {...this.props}/>
<ChannelBookmarks channelId={this.props.channelId}/>
{this.props.isChannelBookmarksEnabled && <ChannelBookmarks channelId={this.props.channelId}/>}
<DeferredPostView
channelId={this.props.channelId}
focusedPostId={this.state.focusedPostId}
Expand Down
3 changes: 3 additions & 0 deletions webapp/channels/src/components/channel_view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {isFirstAdmin} from 'mattermost-redux/selectors/entities/users';

import {goToLastViewedChannel} from 'actions/views/channel';

import {getIsChannelBookmarksEnabled} from 'components/channel_bookmarks/utils';

import type {GlobalState} from 'types/store';

import ChannelView from './channel_view';
Expand Down Expand Up @@ -41,6 +43,7 @@ function mapStateToProps(state: GlobalState) {
teamUrl: getCurrentRelativeTeamUrl(state),
isFirstAdmin: isFirstAdmin(state),
enableWebSocketEventScope,
isChannelBookmarksEnabled: getIsChannelBookmarksEnabled(state),
};
}

Expand Down

0 comments on commit 27dfedd

Please sign in to comment.