From 513414de0440b02f994e624cb59ce5393e2b57a1 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Wed, 29 Apr 2020 05:39:17 -0700 Subject: [PATCH] Make integration of new groups simpler Summary: This diff simplifies the way new groups can be added into the Support form. Users will have to just make an entry in constants folder, thats it. It will automatically be added into the support form. Reviewed By: jknoxville Differential Revision: D21257033 fbshipit-source-id: 8823855c7a7732862a964fc17fa7311512b861db --- desktop/app/src/dispatcher/application.tsx | 24 +++---- desktop/app/src/fb-stubs/constants.tsx | 16 +++-- desktop/app/src/reducers/supportForm.tsx | 84 +++++++++------------- 3 files changed, 55 insertions(+), 69 deletions(-) diff --git a/desktop/app/src/dispatcher/application.tsx b/desktop/app/src/dispatcher/application.tsx index 27bef94fc..befd18102 100644 --- a/desktop/app/src/dispatcher/application.tsx +++ b/desktop/app/src/dispatcher/application.tsx @@ -9,12 +9,7 @@ import {remote, ipcRenderer, IpcRendererEvent} from 'electron'; import {toggleAction} from '../reducers/application'; -import { - Group, - GRAPHQL_ANDROID_GROUP, - GRAPHQL_IOS_GROUP, - LITHO_GROUP, -} from '../reducers/supportForm'; +import {Group, SUPPORTED_GROUPS} from '../reducers/supportForm'; import {Store} from '../reducers/index'; import {Logger} from '../fb-interfaces/Logger'; import {parseFlipperPorts} from '../utils/environmentVariables'; @@ -111,18 +106,15 @@ export default (store: Store, _logger: Logger) => { }, ); - function deeplinkFormParamToGroups(formParam: string | null): Group | null { + function deeplinkFormParamToGroups( + formParam: string | null, + ): Group | undefined { if (!formParam) { - return null; + return undefined; } - if (formParam.toLowerCase() === 'litho') { - return LITHO_GROUP; - } else if (formParam.toLowerCase() === 'graphql_android') { - return GRAPHQL_ANDROID_GROUP; - } else if (formParam.toLowerCase() === 'graphql_ios') { - return GRAPHQL_IOS_GROUP; - } - return null; + return SUPPORTED_GROUPS.find((grp) => { + return grp.deeplinkSuffix.toLowerCase() === formParam.toLowerCase(); + }); } ipcRenderer.on( diff --git a/desktop/app/src/fb-stubs/constants.tsx b/desktop/app/src/fb-stubs/constants.tsx index a59834750..de896b002 100644 --- a/desktop/app/src/fb-stubs/constants.tsx +++ b/desktop/app/src/fb-stubs/constants.tsx @@ -7,6 +7,8 @@ * @format */ +import {OS} from '../devices/BaseDevice'; + export default Object.freeze({ GRAPH_APP_ID: '', GRAPH_CLIENT_TOKEN: '', @@ -29,8 +31,14 @@ export default Object.freeze({ FEEDBACK_GROUP_LINK: 'https://github.com/facebook/flipper/issues', // Workplace Group ID's - LITHO_SUPPORT_GROUP_ID: 0, - GRAPHQL_ANDROID_SUPPORT_GROUP_ID: 0, - GRAPHQL_IOS_SUPPORT_GROUP_ID: 0, - COMPONENTKIT_GROUP_ID: 0, + DEFAULT_SUPPORT_GROUP: { + name: 'Default Support Group', + workplaceGroupID: 0, + requiredPlugins: ['Inspector'], + defaultPlugins: ['DeviceLogs'], + supportedOS: ['Android'] as Array, + deeplinkSuffix: 'default', + }, + + SUPPORT_GROUPS: [], }); diff --git a/desktop/app/src/reducers/supportForm.tsx b/desktop/app/src/reducers/supportForm.tsx index ce24c58bd..4ef7be6c8 100644 --- a/desktop/app/src/reducers/supportForm.tsx +++ b/desktop/app/src/reducers/supportForm.tsx @@ -26,12 +26,8 @@ import {State as PluginMessageQueueState} from '../reducers/pluginMessageQueue'; import Client from '../Client'; import {OS} from '../devices/BaseDevice'; -const { - GRAPHQL_IOS_SUPPORT_GROUP_ID, - GRAPHQL_ANDROID_SUPPORT_GROUP_ID, - LITHO_SUPPORT_GROUP_ID, - COMPONENTKIT_GROUP_ID, -} = constants; +const {DEFAULT_SUPPORT_GROUP} = constants; + type SubmediaType = | {uploadID: string; status: 'Uploaded'} | {status: 'NotUploaded' | 'Uploading'}; @@ -47,23 +43,26 @@ export type GroupValidationErrors = { export class Group { constructor( - name: GroupNames, + name: string, workplaceGroupID: number, requiredPlugins: Array, defaultPlugins: Array, supportedOS: Array, + deeplinkSuffix: string, ) { this.name = name; this.requiredPlugins = requiredPlugins; this.defaultPlugins = defaultPlugins; this.workplaceGroupID = workplaceGroupID; this.supportedOS = supportedOS; + this.deeplinkSuffix = deeplinkSuffix; } - readonly name: GroupNames; + readonly name: string; requiredPlugins: Array; defaultPlugins: Array; workplaceGroupID: number; supportedOS: Array; + deeplinkSuffix: string; getPluginsToSelect(): Array { return Array.from( @@ -252,49 +251,36 @@ export class Group { } } -export type GroupNames = - | 'Litho Support' - | 'GraphQL Android Support' - | 'GraphQL iOS Support' - | 'ComponentKit'; - -export const LITHO_GROUP = new Group( - 'Litho Support', - LITHO_SUPPORT_GROUP_ID, - ['Inspector'], - ['Sections', 'DeviceLogs'], - ['Android'], -); - -export const GRAPHQL_ANDROID_GROUP = new Group( - 'GraphQL Android Support', - GRAPHQL_ANDROID_SUPPORT_GROUP_ID, - ['GraphQL', 'Network'], - ['DeviceLogs'], - ['Android'], -); - -export const GRAPHQL_IOS_GROUP = new Group( - 'GraphQL iOS Support', - GRAPHQL_IOS_SUPPORT_GROUP_ID, - ['GraphQL', 'Network'], - ['DeviceLogs'], - ['iOS'], -); - -export const COMPONENTKIT_GROUP = new Group( - 'ComponentKit', - COMPONENTKIT_GROUP_ID, - ['Inspector'], - ['Sections', 'DeviceLogs'], - ['iOS'], +const DEFAULT_GROUP = new Group( + DEFAULT_SUPPORT_GROUP.name, + DEFAULT_SUPPORT_GROUP.workplaceGroupID, + DEFAULT_SUPPORT_GROUP.requiredPlugins, + DEFAULT_SUPPORT_GROUP.defaultPlugins, + DEFAULT_SUPPORT_GROUP.supportedOS, + DEFAULT_SUPPORT_GROUP.deeplinkSuffix, ); export const SUPPORTED_GROUPS: Array = [ - LITHO_GROUP, - GRAPHQL_ANDROID_GROUP, - GRAPHQL_IOS_GROUP, - COMPONENTKIT_GROUP, + DEFAULT_GROUP, + ...constants.SUPPORT_GROUPS.map( + ({ + name, + workplaceGroupID, + requiredPlugins, + defaultPlugins, + supportedOS, + deeplinkSuffix, + }) => { + return new Group( + name, + workplaceGroupID, + requiredPlugins, + defaultPlugins, + supportedOS, + deeplinkSuffix, + ); + }, + ), ]; export type MediaType = Array; @@ -347,7 +333,7 @@ export const initialState: () => State = () => ({ ].join('\n'), commitHash: '', appName: '', - selectedGroup: LITHO_GROUP, + selectedGroup: DEFAULT_GROUP, }, }); export default function reducer(