From 059ac83fcfcccc55879b7cd7a35fa7dbc4e877c4 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Tue, 12 Feb 2019 08:27:02 -0800 Subject: [PATCH] Do not import already imported data Summary: Before this diff, if one imported same file twice, it duplicated app data.This diff fixes that. When one tries to import the already imported file then this diff will select that flipper files device in the UI. Reviewed By: jknoxville Differential Revision: D14045145 fbshipit-source-id: f17c83486ffcdb0e2a57c70b1589e34567811d01 --- src/utils/exportData.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/utils/exportData.js b/src/utils/exportData.js index ccf7d44fb..3ec6731c4 100644 --- a/src/utils/exportData.js +++ b/src/utils/exportData.js @@ -220,13 +220,25 @@ export const importFileToStore = (file: string, store: Store) => { // During the export, Date is exported as string return {...log, date: new Date(log.date)}; }); + const {serial, deviceType, title, os} = device; const archivedDevice = new ArchivedDevice( - device.serial, - device.deviceType, - device.title, - device.os, + serial, + deviceType, + title, + os, updatedLogs, ); + const devices = store.getState().connections.devices; + const matchedDevices = devices.filter( + availableDevice => availableDevice.serial === serial, + ); + if (matchedDevices.length > 0) { + store.dispatch({ + type: 'SELECT_DEVICE', + payload: matchedDevices[0], + }); + return; + } store.dispatch({ type: 'REGISTER_DEVICE', payload: archivedDevice,