Refactor the default plugins and validation logic into Group object
Summary: This diff refactors the scattered logic of required plugins and default selection of the plugins into Group class. Also the same class handles the deeplink logic. Reviewed By: mweststrate Differential Revision: D19666745 fbshipit-source-id: c9427f0ddba643f0b32aac7b6f2496e2e3248b12
This commit is contained in:
committed by
Facebook Github Bot
parent
9369033d99
commit
670949b016
@@ -9,26 +9,23 @@
|
||||
|
||||
import {remote, ipcRenderer, IpcRendererEvent} from 'electron';
|
||||
import {toggleAction} from '../reducers/application';
|
||||
import {setStaticView} from '../reducers/connections';
|
||||
import {selectedPlugins as setSelectedPlugins} from '../reducers/plugins';
|
||||
import {starPlugin as setStarPlugin} from '../reducers/connections';
|
||||
import {setSupportFormV2State, Groups} from '../reducers/supportForm';
|
||||
import {addStatusMessage, removeStatusMessage} from '../reducers/application';
|
||||
import {
|
||||
Group,
|
||||
GRAPHQL_ANDROID_GROUP,
|
||||
GRAPHQL_IOS_GROUP,
|
||||
LITHO_GROUP,
|
||||
} from '../reducers/supportForm';
|
||||
import {Store} from '../reducers/index.js';
|
||||
import {Logger} from '../fb-interfaces/Logger';
|
||||
import {parseFlipperPorts} from '../utils/environmentVariables';
|
||||
import SupportRequestFormV2 from '../fb-stubs/SupportRequestFormV2';
|
||||
import {
|
||||
importDataToStore,
|
||||
importFileToStore,
|
||||
IMPORT_FLIPPER_TRACE_EVENT,
|
||||
} from '../utils/exportData';
|
||||
import {tryCatchReportPlatformFailures} from '../utils/metrics';
|
||||
import {deconstructClientId} from '../utils/clientUtils';
|
||||
import {defaultSelectedPluginsForGroup} from '../fb-stubs/utils/supportForm';
|
||||
import {selectPlugin} from '../reducers/connections';
|
||||
import qs from 'query-string';
|
||||
import {showStatusUpdatesForDuration} from '../utils/promiseTimeout';
|
||||
|
||||
export const uriComponents = (url: string): Array<string> => {
|
||||
if (!url) {
|
||||
@@ -97,9 +94,9 @@ export default (store: Store, logger: Logger) => {
|
||||
uri.pathname.includes('support-form')
|
||||
) {
|
||||
const formParam = uri.searchParams.get('form');
|
||||
const grps = deeplinkFormParamToGroups(formParam);
|
||||
if (grps) {
|
||||
handleSupportFormDeeplinks(grps);
|
||||
const grp = deeplinkFormParamToGroups(formParam);
|
||||
if (grp) {
|
||||
grp.handleSupportFormDeeplinks(store);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -117,88 +114,20 @@ export default (store: Store, logger: Logger) => {
|
||||
},
|
||||
);
|
||||
|
||||
function deeplinkFormParamToGroups(formParam: string | null): Groups | null {
|
||||
function deeplinkFormParamToGroups(formParam: string | null): Group | null {
|
||||
if (!formParam) {
|
||||
return null;
|
||||
}
|
||||
if (formParam.toLowerCase() === 'litho') {
|
||||
return 'Litho Support';
|
||||
return LITHO_GROUP;
|
||||
} else if (formParam.toLowerCase() === 'graphql_android') {
|
||||
return 'GraphQL Android Support';
|
||||
return GRAPHQL_ANDROID_GROUP;
|
||||
} else if (formParam.toLowerCase() === 'graphql_ios') {
|
||||
return 'GraphQL iOS Support';
|
||||
return GRAPHQL_IOS_GROUP;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function handleSupportFormDeeplinks(grp: Groups) {
|
||||
logger.track('usage', 'support-form-source', {source: 'deeplink'});
|
||||
// TODO: Incorporate grp info in analytics.
|
||||
store.dispatch(setStaticView(SupportRequestFormV2));
|
||||
const selectedApp = store.getState().connections.selectedApp;
|
||||
if (
|
||||
(grp === 'GraphQL Android Support' || grp === 'GraphQL iOS Support') &&
|
||||
selectedApp
|
||||
) {
|
||||
// Enable GraphQL plugin if grp to be posted is the GraphQL one.
|
||||
// TODO: Handle the case where GraphQL plugin is not supported by Client
|
||||
const {app} = deconstructClientId(selectedApp);
|
||||
const selectedClient = store
|
||||
.getState()
|
||||
.connections.clients.find(client => client.id === selectedApp);
|
||||
const enabledPlugins: Array<string> | null = store.getState().connections
|
||||
.userStarredPlugins[app];
|
||||
const graphQLEnabled =
|
||||
enabledPlugins != null && enabledPlugins.includes('GraphQL');
|
||||
if (
|
||||
selectedClient &&
|
||||
selectedClient.plugins.includes('GraphQL') &&
|
||||
!graphQLEnabled
|
||||
) {
|
||||
store.dispatch(
|
||||
setStarPlugin({
|
||||
selectedApp: app,
|
||||
selectedPlugin: 'GraphQL',
|
||||
}),
|
||||
);
|
||||
} else if (
|
||||
!selectedClient ||
|
||||
!selectedClient.plugins.includes('GraphQL')
|
||||
) {
|
||||
showStatusUpdatesForDuration(
|
||||
'The current client does not support GraphQL plugin. Please change the app from the dropdown in the support form',
|
||||
'Deeplink',
|
||||
10000,
|
||||
payload => {
|
||||
store.dispatch(addStatusMessage(payload));
|
||||
},
|
||||
payload => {
|
||||
store.dispatch(removeStatusMessage(payload));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
store.dispatch(
|
||||
setSupportFormV2State({
|
||||
...store.getState().supportForm.supportFormV2,
|
||||
selectedGroup: grp,
|
||||
}),
|
||||
);
|
||||
const selectedClient = store.getState().connections.clients.find(o => {
|
||||
return o.id === store.getState().connections.selectedApp;
|
||||
});
|
||||
store.dispatch(
|
||||
setSelectedPlugins(
|
||||
defaultSelectedPluginsForGroup(
|
||||
grp,
|
||||
store.getState().plugins,
|
||||
selectedClient,
|
||||
store.getState().connections.userStarredPlugins,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ipcRenderer.on(
|
||||
'open-flipper-file',
|
||||
(_event: IpcRendererEvent, url: string) => {
|
||||
|
||||
Reference in New Issue
Block a user