From 35ddc25937d44ee73715d4292adeaee2118b7ca6 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Tue, 3 Dec 2019 09:16:06 -0800 Subject: [PATCH] Make plugin preference global Summary: This is a change which I am not fully confident in, but I think it will make things better; previously favorite plugins where stored per device. This means that when ... - switching between devices - switching between apps - when viewing disconnected devices - when loading devices from flipper traces ... the starred plugin preference would reset (especially for the last two: they have generated unique device names, so there would never be preferred items) This Diff changes the plugin preferences to be global, so on every app and every device you have the same preferences (if they support the plugin). This assumes most people work mostly with the same limited set of plugins Reviewed By: jknoxville Differential Revision: D18780965 fbshipit-source-id: 3a560393b81e7d65ae01fb737938f8562843af13 --- src/chrome/MainSidebar.tsx | 20 +++++++------------- src/reducers/connections.tsx | 21 ++++++++------------- src/reducers/index.tsx | 2 +- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/chrome/MainSidebar.tsx b/src/chrome/MainSidebar.tsx index c3d6705b6..8a93d5c87 100644 --- a/src/chrome/MainSidebar.tsx +++ b/src/chrome/MainSidebar.tsx @@ -231,7 +231,7 @@ type StateFromProps = { staticView: StaticView; selectedPlugin: string | null | undefined; selectedApp: string | null | undefined; - userStarredPlugins: Store['connections']['userStarredPlugins']; + starredPlugins: Store['connections']['starredPlugins']; clients: Array; uninitializedClients: Array<{ client: UninitializedClient; @@ -526,9 +526,8 @@ class MainSidebar extends PureComponent { (p: typeof FlipperPlugin) => client.plugins.indexOf(p.id) > -1, ); const favoritePlugins: FlipperPlugins = getFavoritePlugins( - client, allPlugins, - this.props.userStarredPlugins, + this.props.starredPlugins, true, ); const showAllPlugins = @@ -585,9 +584,8 @@ class MainSidebar extends PureComponent { ? this.renderPluginsByCategory( client, getFavoritePlugins( - client, allPlugins, - this.props.userStarredPlugins, + this.props.starredPlugins, false, ), false, @@ -601,16 +599,12 @@ class MainSidebar extends PureComponent { } function getFavoritePlugins( - client: Client, allPlugins: FlipperPlugins, - userStarredPlugins: Props['userStarredPlugins'], + starredPlugins: Props['starredPlugins'], favorite: boolean, ): FlipperPlugins { - const appName = client.id; return allPlugins.filter(plugin => { - const idx = userStarredPlugins[appName] - ? userStarredPlugins[appName].indexOf(plugin.id) - : -1; + const idx = starredPlugins.indexOf(plugin.id); return idx === -1 ? !favorite : favorite; }); } @@ -639,7 +633,7 @@ export default connect( selectedDevice, selectedPlugin, selectedApp, - userStarredPlugins, + starredPlugins, clients, uninitializedClients, staticView, @@ -658,7 +652,7 @@ export default connect( staticView, selectedPlugin, selectedApp, - userStarredPlugins, + starredPlugins, clients, uninitializedClients, devicePlugins, diff --git a/src/reducers/connections.tsx b/src/reducers/connections.tsx index a5bfcb59d..8ff145646 100644 --- a/src/reducers/connections.tsx +++ b/src/reducers/connections.tsx @@ -44,7 +44,7 @@ export type State = { userPreferredDevice: null | string; userPreferredPlugin: null | string; userPreferredApp: null | string; - userStarredPlugins: {[key: string]: Array}; + starredPlugins: string[]; errors: FlipperError[]; clients: Array; uninitializedClients: Array<{ @@ -148,7 +148,7 @@ const INITAL_STATE: State = { userPreferredDevice: null, userPreferredPlugin: null, userPreferredApp: null, - userStarredPlugins: {}, + starredPlugins: [], errors: [], clients: [], uninitializedClients: [], @@ -235,22 +235,17 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => { } case 'STAR_PLUGIN': { - const {selectedPlugin, selectedApp} = action.payload; - const starredPluginsForApp = [ - ...(state.userStarredPlugins[selectedApp] || []), - ]; - const idx = starredPluginsForApp.indexOf(selectedPlugin); + const {selectedPlugin} = action.payload; + const starredPlugins = state.starredPlugins.slice(); + const idx = starredPlugins.indexOf(selectedPlugin); if (idx === -1) { - starredPluginsForApp.push(selectedPlugin); + starredPlugins.push(selectedPlugin); } else { - starredPluginsForApp.splice(idx, 1); + starredPlugins.splice(idx, 1); } return { ...state, - userStarredPlugins: { - ...state.userStarredPlugins, - [selectedApp]: starredPluginsForApp, - }, + starredPlugins: starredPlugins, }; } diff --git a/src/reducers/index.tsx b/src/reducers/index.tsx index 09e3a0728..5dc12759b 100644 --- a/src/reducers/index.tsx +++ b/src/reducers/index.tsx @@ -102,7 +102,7 @@ export default combineReducers({ 'userPreferredDevice', 'userPreferredPlugin', 'userPreferredApp', - 'userStarredPlugins', + 'starredPlugins', ], }, connections,