From 007cdfee760fb986612d34a8da17c0630e665169 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Mon, 14 Aug 2023 11:33:06 -0700 Subject: [PATCH] Enable flipper import/export Summary: These two functions were not enabled for the browser experience. Reviewed By: antonk52 Differential Revision: D48315991 fbshipit-source-id: 2944a386d9de8a06b043305e7ceb8a6c41e11209 --- .../src/chrome/ShareSheetExportFile.tsx | 30 ++++++------- .../src/sandy-chrome/Navbar.tsx | 24 ++++------ .../flipper-ui-core/src/utils/exportData.tsx | 45 +++++-------------- 3 files changed, 34 insertions(+), 65 deletions(-) diff --git a/desktop/flipper-ui-core/src/chrome/ShareSheetExportFile.tsx b/desktop/flipper-ui-core/src/chrome/ShareSheetExportFile.tsx index ded73c4ac..0e997469e 100644 --- a/desktop/flipper-ui-core/src/chrome/ShareSheetExportFile.tsx +++ b/desktop/flipper-ui-core/src/chrome/ShareSheetExportFile.tsx @@ -13,15 +13,16 @@ import {reportPlatformFailures} from 'flipper-common'; import {Logger} from 'flipper-common'; import {IdlerImpl} from '../utils/Idler'; import { - exportStoreToFile, EXPORT_FLIPPER_TRACE_EVENT, displayFetchMetadataErrors, + exportStore, } from '../utils/exportData'; import ShareSheetErrorList from './ShareSheetErrorList'; import ShareSheetPendingDialog from './ShareSheetPendingDialog'; import {ReactReduxContext, ReactReduxContextValue} from 'react-redux'; import {MiddlewareAPI} from '../reducers/index'; import {Modal} from 'antd'; +import {getRenderHostInstance} from 'flipper-frontend-core'; const Container = styled(FlexColumn)({ padding: 20, @@ -47,7 +48,6 @@ const InfoText = styled(Text)({ type Props = { onHide: () => void; - file: string; logger: Logger; }; @@ -88,27 +88,25 @@ export default class ShareSheetExportFile extends Component { const mark = 'shareSheetExportFile'; performance.mark(mark); try { - if (!this.props.file) { - return; - } - const {fetchMetaDataErrors} = await reportPlatformFailures( - exportStoreToFile( - this.props.file, - this.store, - false, - this.idler, - (msg: string) => { + const {serializedString, fetchMetaDataErrors} = + await reportPlatformFailures( + exportStore(this.store, false, this.idler, (msg: string) => { this.setState({statusUpdate: msg}); - }, - ), - `${EXPORT_FLIPPER_TRACE_EVENT}:UI_FILE`, - ); + }), + `${EXPORT_FLIPPER_TRACE_EVENT}:UI_FILE`, + ); this.setState({ fetchMetaDataErrors, result: fetchMetaDataErrors ? {error: JSON.stringify(fetchMetaDataErrors) as any, kind: 'error'} : {kind: 'success'}, }); + + await getRenderHostInstance().exportFile(serializedString, { + defaultPath: 'export.flipper', + encoding: 'utf-8', + }); + this.props.logger.trackTimeSince(mark, 'export:file-success'); } catch (err) { const result: { diff --git a/desktop/flipper-ui-core/src/sandy-chrome/Navbar.tsx b/desktop/flipper-ui-core/src/sandy-chrome/Navbar.tsx index df30c2444..e84aff56f 100644 --- a/desktop/flipper-ui-core/src/sandy-chrome/Navbar.tsx +++ b/desktop/flipper-ui-core/src/sandy-chrome/Navbar.tsx @@ -45,11 +45,9 @@ import NetworkGraph from '../chrome/NetworkGraph'; import {errorCounterAtom} from '../chrome/ConsoleLogs'; import {filterNotifications} from './notification/notificationUtils'; import { - canFileExport, - canOpenDialog, exportEverythingEverywhereAllAtOnce, ExportEverythingEverywhereAllAtOnceStatus, - showOpenDialog, + startFileImport, startFileExport, startLinkExport, } from '../utils/exportData'; @@ -591,9 +589,9 @@ function ExtrasMenu() { () => startLinkExport(store.dispatch), [store.dispatch], ); - const startImportTracked = useTrackedCallback( + const startFileImportTracked = useTrackedCallback( 'File import', - () => showOpenDialog(store), + () => startFileImport(store), [store], ); @@ -627,16 +625,12 @@ function ExtrasMenu() { }}> Add Plugins - {canOpenDialog() ? ( - - Import Flipper file - - ) : null} - {canFileExport() ? ( - - Export Flipper file - - ) : null} + + Import Flipper file + + + Export Flipper file + {constants.ENABLE_SHAREABLE_LINK ? ( { } }; -export function canOpenDialog() { - return !!getRenderHostInstance().showOpenDialog; -} - -export function showOpenDialog(store: Store) { - return getRenderHostInstance() - .showOpenDialog?.({ - filter: {extensions: ['flipper', 'json', 'txt'], name: 'Flipper files'}, - }) - .then((filePath) => { - if (filePath) { - tryCatchReportPlatformFailures(() => { - importFileToStore(filePath, store); - }, `${IMPORT_FLIPPER_TRACE_EVENT}:UI`); - } - }); -} - -export function canFileExport() { - return !!getRenderHostInstance().showSaveDialog; +export async function startFileImport(store: Store) { + const file = await getRenderHostInstance().importFile({ + extensions: ['flipper', 'json', 'txt'], + }); + if (!file || typeof file.data !== 'string') { + return; + } + importDataToStore(file.name, file.data as string, store); } async function startDeviceFlipperFolderExport() { @@ -765,25 +752,15 @@ export async function exportEverythingEverywhereAllAtOnce( } export async function startFileExport(dispatch: Store['dispatch']) { - const file = await getRenderHostInstance().showSaveDialog?.({ - title: 'FlipperExport', - defaultPath: path.join( - getRenderHostInstance().serverConfig.paths.homePath, - 'FlipperExport.flipper', - ), - }); - if (!file) { - return; - } const plugins = await selectPlugins(); if (plugins === false) { - return; // cancelled + return; } // TODO: no need to put this in the store, - // need to be cleaned up later in combination with SupportForm + // need to be cleaned up later in combination with SupportForm. dispatch(selectedPlugins(plugins)); Dialog.showModal((onHide) => ( - + )); }