Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Isolate Apps to disable them whenever needed #7376

Merged
merged 7 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change shouldProcessApps by a more meaningful name appsEnabled
  • Loading branch information
larkox committed Feb 10, 2021
commit 5fd78293ca6c56523a11ec5abc3992dcbe9fc196
4 changes: 2 additions & 2 deletions actions/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as GlobalActions from 'actions/global_actions';
import * as PostActions from 'actions/post_actions.jsx';

import {isUrlSafe, getSiteURL} from 'utils/url';
import {localizeMessage, getUserIdFromChannelName, shouldProcessApps} from 'utils/utils.jsx';
import {localizeMessage, getUserIdFromChannelName, appsEnabled} from 'utils/utils.jsx';
import * as UserAgent from 'utils/user_agent';
import {Constants, ModalIdentifiers} from 'utils/constants';
import {browserHistory} from 'utils/browser_history';
Expand Down Expand Up @@ -102,7 +102,7 @@ export function executeCommand(message: string, args: CommandArgs): ActionFunc {
dispatch(PostActions.resetEmbedVisibility());
}

if (shouldProcessApps(state)) {
if (appsEnabled(state)) {
const getGlobalState = () => getState() as GlobalState;

const parser = new AppCommandParser({dispatch, getState: getGlobalState}, args.root_id);
Expand Down
2 changes: 1 addition & 1 deletion actions/global_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function emitChannelClickEvent(channel: Channel) {
member: member || {},
}]));

if (Utils.shouldProcessApps(state)) {
if (Utils.appsEnabled(state)) {
dispatch(fetchAppBindings(userId, chan.id));
}
}
Expand Down
4 changes: 2 additions & 2 deletions actions/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {GlobalState} from 'types/store';

import {getApp, getFilter, getPlugin} from 'selectors/views/marketplace';
import {ActionTypes} from 'utils/constants';
import {shouldProcessApps} from 'utils/utils';
import {appsEnabled} from 'utils/utils';

import {isError} from 'types/actions';

Expand Down Expand Up @@ -44,7 +44,7 @@ export function fetchListing(localOnly = false): ActionFunc {
plugins,
});

