Skip to content

Commit b64d0f9

Browse files
authored
fix: Fix for navigation within electron app, Desktop CSV Files (#75)
* fix for navigation within electron app * support csv file saving * many text area upload fixes
1 parent f4ef0be commit b64d0f9

File tree

9 files changed

+52
-32
lines changed

9 files changed

+52
-32
lines changed

desktop/main.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Modules to control application life and create native browser window
2-
const { app, BrowserWindow, Menu } = require("electron")
2+
const { app, BrowserWindow, Menu, shell } = require("electron")
33
const path = require("path")
44
const menuTemplate = require("./menu-template")
55
const { format: formatUrl } = require("url")
@@ -34,6 +34,17 @@ function createWindow() {
3434
)
3535
}
3636

37+
// Don't open links in electron browser
38+
mainWindow.webContents.on("new-window", function (event, url) {
39+
event.preventDefault()
40+
shell.openExternal(url)
41+
})
42+
43+
mainWindow.webContents.on("will-navigate", function (event, url) {
44+
event.preventDefault()
45+
shell.openExternal(url)
46+
})
47+
3748
// Open the DevTools.
3849
// mainWindow.webContents.openDevTools()
3950
}

desktop/menu-template.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,13 @@ module.exports = [
169169
},
170170
],
171171
},
172-
{
173-
label: "Navigate",
174-
submenu: [
175-
{
176-
label: "Welcome Page",
177-
click: (menuItem, currentWindow) => {
178-
currentWindow.webContents.send("open-welcome-page")
179-
},
180-
},
181-
],
182-
},
183172
{
184173
label: "About",
185174
submenu: [
186175
{
187176
label: "Github",
188177
click: () => {
189-
shell.openItem(
178+
shell.openExternal(
190179
"https://github.com/openhumanannotation/universal-data-tool"
191180
)
192181
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"fast-json-patch": "^3.0.0-1",
7474
"ffmpeg-static": "^4.0.1",
7575
"in-browser-download": "^2.0.0",
76-
"jac-format": "^1.1.0",
76+
"jac-format": "^1.1.2",
7777
"js-md5": "^0.7.3",
7878
"moment": "^2.24.0",
7979
"posthog-js": "^1.0.4",

src/components/ConfigureInterface/index.story.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import ConfigureInterface from "./"
99

1010
storiesOf("ConfigureInterface", module).add("Data Entry", () => {
1111
const [iface, changeIFace] = useState({ type: "data_entry" })
12-
console.log({ iface })
1312
return (
1413
<ConfigureInterface
1514
iface={iface}

src/components/ImportUDTFileDialog/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const ImportUDTFileDialog = ({ open, onClose, onAddSamples }) => {
3333
actions={[
3434
{
3535
text: "Add Samples",
36-
disabled: Boolean(error),
3736
onClick: () => {
37+
changeError(null)
3838
let taskData, taskOutput
3939
try {
4040
;[taskData, taskOutput] = JSON.parse(content).taskData
@@ -43,6 +43,11 @@ const ImportUDTFileDialog = ({ open, onClose, onAddSamples }) => {
4343
const udt = fromUDTCSV(content)
4444
;({ taskData, taskOutput } = udt)
4545
} catch (e2) {
46+
console.log({
47+
message: "CSV/JSON Error Stacks",
48+
jsonError: e1.stack,
49+
csvError: e2.stack,
50+
})
4651
changeError(
4752
`JSON did not parse. CSV did not parse.\n\nJSON Error: ${e1.toString()}\nCSV Error: ${e2.toString()}`
4853
)

src/components/InterfacePage/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,15 @@ export default ({ oha, onChange, onClickEditJSON, onClearLabelData }) => {
5252
onClick={onClickEditJSON}
5353
variant="outlined"
5454
onClick={() => {
55-
if (posthog.has_opted_out_captureing()) {
56-
posthog.opt_in_captureing()
55+
if (posthog.has_opted_out_capturing()) {
56+
posthog.opt_in_capturing()
5757
} else {
58-
posthog.opt_out_captureing()
58+
posthog.opt_out_capturing()
5959
}
6060
forceUpdate()
6161
}}
6262
>
63-
{posthog.has_opted_out_captureing() ? "Enable" : "Disable"}{" "}
64-
Telemetry
63+
{posthog.has_opted_out_capturing() ? "Enable" : "Disable"} Telemetry
6564
</Button>
6665
</Box>
6766
</PaperContainer>

src/components/SampleContainer/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import React, { useState } from "react"
3+
import React, { useState, useEffect } from "react"
44
import { makeStyles } from "@material-ui/core"
55
import Grid from "@material-ui/core/Grid"
66
import Button from "@material-ui/core/Button"
@@ -92,7 +92,9 @@ const useStyles = makeStyles((theme) => ({
9292
}))
9393

9494
export const SampleContainer = ({
95-
hideDescription: defaultHideDescription = false,
95+
hideDescription: defaultHideDescription = window.localStorage.getItem(
96+
"hideDescription"
97+
) === '"true"',
9698
lastSampleExitText,
9799
onExit,
98100
requireCompleteToPressNext = false,
@@ -106,9 +108,17 @@ export const SampleContainer = ({
106108
children,
107109
}) => {
108110
const c = useStyles()
109-
const [hideDescription, changeHideDescription] = useState(
111+
const [hideDescription, changeHideDescriptionState] = useState(
110112
defaultHideDescription
111113
)
114+
const changeHideDescription = (hide) => {
115+
window.localStorage.setItem(
116+
"hideDescription",
117+
`"${hide ? "true" : "false"}"`
118+
)
119+
changeHideDescriptionState(hide)
120+
}
121+
112122
const [sampleDrawerOpen, changeSampleDrawerOpen] = useState(false)
113123
return (
114124
<>

src/components/TextAreaWithUpload/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ export default ({ content, onChangeContent, placeholder }) => {
2626
const reader = new FileReader()
2727
reader.onload = (e) => {
2828
const fileContent = e.target.result
29-
if (fileName.endsWith("csv") || fileName.endsWith("CSV")) {
30-
onChangeContent(fileContent.replace(",", "\n"))
31-
} else {
32-
onChangeContent(fileContent)
33-
}
29+
onChangeContent(fileContent)
3430
}
3531
reader.readAsText(acceptedFiles[0])
3632
})

src/utils/file-handlers/use-filesystem.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import useElectron from "../use-electron.js"
66
import { useToasts } from "../../components/Toasts"
77
import templates from "../../components/StartingPage/templates.js"
88
import { setIn } from "seamless-immutable"
9+
import toUDTCSV from "../to-udt-csv.js"
910
import useIsDesktop from "../use-is-desktop"
1011

1112
const webReturn = { saveFile: () => null }
@@ -24,10 +25,15 @@ export default (file, changeFile) => {
2425
cancelled,
2526
filePath: newFilePath,
2627
} = await remote.dialog.showSaveDialog({
27-
filters: [{ name: ".udt.json", extensions: ["udt.json"] }],
28+
filters: [
29+
{ name: ".udt.json", extensions: ["udt.json"] },
30+
{ name: ".udt.csv", extensions: ["udt.csv"] },
31+
],
2832
})
2933
filePath =
30-
!newFilePath || newFilePath.endsWith(".json")
34+
!newFilePath ||
35+
newFilePath.endsWith(".json") ||
36+
newFilePath.endsWith(".csv")
3137
? newFilePath
3238
: `${newFilePath}.udt.json`
3339
if (cancelled || !filePath) {
@@ -42,7 +48,12 @@ export default (file, changeFile) => {
4248
}
4349
await remote
4450
.require("fs")
45-
.promises.writeFile(filePath, JSON.stringify(file.content, null, " "))
51+
.promises.writeFile(
52+
filePath,
53+
filePath.endsWith(".csv")
54+
? toUDTCSV(file.content)
55+
: JSON.stringify(file.content, null, " ")
56+
)
4657
addToast("File Saved!")
4758
}
4859
saveFileAsync()

0 commit comments

Comments
 (0)