From c3dfcbe6013dcc6fbed616124101962e36c44d68 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Wed, 11 Dec 2019 06:25:54 -0800 Subject: [PATCH] Show the plugins from the redux store only belonging to the selected app Summary: It fixes the bug, where currently we show all active persistent plugins for the export functionality irrespective of the fact that the plugin is active for the selected client. With this diff we will only show active persistent plugins for the selected client. Reviewed By: mweststrate Differential Revision: D18890247 fbshipit-source-id: e567da0ccf04e051ca0eabb497a6bd72cc8a0d76 --- src/chrome/ExportDataPluginSheet.tsx | 34 +++++++++++++++++------ src/reducers/plugins.tsx | 1 - src/utils/pluginUtils.tsx | 41 +++++++++++++++++++++------- 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/src/chrome/ExportDataPluginSheet.tsx b/src/chrome/ExportDataPluginSheet.tsx index dc04123b2..bc118f995 100644 --- a/src/chrome/ExportDataPluginSheet.tsx +++ b/src/chrome/ExportDataPluginSheet.tsx @@ -25,6 +25,8 @@ import ListView from './ListView'; import {Dispatch, Action} from 'redux'; import {unsetShare} from '../reducers/application'; import {FlexColumn, styled} from 'flipper'; +import Client from '../Client'; + type OwnProps = { onHide: () => void; }; @@ -33,6 +35,7 @@ type StateFromProps = { share: ShareType | null; plugins: PluginState; pluginStates: PluginStatesState; + selectedClient: Client | undefined; }; type DispatchFromProps = { @@ -54,11 +57,16 @@ const Container = styled(FlexColumn)({ class ExportDataPluginSheet extends Component { render() { - const {plugins, pluginStates, onHide} = this.props; + const {plugins, pluginStates, onHide, selectedClient} = this.props; const onHideWithUnsettingShare = () => { this.props.unsetShare(); onHide(); }; + const pluginsToExport = getActivePersistentPlugins( + pluginStates, + plugins, + selectedClient, + ); return ( { } } }} - elements={getActivePersistentPlugins(pluginStates, plugins)} - selectedElements={getActivePersistentPlugins( - pluginStates, - plugins, - ).reduce((acc, plugin) => { + elements={pluginsToExport} + selectedElements={pluginsToExport.reduce((acc, plugin) => { if ( plugins.selectedPlugins.length <= 0 || plugins.selectedPlugins.includes(plugin) @@ -112,11 +117,22 @@ class ExportDataPluginSheet extends Component { } export default connect( - ({application: {share}, plugins, pluginStates}) => ({ - share, + ({ + application: {share}, plugins, pluginStates, - }), + connections: {selectedApp, clients}, + }) => { + const selectedClient = clients.find(o => { + return o.id === selectedApp; + }); + return { + share, + plugins, + pluginStates, + selectedClient, + }; + }, (dispatch: Dispatch>) => ({ selectedPlugins: (plugins: Array) => { dispatch(actionForSelectedPlugins(plugins)); diff --git a/src/reducers/plugins.tsx b/src/reducers/plugins.tsx index 3734ba227..2846e6629 100644 --- a/src/reducers/plugins.tsx +++ b/src/reducers/plugins.tsx @@ -73,7 +73,6 @@ export default function reducer( clientPlugins.set(p.id, p); } }); - return { ...state, devicePlugins, diff --git a/src/utils/pluginUtils.tsx b/src/utils/pluginUtils.tsx index 21d405ac0..c9a79d5e2 100644 --- a/src/utils/pluginUtils.tsx +++ b/src/utils/pluginUtils.tsx @@ -14,6 +14,7 @@ import {pluginsClassMap} from './exportData'; import {State as PluginsState} from '../reducers/plugins'; import {PluginDefinition} from '../dispatcher/plugins'; import {deconstructPluginKey} from './clientUtils'; +import Client from '../Client'; export function getPluginKey( selectedApp: string | null, @@ -46,24 +47,44 @@ export function getPersistedState( return persistedState; } +/** + * + * @param pluginsState PluginsState of the Redux Store. + * @param plugins Plugins from the state which has the mapping to Plugin's Class. + * @param selectedClient Optional paramater indicating the selected client. + * Returns active persistent plugin, which means plugins which has the data in redux store or has the `exportPersistedState` function defined which can return the plugin's data when called. + * If the selectedClient is defined then the active persistent plugins only for the selectedClient will be returned, otherwise it will return all active persistent plugins. + */ export function getActivePersistentPlugins( pluginsState: PluginStatesState, plugins: PluginsState, + selectedClient?: Client, ): Array { const pluginsMap: Map< string, typeof FlipperDevicePlugin | typeof FlipperPlugin > = pluginsClassMap(plugins); - return getPersistentPlugins(plugins).filter(pluginName => { - const pluginClass = pluginsMap.get(pluginName); - const pluginNames = Object.keys(pluginsState).map( - pluginKey => deconstructPluginKey(pluginKey).pluginName, - ); - return ( - (pluginClass && pluginClass.exportPersistedState != undefined) || - pluginName == 'DeviceLogs' || - pluginNames.includes(pluginName) - ); + return getPersistentPlugins(plugins).filter(plugin => { + const pluginClass = pluginsMap.get(plugin); + const keys = Object.keys(pluginsState) + .filter(k => !selectedClient || k.includes(selectedClient.id)) + .map(key => deconstructPluginKey(key).pluginName); + let result = plugin == 'DeviceLogs'; + const pluginsWithExportPersistedState = + pluginClass && pluginClass.exportPersistedState != undefined; + const pluginsWithReduxData = keys.includes(plugin); + if (!result && selectedClient) { + // If there is a selected client, active persistent plugin is the plugin which is active for selectedClient and also persistent. + result = + selectedClient.plugins.includes(plugin) && + (pluginsWithExportPersistedState || pluginsWithReduxData); + } else if (!result && !selectedClient) { + // If there is no selected client, active persistent plugin is the plugin which is just persistent. + result = + (pluginClass && pluginClass.exportPersistedState != undefined) || + keys.includes(plugin); + } + return result; }); }