if (shouldProcessApps(state)) {
if (appsEnabled(state)) {
try {
apps = await Client4.getMarketplaceApps(filter);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion components/dot_menu/dot_menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('components/dot_menu/DotMenu', () => {
canDelete: false,
appBindings: [],
pluginMenuItems: [],
shouldProcessApps: false,
appsEnabled: false,
};

test('should match snapshot, on Center', () => {
Expand Down
4 changes: 2 additions & 2 deletions components/dot_menu/dot_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Props = {
channelIsArchived?: boolean; // TechDebt: Made non-mandatory while converting to typescript
currentTeamUrl?: string; // TechDebt: Made non-mandatory while converting to typescript
appBindings: AppBinding[];
shouldProcessApps: boolean;
appsEnabled: boolean;

/**
* Components for overriding provided by plugins
Expand Down Expand Up @@ -330,7 +330,7 @@ export default class DotMenu extends React.PureComponent<Props, State> {
}) || [];

let appBindings = [] as JSX.Element[];
if (this.props.shouldProcessApps) {
if (this.props.appsEnabled) {
appBindings = this.props.appBindings.map((item) => {
let icon: JSX.Element | undefined;
if (item.icon) {
Expand Down
2 changes: 1 addition & 1 deletion components/dot_menu/dot_menu_empty.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('components/dot_menu/DotMenu returning empty ("")', () => {
canDelete: false,
appBindings: [],
pluginMenuItems: [],
shouldProcessApps: false,
appsEnabled: false,
};

const wrapper: ShallowWrapper<any, any, DotMenu> = shallow(
Expand Down
2 changes: 1 addition & 1 deletion components/dot_menu/dot_menu_mobile.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('components/dot_menu/DotMenu on mobile view', () => {
canDelete: false,
appBindings: [],
pluginMenuItems: [],
shouldProcessApps: false,
appsEnabled: false,
};

const wrapper: ShallowWrapper<any, any, DotMenu> = shallow(
Expand Down
8 changes: 4 additions & 4 deletions components/dot_menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import * as PostUtils from 'utils/post_utils.jsx';
import {isArchivedChannel} from 'utils/channel_utils';
import {getSiteURL} from 'utils/url';

import {shouldProcessApps} from 'utils/utils';
import {appsEnabled} from 'utils/utils';

import DotMenu from './dot_menu';

Expand All @@ -59,8 +59,8 @@ function mapStateToProps(state: GlobalState, ownProps: Props) {
const currentTeam = getCurrentTeam(state) || {};
const currentTeamUrl = `${getSiteURL()}/${currentTeam.name}`;

const processApps = shouldProcessApps(state);
const appBindings = processApps ? getAppBindings(state, AppBindingLocations.POST_MENU_ITEM) : [];
const apps = appsEnabled(state);
const appBindings = apps ? getAppBindings(state, AppBindingLocations.POST_MENU_ITEM) : [];

return {
channelIsArchived: isArchivedChannel(channel),
Expand All @@ -73,7 +73,7 @@ function mapStateToProps(state: GlobalState, ownProps: Props) {
canDelete: PostUtils.canDeletePost(state, post, channel),
currentTeamUrl,
appBindings,
shouldProcessApps: processApps,
appsEnabled: apps,
...ownProps,
};
}
Expand Down
4 changes: 2 additions & 2 deletions components/post_view/post_body_additional_content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {isEmbedVisible} from 'selectors/posts';
import {GlobalState} from 'types/store';
import {PostWillRenderEmbedPluginComponent} from 'types/store/plugins';

import {shouldProcessApps} from 'utils/utils';
import {appsEnabled} from 'utils/utils';

import PostBodyAdditionalContent, {
Props,
Expand All @@ -20,7 +20,7 @@ function mapStateToProps(state: GlobalState, ownProps: Props) {
return {
isEmbedVisible: isEmbedVisible(state, ownProps.post.id),
pluginPostWillRenderEmbedComponents: state.plugins.components.PostWillRenderEmbedComponent as unknown as PostWillRenderEmbedPluginComponent[],
shouldProcessApps: shouldProcessApps(state),
appsEnabled: appsEnabled(state),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('PostBodyAdditionalContent', () => {
actions: {
toggleEmbedVisibility: jest.fn(),
},
shouldProcessApps: false,
appsEnabled: false,
};

describe('with an image preview', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type Props = {
children?: JSX.Element;
isEmbedVisible?: boolean;
options?: Partial<TextFormattingOptions>;
shouldProcessApps: boolean;
appsEnabled: boolean;
actions: {
toggleEmbedVisibility: (id: string) => void;
};
Expand Down Expand Up @@ -133,7 +133,7 @@ export default class PostBodyAdditionalContent extends React.PureComponent<Props
render() {
const embed = this.getEmbed();

if (this.props.shouldProcessApps) {
if (this.props.appsEnabled) {
if (hasValidEmbeddedForm(this.props.post.props)) {
// TODO Put some log / message if the form is not valid?
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default class CommandProvider extends Provider {
}
}

if (Utils.shouldProcessApps(this.store.getState())) {
if (Utils.appsEnabled(this.store.getState())) {
this.appCommandParser = new AppCommandParser(this.store, rootId);
}
}
Expand Down
11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports[`plugins/ChannelHeaderPlug should match snapshot with no extended compon
channel={Object {}}
channelMember={Object {}}
components={Array []}
shouldProcessApps={false}
appsEnabled={false}
theme={Object {}}
/>
`;
Expand Down Expand Up @@ -40,7 +40,7 @@ exports[`plugins/ChannelHeaderPlug should match snapshot with one extended compo
},
]
}
shouldProcessApps={false}
appsEnabled={false}
theme={Object {}}
>
<HeaderIconWrapper
Expand Down Expand Up @@ -194,7 +194,7 @@ exports[`plugins/ChannelHeaderPlug should match snapshot with six extended compo
},
]
}
shouldProcessApps={false}
appsEnabled={false}
theme={Object {}}
>
<div
Expand Down
6 changes: 3 additions & 3 deletions plugins/channel_header_plug/channel_header_plug.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('plugins/ChannelHeaderPlug', () => {
doAppCall: jest.fn(),
}}
appBindings={[]}
shouldProcessApps={false}
appsEnabled={false}
/>,
);
expect(wrapper).toMatchSnapshot();
Expand All @@ -49,7 +49,7 @@ describe('plugins/ChannelHeaderPlug', () => {
doAppCall: jest.fn(),
}}
appBindings={[]}
shouldProcessApps={false}
appsEnabled={false}
/>,
);
expect(wrapper).toMatchSnapshot();
Expand All @@ -73,7 +73,7 @@ describe('plugins/ChannelHeaderPlug', () => {
doAppCall: jest.fn(),
}}
appBindings={[]}
shouldProcessApps={false}
appsEnabled={false}
/>,
);
expect(wrapper).toMatchSnapshot();
Expand Down
8 changes: 4 additions & 4 deletions plugins/channel_header_plug/channel_header_plug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class CustomToggle extends React.PureComponent<CustomToggleProps> {
type ChannelHeaderPlugProps = {
components: PluginComponent[];
appBindings: AppBinding[];
shouldProcessApps: boolean;
appsEnabled: boolean;
channel: Channel;
channelMember: ChannelMembership;
theme: Theme;
Expand Down Expand Up @@ -198,7 +198,7 @@ export default class ChannelHeaderPlug extends React.PureComponent<ChannelHeader
});

let items = componentItems;
if (this.props.shouldProcessApps) {
if (this.props.appsEnabled) {
items = componentItems.concat(appBindings.filter((binding) => binding.call).map((binding) => {
return (
<li
Expand Down Expand Up @@ -281,12 +281,12 @@ export default class ChannelHeaderPlug extends React.PureComponent<ChannelHeader

render() {
const components = this.props.components || [];
const appBindings = this.props.shouldProcessApps ? this.props.appBindings || [] : [];
const appBindings = this.props.appsEnabled ? this.props.appBindings || [] : [];
if (components.length === 0 && appBindings.length === 0) {
return null;
} else if ((components.length + appBindings.length) <= 5) {
let componentButtons = components.filter((plug) => plug.icon && plug.action).map(this.createComponentButton);
if (this.props.shouldProcessApps) {
if (this.props.appsEnabled) {
componentButtons = componentButtons.concat(appBindings.map(this.createAppBindingButton));
}
return componentButtons;
Expand Down
8 changes: 4 additions & 4 deletions plugins/channel_header_plug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import {GenericAction} from 'mattermost-redux/types/actions';
import {doAppCall} from 'actions/apps';
import {GlobalState} from 'types/store';

import {shouldProcessApps} from 'utils/utils';
import {appsEnabled} from 'utils/utils';

import ChannelHeaderPlug from './channel_header_plug';

function mapStateToProps(state: GlobalState) {
const processApps = shouldProcessApps(state);
const apps = appsEnabled(state);
return {
components: state.plugins.components.ChannelHeaderButton || [],
appBindings: processApps ? getAppBindings(state, AppBindingLocations.CHANNEL_HEADER_ICON) : [],
shouldProcessApps: processApps,
appBindings: apps ? getAppBindings(state, AppBindingLocations.CHANNEL_HEADER_ICON) : [],
appsEnabled: apps,
theme: getTheme(state),
};
}
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ export function stringToNumber(s) {
return parseInt(s, 10);
}

export function shouldProcessApps(state) {// eslint-disable-line no-unused-vars
export function appsEnabled(state) {// eslint-disable-line no-unused-vars
// TODO uncomment when featur flag is in place
//return getConfig(state)?.['FeatureFlagApps' as keyof Partial<ClientConfig>];
return true;
Expand Down