From d70e512889c6012a3149ad2aa5f32592b94c76fd Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Tue, 5 Feb 2019 09:26:43 -0800 Subject: [PATCH] Show save as dialog for export data Summary: This diff adds support to specify custom location to save the flipper data to be exported Reviewed By: passy Differential Revision: D13916944 fbshipit-source-id: cfe816d07eb505d99c00f7798f3a97a2093ab265 --- src/MenuBar.js | 13 ++++++++++++- src/utils/exportData.js | 16 +++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/MenuBar.js b/src/MenuBar.js index da0e61303..d3e5c70a3 100644 --- a/src/MenuBar.js +++ b/src/MenuBar.js @@ -12,6 +12,8 @@ import electron from 'electron'; import {GK} from 'flipper'; import {remote} from 'electron'; const {dialog} = remote; +import os from 'os'; +import path from 'path'; export type DefaultKeyboardAction = 'clear' | 'goToBottom' | 'createPaste'; export type TopLevelMenu = 'Edit' | 'View' | 'Window' | 'Help'; @@ -320,7 +322,16 @@ function getTemplate( label: 'Export Data...', role: 'export', click: function(item: Object, focusedWindow: Object) { - exportStoreToFile(store); + dialog.showSaveDialog( + null, + { + title: 'FlipperExport', + defaultPath: path.join(os.homedir(), 'FlipperExport.json'), + }, + file => { + exportStoreToFile(file, store); + }, + ); }, }, { diff --git a/src/utils/exportData.js b/src/utils/exportData.js index eb0af3405..4e5c1bcf1 100644 --- a/src/utils/exportData.js +++ b/src/utils/exportData.js @@ -16,16 +16,7 @@ import {default as BaseDevice} from '../devices/BaseDevice'; import {default as ArchivedDevice} from '../devices/ArchivedDevice'; import {default as Client} from '../Client'; import {getInstance} from '../fb-stubs/Logger.js'; - import fs from 'fs'; -import os from 'os'; -import path from 'path'; - -const exportFilePath = path.join( - os.homedir(), - '.flipper', - 'FlipperExport.json', -); export type ExportType = {| fileVersion: '1.0.0', @@ -138,8 +129,11 @@ export function serializeStore(state: State): ?ExportType { ); } -export const exportStoreToFile = (store: Store): Promise => { - const json = serializeStore(store.getState()); +export const exportStoreToFile = ( + exportFilePath: string, + data: Store, +): Promise => { + const json = serializeStore(data.getState()); if (json) { return new Promise((resolve, reject) => { fs.writeFile(exportFilePath, JSON.stringify(json), err => {