Skip to content

Commit

Permalink
Flipper export file implementation
Browse files Browse the repository at this point in the history
Summary:
^

Changelog: add export file implementation for browsers

Reviewed By: antonk52

Differential Revision: D46840341

fbshipit-source-id: 8a011f2a7c0ce329286cb8813def8f9c0572d133
  • Loading branch information
lblasa authored and facebook-github-bot committed Jun 19, 2023
1 parent f0ccad9 commit daa3a38
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
2 changes: 2 additions & 0 deletions desktop/flipper-ui-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"license": "MIT",
"bugs": "https://github.com/facebook/flipper/issues",
"dependencies": {
"file-saver": "^2.0.5",
"reconnecting-websocket": "^4.4.0"
},
"devDependencies": {
"@types/file-saver": "^2.0.5",
"eventemitter3": "^4.0.7",
"flipper-common": "0.0.0",
"flipper-frontend-core": "0.0.0",
Expand Down
20 changes: 16 additions & 4 deletions desktop/flipper-ui-browser/src/initializeRenderHost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
wrapRequire,
} from 'flipper-common';
import type {RenderHost} from 'flipper-ui-core';
import FileSaver from 'file-saver';

declare module globalThis {
let require: any;
Expand Down Expand Up @@ -44,11 +45,22 @@ export function initializeRenderHost(
async importFile() {
throw new Error('Not implemented');
},
async exportFile() {
throw new Error('Not implemented');
async exportFile(data: string, {defaultPath}: {defaultPath?: string}) {
const file = new File([data], defaultPath ?? 'unknown', {
type: 'text/plain;charset=utf-8',
});
FileSaver.saveAs(file);
return defaultPath;
},
async exportFileBinary() {
throw new Error('Not implemented');
async exportFileBinary(
data: Uint8Array,
{defaultPath}: {defaultPath?: string},
) {
const file = new File([data], defaultPath ?? 'unknown', {
type: 'application/octet-stream',
});
FileSaver.saveAs(file);
return defaultPath;
},
openLink(url: string) {
window.open(url, '_blank');
Expand Down
2 changes: 1 addition & 1 deletion desktop/flipper-ui-core/src/utils/exportData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ export async function exportEverythingEverywhereAllAtOnce(
const exportedFilePath = await getRenderHostInstance().exportFileBinary?.(
archiveData,
{
defaultPath: 'flipper_EEAaO_export',
defaultPath: 'flipper_EEAaO_export.zip',
},
);

Expand Down
23 changes: 19 additions & 4 deletions desktop/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3956,6 +3956,11 @@
resolved "https://registry.yarnpkg.com/@types/fb-watchman/-/fb-watchman-2.0.1.tgz#4f44c7b7ac98463488765d41d269272dd34cb815"
integrity sha512-iJ7/e6drSmuCzAp96/dpksm8YjxbhhyXWV6m1HPbRHvZwUOUZ5vZvZIAUJxKDtI0UpdNfDvLPiai0MTJmmS+HA==

"@types/file-saver@^2.0.5":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@types/file-saver/-/file-saver-2.0.5.tgz#9ee342a5d1314bb0928375424a2f162f97c310c7"
integrity sha512-zv9kNf3keYegP5oThGLaPk8E081DFDuwfqjtiTzm6PoxChdJ1raSuADf2YGCVIyrSynLrgc8JWv296s7Q7pQSQ==

"@types/fs-extra@^9.0.11", "@types/fs-extra@^9.0.12", "@types/fs-extra@^9.0.13":
version "9.0.13"
resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.13.tgz#7594fbae04fe7f1918ce8b3d213f74ff44ac1f45"
Expand Down Expand Up @@ -4702,7 +4707,12 @@ acorn@^7.4.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa"
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==

acorn@^8.1.0, acorn@^8.4.1, acorn@^8.8.1:
acorn@^8.1.0, acorn@^8.8.1:
version "8.9.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.9.0.tgz#78a16e3b2bcc198c10822786fa6679e245db5b59"
integrity sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==

acorn@^8.4.1:
version "8.8.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a"
integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==
Expand Down Expand Up @@ -8116,6 +8126,11 @@ file-entry-cache@^6.0.1:
dependencies:
flat-cache "^3.0.4"

file-saver@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.5.tgz#d61cfe2ce059f414d899e9dd6d4107ee25670c38"
integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==

file-stream-rotator@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/file-stream-rotator/-/file-stream-rotator-0.6.1.tgz#007019e735b262bb6c6f0197e58e5c87cb96cec3"
Expand Down Expand Up @@ -14580,9 +14595,9 @@ [email protected]:
integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==

tough-cookie@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.1.2.tgz#e53e84b85f24e0b65dd526f46628db6c85f6b874"
integrity sha512-G9fqXWoYFZgTc2z8Q5zaHy/vJMjm+WV0AkAeHxVCQiEB1b+dGvWzFW6QV07cY5jQ5gRkeid2qIkzkxUnmoQZUQ==
version "4.1.3"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.1.3.tgz#97b9adb0728b42280aa3d814b6b999b2ff0318bf"
integrity sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==
dependencies:
psl "^1.1.33"
punycode "^2.1.1"
Expand Down

0 comments on commit daa3a38

Please sign in to comment.