From 5d25b77622e19b761bc7e02d27eed660011387b3 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 2 Jan 2020 07:12:06 -0800 Subject: [PATCH] Bug: cannot export data / submit bug without selected device / client Summary: Without selected device or client, it is currently impossible to submit a bug report. This diff fixes that. Reviewed By: jknoxville Differential Revision: D19251701 fbshipit-source-id: fd0dc0c779fb27d93ed02a404da76a7e6b251b94 --- src/utils/exportData.tsx | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/utils/exportData.tsx b/src/utils/exportData.tsx index 2b4ec52c4..adba26598 100644 --- a/src/utils/exportData.tsx +++ b/src/utils/exportData.tsx @@ -469,23 +469,14 @@ async function processQueues( function getSelection( store: MiddlewareAPI, -): {client: Client; device: BaseDevice} { +): {client: Client | null; device: BaseDevice | null} { const state = store.getState(); const {clients} = state.connections; const client = clients.find( client => client.id === state.connections.selectedApp, ); const {selectedDevice} = state.connections; - // TODO: T59434642 remove these restrictions - if (!selectedDevice) { - throw new Error('Please select a device before exporting data.'); - } - // TODO: T39612653 Make Client mockable. Currently rsocket logic is tightly coupled. - // Not passing the entire state as currently Client is not mockable. - if (!client) { - throw new Error('Please select a client before exporting data.'); - } - return {client, device: selectedDevice}; + return {client: client ?? null, device: selectedDevice}; } export function determinePluginsToProcess( @@ -498,10 +489,11 @@ export function determinePluginsToProcess( const pluginsToProcess: PluginsToProcess = []; const selectedPlugins = state.plugins.selectedPlugins; - const selectedFilteredPlugins = - selectedPlugins.length > 0 + const selectedFilteredPlugins = client + ? selectedPlugins.length > 0 ? client.plugins.filter(plugin => selectedPlugins.includes(plugin)) - : client.plugins; + : client.plugins + : []; for (const client of clients) { if (!device || device.isArchived || !client.id.includes(device.serial)) { continue; @@ -560,7 +552,7 @@ export async function getStoreExport( activeNotifications, device, pluginStates: newPluginState, - clients: [client.toJSON()], + clients: client ? [client.toJSON()] : [], devicePlugins, clientPlugins, salt: uuid.v4(), @@ -609,8 +601,7 @@ export async function exportStore( ); return {serializedString, errorArray}; } else { - console.error('Make sure a device is connected'); - throw new Error('No device is selected'); + return {serializedString: '{}', errorArray: []}; } }