Skip to content

Commit

Permalink
Merge branch 'main' into 295/error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
roll authored Jun 18, 2024
2 parents 33748c8 + c0f4d26 commit cb0b9ea
Show file tree
Hide file tree
Showing 22 changed files with 178 additions and 224 deletions.
20 changes: 4 additions & 16 deletions client/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import omit from 'lodash/omit'
import * as settings from './settings'
import * as types from './types'

// https://fastapi.tiangolo.com/tutorial/handling-errors/
Expand All @@ -14,28 +13,17 @@ export class Client {
serverUrl?: string
Error: typeof ClientError

constructor(props: { serverUrl?: string } = {}) {
this.serverUrl = props.serverUrl
constructor() {
this.serverUrl = 'http://localhost:4040'
this.Error = ClientError
}

async readServerUrl() {
return (
this.serverUrl ||
// @ts-ignore
(await window?.opendataeditor?.readServerUrl()) ||
settings.SERVER_URL
)
}

async request<T>(
path: string,
props: { [key: string]: any; file?: File; isBytes?: boolean } = {}
) {
const serverUrl = await this.readServerUrl()
const response = await makeRequest<T>(serverUrl + path, props)
return response
}
return await makeRequest<T>(this.serverUrl + path, props)
}

// Article

Expand Down
3 changes: 1 addition & 2 deletions client/components/Application/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import DeleteFolderDialog from './Dialogs/DeleteFolder'
import IndexFilesDialog from './Dialogs/IndexFiles'
import MoveFileDialog from './Dialogs/MoveFile'
import MoveFolderDialog from './Dialogs/MoveFolder'
import StartDialog from './Dialogs/Start'
import { useStore } from './store'

export default function Dialog() {
const dialog = useStore((state) => state.dialog)
if (!dialog) return null
// @ts-ignore
const Dialog = DIALOGS[dialog]
return <Dialog />
}
Expand All @@ -34,5 +34,4 @@ const DIALOGS = {
indexFiles: IndexFilesDialog,
moveFile: MoveFileDialog,
moveFolder: MoveFolderDialog,
start: StartDialog,
}
20 changes: 0 additions & 20 deletions client/components/Application/Dialogs/Start.tsx

This file was deleted.

7 changes: 1 addition & 6 deletions client/components/Application/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ export function makeStore(props: ApplicationProps) {

onStart: async () => {
const { client, loadConfig, loadFiles, updateState } = get()
updateState({ dialog: 'start' })

// Wait for the server
// @ts-ignore
const sendFatalError = window?.opendataeditor?.sendFatalError
let ready = false
Expand All @@ -102,14 +100,13 @@ export function makeStore(props: ApplicationProps) {
} catch (error) {
attempt += 1
if (attempt >= maxAttempts) {
const serverUrl = await client.readServerUrl()
const serverUrl = client.serverUrl
const message = `Client cannot connect to server on "${serverUrl}"`
sendFatalError ? sendFatalError(message) : alert(message)
}
await delay(delaySeconds * 1000)
}
}

// Setup project sync polling
setInterval(async () => {
const result = await client.projectSync({})
Expand All @@ -121,8 +118,6 @@ export function makeStore(props: ApplicationProps) {

updateState({ files: result.files })
}, settings.PROJECT_SYNC_INTERVAL_MILLIS)

updateState({ dialog: undefined })
},
onFileCreate: async (paths) => {
const { loadFiles, selectFile } = get()
Expand Down
4 changes: 2 additions & 2 deletions client/components/Editors/Base/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface EditorListProps {
query?: string
onAddClick: () => void
// We accept search as a prop otherwise it loses focus
SearchInput: React.ReactNode
SearchInput?: React.ReactNode
}

export default function EditorList(props: React.PropsWithChildren<EditorListProps>) {
Expand All @@ -28,7 +28,7 @@ export default function EditorList(props: React.PropsWithChildren<EditorListProp
return (
<React.Fragment>
<HeadingBox>
<Columns spacing={1} layout={[4, 5, 3]}>
<Columns spacing={1} layout={props.SearchInput ? [4, 5, 3] : [6, 6]}>
<Box sx={{ whiteSpace: 'nowrap' }}>{startCase(props.kind)}s</Box>
<Box sx={{ float: 'right' }}>
<AddButton />
Expand Down
13 changes: 1 addition & 12 deletions client/components/Editors/Resource/Sections/Contributors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import InputField from '../../../Parts/Fields/Input'
import EditorItem from '../../Base/Item'
import EditorList from '../../Base/List'
import EditorListItem from '../../Base/ListItem'
import EditorSearch from '../../Base/Search'
import { useStore, selectors, select } from '../store'

export default function Contributors() {
Expand All @@ -19,17 +18,7 @@ function ContributorList() {
const addContributor = useStore((state) => state.addContributor)
const removeContributor = useStore((state) => state.removeContributor)
return (
<EditorList
kind="contributor"
query={query}
onAddClick={() => addContributor()}
SearchInput={
<EditorSearch
value={query || ''}
onChange={(query) => updateContributorState({ query })}
/>
}
>
<EditorList kind="contributor" query={query} onAddClick={() => addContributor()}>
{contributorItems.map(({ index, contributor }) => (
<EditorListItem
key={index}
Expand Down
13 changes: 1 addition & 12 deletions client/components/Editors/Resource/Sections/Licenses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import InputField from '../../../Parts/Fields/Input'
import EditorItem from '../../Base/Item'
import EditorList from '../../Base/List'
import EditorListItem from '../../Base/ListItem'
import EditorSearch from '../../Base/Search'
import { useStore, selectors, select } from '../store'
import validator from 'validator'

Expand All @@ -21,17 +20,7 @@ function LicenseList() {
const addLicense = useStore((state) => state.addLicense)
const removeLicense = useStore((state) => state.removeLicense)
return (
<EditorList
kind="license"
query={query}
onAddClick={() => addLicense()}
SearchInput={
<EditorSearch
value={query || ''}
onChange={(query) => updateLicenseState({ query })}
/>
}
>
<EditorList kind="license" query={query} onAddClick={() => addLicense()}>
{licenseItems.map(({ index, license }) => (
<EditorListItem
key={index}
Expand Down
13 changes: 1 addition & 12 deletions client/components/Editors/Resource/Sections/Sources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import InputField from '../../../Parts/Fields/Input'
import EditorItem from '../../Base/Item'
import EditorList from '../../Base/List'
import EditorListItem from '../../Base/ListItem'
import EditorSearch from '../../Base/Search'
import { useStore, selectors, select } from '../store'
import validator from 'validator'

Expand All @@ -21,17 +20,7 @@ function SourceList() {
const addSource = useStore((state) => state.addSource)
const removeSource = useStore((state) => state.removeSource)
return (
<EditorList
kind="source"
query={query}
onAddClick={() => addSource()}
SearchInput={
<EditorSearch
value={query || ''}
onChange={(query) => updateSourceState({ query })}
/>
}
>
<EditorList kind="source" query={query} onAddClick={() => addSource()}>
{sourceItems.map(({ index, source }) => (
<EditorListItem
key={index}
Expand Down
13 changes: 1 addition & 12 deletions client/components/Editors/Schema/Sections/ForeignKeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import SelectField from '../../../Parts/Fields/Select'
import EditorItem from '../../Base/Item'
import EditorList from '../../Base/List'
import EditorListItem from '../../Base/ListItem'
import EditorSearch from '../../Base/Search'
import { useStore, selectors, select } from '../store'

export default function ForeignKey() {
Expand All @@ -20,17 +19,7 @@ function ForeignKeyList() {
const addForeignKey = useStore((state) => state.addForeignKey)
const removeForeignKey = useStore((state) => state.removeForeignKey)
return (
<EditorList
kind="foreign key"
query={query}
onAddClick={() => addForeignKey()}
SearchInput={
<EditorSearch
value={query || ''}
onChange={(query) => updateForeignKeyState({ query })}
/>
}
>
<EditorList kind="foreign key" query={query} onAddClick={() => addForeignKey()}>
{foreignKeyItems.map(({ index, foreignKey }) => (
<EditorListItem
key={index}
Expand Down
43 changes: 0 additions & 43 deletions client/components/Parts/Dialogs/Wait.tsx

This file was deleted.

71 changes: 71 additions & 0 deletions client/loading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Open Data Editor</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<script>
window?.opendataeditor.ensureLogs((message) => {
if (message == "python") {
var element = document.getElementById("python")
var loader = document.getElementById("loader")
element.classList.toggle('pending')
element.removeChild(loader)
var next = document.getElementById("requirements")
next.appendChild(loader)
}
if (message == "requirements") {
var element = document.getElementById("requirements")
var loader = document.getElementById("loader")
element.classList.toggle('pending')
element.removeChild(loader)
var next = document.getElementById("server")
next.appendChild(loader)
}
if (message == "server") {
var element = document.getElementById("server")
var loader = document.getElementById("loader")
element.classList.toggle('pending')
element.removeChild(loader)
}
})
</script>
<style>
li {
color: black;
}
.pending {
color: grey;
}
.loader {
border: 5px solid grey;
border-bottom-color: transparent;
border-radius: 50%;
display: inline-block;
box-sizing: border-box;
animation: rotation 1s linear infinite;
}
@keyframes rotation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<section style="display:grid; place-items: center;">
<div>
<h1 style="text-align: center;">Open Data Editor is loading</h1>
<p style="text-align: center;">The first time launching Open Data Editor needs to ensure requirements are installed.</p>
<ul id="logs">
<li class="pending" id="python">Ensure python is installed <span id="loader" class="loader"></span></li>
<li class="pending" id="requirements">Ensure python dependencies are installed</li>
<li class="pending" id="server">Ensure server is running</li>
</ul>
</div>
</section>
</body>
</html>
5 changes: 1 addition & 4 deletions desktop/bridge.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { ipcMain, dialog, app } from 'electron'
import log from 'electron-log'

export function createBridge({ serverPort }: { serverPort: number }) {
ipcMain.handle('readServerUrl', async () => {
return `http://localhost:${serverPort}`
})
export function createBridge() {
ipcMain.handle('sendFatalError', async (_ev, message: string) => {
log.error(message)
await dialog.showMessageBox({
Expand Down
Loading

0 comments on commit cb0b9ea

Please sign in to comment.