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
This commit is contained in:
committed by
Facebook Github Bot
parent
9bc54597cf
commit
d70e512889
@@ -12,6 +12,8 @@ import electron from 'electron';
|
|||||||
import {GK} from 'flipper';
|
import {GK} from 'flipper';
|
||||||
import {remote} from 'electron';
|
import {remote} from 'electron';
|
||||||
const {dialog} = remote;
|
const {dialog} = remote;
|
||||||
|
import os from 'os';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
export type DefaultKeyboardAction = 'clear' | 'goToBottom' | 'createPaste';
|
export type DefaultKeyboardAction = 'clear' | 'goToBottom' | 'createPaste';
|
||||||
export type TopLevelMenu = 'Edit' | 'View' | 'Window' | 'Help';
|
export type TopLevelMenu = 'Edit' | 'View' | 'Window' | 'Help';
|
||||||
@@ -320,7 +322,16 @@ function getTemplate(
|
|||||||
label: 'Export Data...',
|
label: 'Export Data...',
|
||||||
role: 'export',
|
role: 'export',
|
||||||
click: function(item: Object, focusedWindow: Object) {
|
click: function(item: Object, focusedWindow: Object) {
|
||||||
exportStoreToFile(store);
|
dialog.showSaveDialog(
|
||||||
|
null,
|
||||||
|
{
|
||||||
|
title: 'FlipperExport',
|
||||||
|
defaultPath: path.join(os.homedir(), 'FlipperExport.json'),
|
||||||
|
},
|
||||||
|
file => {
|
||||||
|
exportStoreToFile(file, store);
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,16 +16,7 @@ import {default as BaseDevice} from '../devices/BaseDevice';
|
|||||||
import {default as ArchivedDevice} from '../devices/ArchivedDevice';
|
import {default as ArchivedDevice} from '../devices/ArchivedDevice';
|
||||||
import {default as Client} from '../Client';
|
import {default as Client} from '../Client';
|
||||||
import {getInstance} from '../fb-stubs/Logger.js';
|
import {getInstance} from '../fb-stubs/Logger.js';
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import os from 'os';
|
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
const exportFilePath = path.join(
|
|
||||||
os.homedir(),
|
|
||||||
'.flipper',
|
|
||||||
'FlipperExport.json',
|
|
||||||
);
|
|
||||||
|
|
||||||
export type ExportType = {|
|
export type ExportType = {|
|
||||||
fileVersion: '1.0.0',
|
fileVersion: '1.0.0',
|
||||||
@@ -138,8 +129,11 @@ export function serializeStore(state: State): ?ExportType {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const exportStoreToFile = (store: Store): Promise<void> => {
|
export const exportStoreToFile = (
|
||||||
const json = serializeStore(store.getState());
|
exportFilePath: string,
|
||||||
|
data: Store,
|
||||||
|
): Promise<void> => {
|
||||||
|
const json = serializeStore(data.getState());
|
||||||
if (json) {
|
if (json) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.writeFile(exportFilePath, JSON.stringify(json), err => {
|
fs.writeFile(exportFilePath, JSON.stringify(json), err => {
|
||||||
|
|||||||
Reference in New Issue
Block a user