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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ff6f98fc0d
commit
007cdfee76
@@ -13,15 +13,16 @@ import {reportPlatformFailures} from 'flipper-common';
|
|||||||
import {Logger} from 'flipper-common';
|
import {Logger} from 'flipper-common';
|
||||||
import {IdlerImpl} from '../utils/Idler';
|
import {IdlerImpl} from '../utils/Idler';
|
||||||
import {
|
import {
|
||||||
exportStoreToFile,
|
|
||||||
EXPORT_FLIPPER_TRACE_EVENT,
|
EXPORT_FLIPPER_TRACE_EVENT,
|
||||||
displayFetchMetadataErrors,
|
displayFetchMetadataErrors,
|
||||||
|
exportStore,
|
||||||
} from '../utils/exportData';
|
} from '../utils/exportData';
|
||||||
import ShareSheetErrorList from './ShareSheetErrorList';
|
import ShareSheetErrorList from './ShareSheetErrorList';
|
||||||
import ShareSheetPendingDialog from './ShareSheetPendingDialog';
|
import ShareSheetPendingDialog from './ShareSheetPendingDialog';
|
||||||
import {ReactReduxContext, ReactReduxContextValue} from 'react-redux';
|
import {ReactReduxContext, ReactReduxContextValue} from 'react-redux';
|
||||||
import {MiddlewareAPI} from '../reducers/index';
|
import {MiddlewareAPI} from '../reducers/index';
|
||||||
import {Modal} from 'antd';
|
import {Modal} from 'antd';
|
||||||
|
import {getRenderHostInstance} from 'flipper-frontend-core';
|
||||||
|
|
||||||
const Container = styled(FlexColumn)({
|
const Container = styled(FlexColumn)({
|
||||||
padding: 20,
|
padding: 20,
|
||||||
@@ -47,7 +48,6 @@ const InfoText = styled(Text)({
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onHide: () => void;
|
onHide: () => void;
|
||||||
file: string;
|
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -88,27 +88,25 @@ export default class ShareSheetExportFile extends Component<Props, State> {
|
|||||||
const mark = 'shareSheetExportFile';
|
const mark = 'shareSheetExportFile';
|
||||||
performance.mark(mark);
|
performance.mark(mark);
|
||||||
try {
|
try {
|
||||||
if (!this.props.file) {
|
const {serializedString, fetchMetaDataErrors} =
|
||||||
return;
|
await reportPlatformFailures(
|
||||||
}
|
exportStore(this.store, false, this.idler, (msg: string) => {
|
||||||
const {fetchMetaDataErrors} = await reportPlatformFailures(
|
|
||||||
exportStoreToFile(
|
|
||||||
this.props.file,
|
|
||||||
this.store,
|
|
||||||
false,
|
|
||||||
this.idler,
|
|
||||||
(msg: string) => {
|
|
||||||
this.setState({statusUpdate: msg});
|
this.setState({statusUpdate: msg});
|
||||||
},
|
}),
|
||||||
),
|
`${EXPORT_FLIPPER_TRACE_EVENT}:UI_FILE`,
|
||||||
`${EXPORT_FLIPPER_TRACE_EVENT}:UI_FILE`,
|
);
|
||||||
);
|
|
||||||
this.setState({
|
this.setState({
|
||||||
fetchMetaDataErrors,
|
fetchMetaDataErrors,
|
||||||
result: fetchMetaDataErrors
|
result: fetchMetaDataErrors
|
||||||
? {error: JSON.stringify(fetchMetaDataErrors) as any, kind: 'error'}
|
? {error: JSON.stringify(fetchMetaDataErrors) as any, kind: 'error'}
|
||||||
: {kind: 'success'},
|
: {kind: 'success'},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await getRenderHostInstance().exportFile(serializedString, {
|
||||||
|
defaultPath: 'export.flipper',
|
||||||
|
encoding: 'utf-8',
|
||||||
|
});
|
||||||
|
|
||||||
this.props.logger.trackTimeSince(mark, 'export:file-success');
|
this.props.logger.trackTimeSince(mark, 'export:file-success');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const result: {
|
const result: {
|
||||||
|
|||||||
@@ -45,11 +45,9 @@ import NetworkGraph from '../chrome/NetworkGraph';
|
|||||||
import {errorCounterAtom} from '../chrome/ConsoleLogs';
|
import {errorCounterAtom} from '../chrome/ConsoleLogs';
|
||||||
import {filterNotifications} from './notification/notificationUtils';
|
import {filterNotifications} from './notification/notificationUtils';
|
||||||
import {
|
import {
|
||||||
canFileExport,
|
|
||||||
canOpenDialog,
|
|
||||||
exportEverythingEverywhereAllAtOnce,
|
exportEverythingEverywhereAllAtOnce,
|
||||||
ExportEverythingEverywhereAllAtOnceStatus,
|
ExportEverythingEverywhereAllAtOnceStatus,
|
||||||
showOpenDialog,
|
startFileImport,
|
||||||
startFileExport,
|
startFileExport,
|
||||||
startLinkExport,
|
startLinkExport,
|
||||||
} from '../utils/exportData';
|
} from '../utils/exportData';
|
||||||
@@ -591,9 +589,9 @@ function ExtrasMenu() {
|
|||||||
() => startLinkExport(store.dispatch),
|
() => startLinkExport(store.dispatch),
|
||||||
[store.dispatch],
|
[store.dispatch],
|
||||||
);
|
);
|
||||||
const startImportTracked = useTrackedCallback(
|
const startFileImportTracked = useTrackedCallback(
|
||||||
'File import',
|
'File import',
|
||||||
() => showOpenDialog(store),
|
() => startFileImport(store),
|
||||||
[store],
|
[store],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -627,16 +625,12 @@ function ExtrasMenu() {
|
|||||||
}}>
|
}}>
|
||||||
Add Plugins
|
Add Plugins
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
{canOpenDialog() ? (
|
<Menu.Item key="importFlipperFile" onClick={startFileImportTracked}>
|
||||||
<Menu.Item key="importFlipperFile" onClick={startImportTracked}>
|
Import Flipper file
|
||||||
Import Flipper file
|
</Menu.Item>
|
||||||
</Menu.Item>
|
<Menu.Item key="exportFlipperFile" onClick={startFileExportTracked}>
|
||||||
) : null}
|
Export Flipper file
|
||||||
{canFileExport() ? (
|
</Menu.Item>
|
||||||
<Menu.Item key="exportFile" onClick={startFileExportTracked}>
|
|
||||||
Export Flipper file
|
|
||||||
</Menu.Item>
|
|
||||||
) : null}
|
|
||||||
{constants.ENABLE_SHAREABLE_LINK ? (
|
{constants.ENABLE_SHAREABLE_LINK ? (
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
key="exportShareableLink"
|
key="exportShareableLink"
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import {DevicePluginMap, ClientPluginMap} from '../plugin';
|
|||||||
import {BaseDevice} from 'flipper-frontend-core';
|
import {BaseDevice} from 'flipper-frontend-core';
|
||||||
import {ArchivedDevice} from 'flipper-frontend-core';
|
import {ArchivedDevice} from 'flipper-frontend-core';
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
import {tryCatchReportPlatformFailures} from 'flipper-common';
|
|
||||||
import {TestIdler} from './Idler';
|
import {TestIdler} from './Idler';
|
||||||
import {processMessageQueue} from './messageQueue';
|
import {processMessageQueue} from './messageQueue';
|
||||||
import {getPluginTitle} from './pluginUtils';
|
import {getPluginTitle} from './pluginUtils';
|
||||||
@@ -594,26 +593,14 @@ export const importFileToStore = async (file: string, store: Store) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function canOpenDialog() {
|
export async function startFileImport(store: Store) {
|
||||||
return !!getRenderHostInstance().showOpenDialog;
|
const file = await getRenderHostInstance().importFile({
|
||||||
}
|
extensions: ['flipper', 'json', 'txt'],
|
||||||
|
});
|
||||||
export function showOpenDialog(store: Store) {
|
if (!file || typeof file.data !== 'string') {
|
||||||
return getRenderHostInstance()
|
return;
|
||||||
.showOpenDialog?.({
|
}
|
||||||
filter: {extensions: ['flipper', 'json', 'txt'], name: 'Flipper files'},
|
importDataToStore(file.name, file.data as string, store);
|
||||||
})
|
|
||||||
.then((filePath) => {
|
|
||||||
if (filePath) {
|
|
||||||
tryCatchReportPlatformFailures(() => {
|
|
||||||
importFileToStore(filePath, store);
|
|
||||||
}, `${IMPORT_FLIPPER_TRACE_EVENT}:UI`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function canFileExport() {
|
|
||||||
return !!getRenderHostInstance().showSaveDialog;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startDeviceFlipperFolderExport() {
|
async function startDeviceFlipperFolderExport() {
|
||||||
@@ -765,25 +752,15 @@ export async function exportEverythingEverywhereAllAtOnce(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function startFileExport(dispatch: Store['dispatch']) {
|
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();
|
const plugins = await selectPlugins();
|
||||||
if (plugins === false) {
|
if (plugins === false) {
|
||||||
return; // cancelled
|
return;
|
||||||
}
|
}
|
||||||
// TODO: no need to put this in the store,
|
// 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));
|
dispatch(selectedPlugins(plugins));
|
||||||
Dialog.showModal((onHide) => (
|
Dialog.showModal((onHide) => (
|
||||||
<ShareSheetExportFile onHide={onHide} file={file} logger={getLogger()} />
|
<ShareSheetExportFile onHide={onHide} logger={getLogger()} />
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user