Favorite plugins are now stored per app rather than globally
Summary: This diff is a refinement of D18780965, which fixed plugin preferences to be stored per device. Instead of storing plugin preferences globally, we now store them per app, so that every app can have their own favorites, which are shared regardless the device Note that the current favorite selection will be lost. Reviewed By: nikoant Differential Revision: D19018169 fbshipit-source-id: acfa05ece8516840bb91aee4059886365b346582
This commit is contained in:
committed by
Facebook Github Bot
parent
02ad5c64aa
commit
edd894258c
@@ -228,7 +228,7 @@ type StateFromProps = {
|
|||||||
staticView: StaticView;
|
staticView: StaticView;
|
||||||
selectedPlugin: string | null | undefined;
|
selectedPlugin: string | null | undefined;
|
||||||
selectedApp: string | null | undefined;
|
selectedApp: string | null | undefined;
|
||||||
starredPlugins: Store['connections']['starredPlugins'];
|
userStarredPlugins: Store['connections']['userStarredPlugins'];
|
||||||
clients: Array<Client>;
|
clients: Array<Client>;
|
||||||
uninitializedClients: Array<{
|
uninitializedClients: Array<{
|
||||||
client: UninitializedClient;
|
client: UninitializedClient;
|
||||||
@@ -480,7 +480,7 @@ class MainSidebar extends PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
const onFavorite = (plugin: string) => {
|
const onFavorite = (plugin: string) => {
|
||||||
this.props.starPlugin({
|
this.props.starPlugin({
|
||||||
selectedApp: client.id,
|
selectedApp: client.query.app,
|
||||||
selectedPlugin: plugin,
|
selectedPlugin: plugin,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -489,7 +489,7 @@ class MainSidebar extends PureComponent<Props, State> {
|
|||||||
);
|
);
|
||||||
const favoritePlugins: FlipperPlugins = getFavoritePlugins(
|
const favoritePlugins: FlipperPlugins = getFavoritePlugins(
|
||||||
allPlugins,
|
allPlugins,
|
||||||
this.props.starredPlugins,
|
this.props.userStarredPlugins[client.query.app],
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
const showAllPlugins =
|
const showAllPlugins =
|
||||||
@@ -547,7 +547,7 @@ class MainSidebar extends PureComponent<Props, State> {
|
|||||||
client,
|
client,
|
||||||
getFavoritePlugins(
|
getFavoritePlugins(
|
||||||
allPlugins,
|
allPlugins,
|
||||||
this.props.starredPlugins,
|
this.props.userStarredPlugins[client.query.app],
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
@@ -597,9 +597,12 @@ function isStaticViewActive(
|
|||||||
|
|
||||||
function getFavoritePlugins(
|
function getFavoritePlugins(
|
||||||
allPlugins: FlipperPlugins,
|
allPlugins: FlipperPlugins,
|
||||||
starredPlugins: Props['starredPlugins'],
|
starredPlugins: undefined | string[],
|
||||||
favorite: boolean,
|
favorite: boolean,
|
||||||
): FlipperPlugins {
|
): FlipperPlugins {
|
||||||
|
if (!starredPlugins || !starredPlugins.length) {
|
||||||
|
return favorite ? [] : allPlugins;
|
||||||
|
}
|
||||||
return allPlugins.filter(plugin => {
|
return allPlugins.filter(plugin => {
|
||||||
const idx = starredPlugins.indexOf(plugin.id);
|
const idx = starredPlugins.indexOf(plugin.id);
|
||||||
return idx === -1 ? !favorite : favorite;
|
return idx === -1 ? !favorite : favorite;
|
||||||
@@ -630,7 +633,7 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
|||||||
selectedDevice,
|
selectedDevice,
|
||||||
selectedPlugin,
|
selectedPlugin,
|
||||||
selectedApp,
|
selectedApp,
|
||||||
starredPlugins,
|
userStarredPlugins,
|
||||||
clients,
|
clients,
|
||||||
uninitializedClients,
|
uninitializedClients,
|
||||||
staticView,
|
staticView,
|
||||||
@@ -649,7 +652,7 @@ export default connect<StateFromProps, DispatchFromProps, OwnProps, Store>(
|
|||||||
staticView,
|
staticView,
|
||||||
selectedPlugin,
|
selectedPlugin,
|
||||||
selectedApp,
|
selectedApp,
|
||||||
starredPlugins,
|
userStarredPlugins,
|
||||||
clients,
|
clients,
|
||||||
uninitializedClients,
|
uninitializedClients,
|
||||||
devicePlugins,
|
devicePlugins,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import NotificationScreen from '../chrome/NotificationScreen';
|
|||||||
import SupportRequestForm from '../fb-stubs/SupportRequestFormManager';
|
import SupportRequestForm from '../fb-stubs/SupportRequestFormManager';
|
||||||
import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2';
|
import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2';
|
||||||
import SupportRequestDetails from '../fb-stubs/SupportRequestDetails';
|
import SupportRequestDetails from '../fb-stubs/SupportRequestDetails';
|
||||||
|
import {produce} from 'immer';
|
||||||
|
|
||||||
export type StaticView =
|
export type StaticView =
|
||||||
| null
|
| null
|
||||||
@@ -48,7 +49,7 @@ export type State = {
|
|||||||
userPreferredDevice: null | string;
|
userPreferredDevice: null | string;
|
||||||
userPreferredPlugin: null | string;
|
userPreferredPlugin: null | string;
|
||||||
userPreferredApp: null | string;
|
userPreferredApp: null | string;
|
||||||
starredPlugins: string[];
|
userStarredPlugins: {[client: string]: string[]};
|
||||||
errors: FlipperError[];
|
errors: FlipperError[];
|
||||||
clients: Array<Client>;
|
clients: Array<Client>;
|
||||||
uninitializedClients: Array<{
|
uninitializedClients: Array<{
|
||||||
@@ -152,7 +153,7 @@ const INITAL_STATE: State = {
|
|||||||
userPreferredDevice: null,
|
userPreferredDevice: null,
|
||||||
userPreferredPlugin: null,
|
userPreferredPlugin: null,
|
||||||
userPreferredApp: null,
|
userPreferredApp: null,
|
||||||
starredPlugins: [],
|
userStarredPlugins: {},
|
||||||
errors: [],
|
errors: [],
|
||||||
clients: [],
|
clients: [],
|
||||||
uninitializedClients: [],
|
uninitializedClients: [],
|
||||||
@@ -238,18 +239,20 @@ const reducer = (state: State = INITAL_STATE, action: Actions): State => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'STAR_PLUGIN': {
|
case 'STAR_PLUGIN': {
|
||||||
const {selectedPlugin} = action.payload;
|
const {selectedPlugin, selectedApp} = action.payload;
|
||||||
const starredPlugins = state.starredPlugins.slice();
|
return produce(state, draft => {
|
||||||
const idx = starredPlugins.indexOf(selectedPlugin);
|
if (!draft.userStarredPlugins[selectedApp]) {
|
||||||
if (idx === -1) {
|
draft.userStarredPlugins[selectedApp] = [selectedPlugin];
|
||||||
starredPlugins.push(selectedPlugin);
|
} else {
|
||||||
} else {
|
const plugins = draft.userStarredPlugins[selectedApp];
|
||||||
starredPlugins.splice(idx, 1);
|
const idx = plugins.indexOf(selectedPlugin);
|
||||||
}
|
if (idx === -1) {
|
||||||
return {
|
plugins.push(selectedPlugin);
|
||||||
...state,
|
} else {
|
||||||
starredPlugins: starredPlugins,
|
plugins.splice(idx, 1);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'SELECT_USER_PREFERRED_PLUGIN': {
|
case 'SELECT_USER_PREFERRED_PLUGIN': {
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export default combineReducers<State, Actions>({
|
|||||||
'userPreferredDevice',
|
'userPreferredDevice',
|
||||||
'userPreferredPlugin',
|
'userPreferredPlugin',
|
||||||
'userPreferredApp',
|
'userPreferredApp',
|
||||||
'starredPlugins',
|
'userStarredPlugins',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
connections,
|
connections,
|
||||||
|
|||||||
Reference in New Issue
Block a user