Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export timeline log feature #1533

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion apps/reactotron-app/src/renderer/pages/timeline/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useCallback, useContext, useMemo } from "react"
import { clipboard, shell } from "electron"
import fs from "fs"
import os from "os"
import path from "path"
import debounce from "lodash.debounce"
import {
Header,
Expand All @@ -12,7 +14,14 @@ import {
TimelineContext,
RandomJoke,
} from "reactotron-core-ui"
import { MdSearch, MdDeleteSweep, MdFilterList, MdSwapVert, MdReorder } from "react-icons/md"
import {
MdSearch,
MdDeleteSweep,
MdFilterList,
MdSwapVert,
MdReorder,
MdDownload,
} from "react-icons/md"
import { FaTimes } from "react-icons/fa"
import styled from "styled-components"

Expand Down Expand Up @@ -104,6 +113,21 @@ function Timeline() {
shell.openExternal("https://docs.infinite.red/reactotron/quick-start/react-native/")
}

function downloadLog() {
if (commands.length > 0) {
const homeDir = os.homedir()
const downloadDir = path.join(homeDir, "Downloads")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: if ~/Downloads doesn't exist, this fails silently. Can we either give the user an alert, or perhaps prompt them to set a download location instead of just assuming this path will exist for them?

I don't think we need to block on this because it doesn't crash the app, but if we can add that to this PR or quickly follow up, that would be great.

fs.writeFileSync(
path.resolve(downloadDir, `timeline-log-${Date.now()}.json`),
JSON.stringify(commands),
"utf8"
)
console.log(`Exported timeline log to ${downloadDir}`)
} else {
console.error("There is nothing to export.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: @denis-remitly - what do you think about still exporting an empty array here instead? That would be my preference.

}
}

const { searchString, handleInputChange } = useDebouncedSearchInput(search, setSearch, 300)

return (
Expand All @@ -112,6 +136,13 @@ function Timeline() {
title="Timeline"
isDraggable
actions={[
{
tip: "Export Log",
icon: MdDownload,
onClick: () => {
downloadLog()
},
},
{
tip: "Search",
icon: MdSearch,
Expand Down