From 4ad7a70ee3f73f642de4b34f45d3d5016b90c720 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Tue, 29 Jun 2021 13:00:18 -0700 Subject: [PATCH] Differentiate enabled and disabled selected plugins in analytics Summary: As we now allow selection of disabled plugins we need to track plugin usage a bit smarter. We'll add a new field "pluginEnabled" to the logged messages to indicate whether selected plugin is enabled or not. Reviewed By: cekkaewnumchai Differential Revision: D29455248 fbshipit-source-id: 32c79e0961653edc8f4cc89adecc2662b37cbd7b --- .../dispatcher/__tests__/tracking.node.tsx | 1 + desktop/app/src/dispatcher/tracking.tsx | 11 +--- desktop/app/src/utils/__tests__/info.node.tsx | 2 + desktop/app/src/utils/info.tsx | 50 ++++++++++++------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/desktop/app/src/dispatcher/__tests__/tracking.node.tsx b/desktop/app/src/dispatcher/__tests__/tracking.node.tsx index c1fcb6939..2806cc307 100644 --- a/desktop/app/src/dispatcher/__tests__/tracking.node.tsx +++ b/desktop/app/src/dispatcher/__tests__/tracking.node.tsx @@ -15,6 +15,7 @@ const layoutSelection: SelectionInfo = { plugin: 'Layout', pluginName: 'flipper-plugin-layout', pluginVersion: '0.0.0', + pluginEnabled: true, app: 'Facebook', device: 'test device', deviceName: 'test device', diff --git a/desktop/app/src/dispatcher/tracking.tsx b/desktop/app/src/dispatcher/tracking.tsx index 9057fed03..a8ddb2d29 100644 --- a/desktop/app/src/dispatcher/tracking.tsx +++ b/desktop/app/src/dispatcher/tracking.tsx @@ -84,15 +84,8 @@ export default (store: Store, logger: Logger) => { noTimeBudgetWarns: true, runSynchronously: true, }, - (state) => ({ - connections: state.connections, - loadedPlugins: state.plugins.loadedPlugins, - }), - (state, store) => { - const selection = getSelectionInfo( - state.connections, - state.loadedPlugins, - ); + getSelectionInfo, + (selection, store) => { const time = Date.now(); store.dispatch(selectionChanged({selection, time})); }, diff --git a/desktop/app/src/utils/__tests__/info.node.tsx b/desktop/app/src/utils/__tests__/info.node.tsx index 46f4fe688..1ed89f957 100644 --- a/desktop/app/src/utils/__tests__/info.node.tsx +++ b/desktop/app/src/utils/__tests__/info.node.tsx @@ -88,6 +88,7 @@ describe('info', () => { "deviceType": "physical", "os": "Android", "plugin": "Network", + "pluginEnabled": true, "pluginName": "flipper-plugin-network", "pluginVersion": "0.78.0", } @@ -102,6 +103,7 @@ describe('info', () => { "deviceType": "physical", "os": "Android", "plugin": "Inspector", + "pluginEnabled": true, "pluginName": "flipper-plugin-inspector", "pluginVersion": "0.59.0", } diff --git a/desktop/app/src/utils/info.tsx b/desktop/app/src/utils/info.tsx index 0e85cabb2..843a72746 100644 --- a/desktop/app/src/utils/info.tsx +++ b/desktop/app/src/utils/info.tsx @@ -29,6 +29,7 @@ export type SelectionInfo = { plugin: string | null; pluginName: string | null; pluginVersion: string | null; + pluginEnabled: boolean | null; app: string | null; os: string | null; device: string | null; @@ -47,6 +48,7 @@ let selection: SelectionInfo = { plugin: null, pluginName: null, pluginVersion: null, + pluginEnabled: null, app: null, os: null, device: null, @@ -66,12 +68,9 @@ export default (store: Store, _logger: Logger) => { runSynchronously: true, fireImmediately: true, }, - (state) => ({ - connections: state.connections, - loadedPlugins: state.plugins.loadedPlugins, - }), - (state, _store) => { - selection = getSelectionInfo(state.connections, state.loadedPlugins); + getSelectionInfo, + (newSelection, _store) => { + selection = newSelection; }, ); }; @@ -127,25 +126,38 @@ export function stringifyInfo(info: Info): string { return lines.join('\n'); } -export function getSelectionInfo( - connections: State['connections'], - loadedPlugins: State['plugins']['loadedPlugins'], -): SelectionInfo { - const selectedApp = connections.selectedApp; +export function getSelectionInfo({ + plugins: {clientPlugins, devicePlugins, loadedPlugins}, + connections: { + selectedApp, + selectedPlugin, + enabledDevicePlugins, + enabledPlugins, + selectedDevice, + }, +}: State): SelectionInfo { const clientIdParts = selectedApp ? deconstructClientId(selectedApp) : null; - const loadedPlugin = connections.selectedPlugin - ? loadedPlugins.get(connections.selectedPlugin) + const loadedPlugin = selectedPlugin + ? loadedPlugins.get(selectedPlugin) : null; + const pluginEnabled = + !!selectedPlugin && + ((enabledDevicePlugins.has(selectedPlugin) && + devicePlugins.has(selectedPlugin)) || + (clientIdParts && + enabledPlugins[clientIdParts.app]?.includes(selectedPlugin) && + clientPlugins.has(selectedPlugin))); return { - plugin: connections.selectedPlugin || null, + plugin: selectedPlugin || null, pluginName: loadedPlugin?.name || null, pluginVersion: loadedPlugin?.version || null, + pluginEnabled, app: clientIdParts?.app || null, - device: connections.selectedDevice?.title || null, + device: selectedDevice?.title || null, deviceName: clientIdParts?.device || null, - deviceSerial: connections.selectedDevice?.serial || null, - deviceType: connections.selectedDevice?.deviceType || null, - os: connections.selectedDevice?.os || null, - archived: connections.selectedDevice?.isArchived || false, + deviceSerial: selectedDevice?.serial || null, + deviceType: selectedDevice?.deviceType || null, + os: selectedDevice?.os || null, + archived: selectedDevice?.isArchived || false, }; }