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
This commit is contained in:
Michel Weststrate
2019-12-03 09:16:06 -08:00
committed by Facebook Github Bot
parent c332f4145a
commit 35ddc25937
3 changed files with 16 additions and 27 deletions

View File

@@ -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<Client>;
uninitializedClients: Array<{
client: UninitializedClient;
@@ -526,9 +526,8 @@ class MainSidebar extends PureComponent<Props, State> {
(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<Props, State> {
? this.renderPluginsByCategory(
client,
getFavoritePlugins(
client,
allPlugins,
this.props.userStarredPlugins,
this.props.starredPlugins,
false,
),
false,
@@ -601,16 +599,12 @@ class MainSidebar extends PureComponent<Props, State> {
}
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<StateFromProps, DispatchFromProps, OwnProps, Store>(
selectedDevice,
selectedPlugin,
selectedApp,
userStarredPlugins,
starredPlugins,
clients,
uninitializedClients,
staticView,
@@ -658,7 +652,7 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
staticView,
selectedPlugin,
selectedApp,
userStarredPlugins,
starredPlugins,
clients,
uninitializedClients,
devicePlugins,

View File

@@ -44,7 +44,7 @@ export type State = {
userPreferredDevice: null | string;
userPreferredPlugin: null | string;
userPreferredApp: null | string;
userStarredPlugins: {[key: string]: Array<string>};
starredPlugins: string[];
errors: FlipperError[];
clients: Array<Client>;
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,
};
}

View File

@@ -102,7 +102,7 @@ export default combineReducers<State, Actions>({
'userPreferredDevice',
'userPreferredPlugin',
'userPreferredApp',
'userStarredPlugins',
'starredPlugins',
],
},
connections,