-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
203 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {useState} from "react" | ||
|
||
export function useStateObject<T>(init: T) { | ||
const [state, setState] = useState<T>(init) | ||
|
||
return { | ||
...state, | ||
set: setState, | ||
setItem: (key: string, value: any) => { | ||
setState((prev) => ({...prev, [key]: value})) | ||
}, | ||
} | ||
} | ||
|
||
export type StateObject<S> = S & ReturnType<typeof useStateObject> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Dispatch, State, Store} from "src/js/state/types" | ||
import {ipc} from "src/modules/bullet/view" | ||
import {invoke} from "./invoke" | ||
|
||
type Selector = (state: State, ...args: any) => any | ||
|
||
export class ViewHandler { | ||
static store: Store | ||
static invoke = invoke | ||
protected invoke = invoke | ||
|
||
protected get store() { | ||
return ViewHandler.store | ||
} | ||
|
||
protected dispatch(action: Parameters<Dispatch>[0]) { | ||
return this.store.dispatch(action) | ||
} | ||
|
||
protected select<T extends Selector>(selector: T): ReturnType<T> { | ||
return selector(this.store.getState()) | ||
} | ||
|
||
protected request(path: string, params?: object) { | ||
return ipc.request(path, params) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {ipc} from "./ipc" | ||
|
||
class Application { | ||
controllers: any[] = [] | ||
|
||
config(fn) { | ||
return fn(this) | ||
} | ||
|
||
boot() { | ||
ipc.listen() | ||
} | ||
} | ||
|
||
export const BulletApplication = new Application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./application" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {ipcMain} from "electron" | ||
import {camelCase, capitalize} from "lodash" | ||
import {BulletApplication} from "./application" | ||
|
||
class MainIpc { | ||
listen() { | ||
ipcMain.handle("bullet:view-request", (e, controllerAction, params) => { | ||
const [shortName, action] = controllerAction.split("#") | ||
const name = capitalize(camelCase(shortName)) + "Controller" | ||
const Controller = BulletApplication.controllers[name] | ||
if (!Controller) { | ||
throw new Error("ControllerNotFound: " + controllerAction) | ||
} | ||
const instance = new Controller() | ||
return instance[action](params) | ||
}) | ||
} | ||
} | ||
|
||
export const ipc = new MainIpc() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./ipc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export class ViewIpc { | ||
request(path: string, params: any) { | ||
return global.zui.invoke("bullet:view-request", path, params) | ||
} | ||
} | ||
|
||
export const ipc = new ViewIpc() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import {ViewHandler} from "src/core/view-handler" | ||
import {Active} from "src/models/active" | ||
import QueryInfo from "src/js/state/QueryInfo" | ||
import Tabs from "src/js/state/Tabs" | ||
import Notice from "src/js/state/Notice" | ||
import Editor from "src/js/state/Editor" | ||
import {startTransition} from "react" | ||
import { | ||
runResultsCount, | ||
runResultsMain, | ||
} from "../results-pane/run-results-query" | ||
import Layout from "src/js/state/Layout" | ||
import {runHistogramQuery} from "../histogram-pane/run-query" | ||
import {fetchQueryInfo} from "src/domain/session/handlers" | ||
import Current from "src/js/state/Current" | ||
import Pools from "src/js/state/Pools" | ||
import {syncPool} from "src/app/core/pools/sync-pool" | ||
|
||
type Props = { | ||
locationKey: string | ||
} | ||
|
||
export class SessionPageHandler extends ViewHandler { | ||
constructor(public props: Props) { | ||
super() | ||
} | ||
|
||
load() { | ||
this.reset() | ||
this.setEditorValues() | ||
this.fetchResults() | ||
this.parseQueryText() | ||
} | ||
|
||
private reset() { | ||
this.dispatch(QueryInfo.reset()) | ||
this.dispatch(Tabs.loaded(this.props.locationKey)) | ||
this.dispatch(Notice.dismiss()) // This may not be needed any more | ||
} | ||
|
||
private setEditorValues() { | ||
const snapshot = Active.session.snapshot | ||
// Give editor a chance to update by scheduling this update | ||
setTimeout(() => { | ||
this.dispatch(Editor.setValue(snapshot.attrs.value ?? "")) | ||
this.dispatch(Editor.setPins(snapshot.attrs.pins || [])) | ||
}) | ||
} | ||
|
||
private fetchResults() { | ||
startTransition(() => { | ||
runResultsMain() | ||
runResultsCount() | ||
if (this.histogramVisible) runHistogramQuery() | ||
}) | ||
} | ||
|
||
private get histogramVisible() { | ||
return this.select(Layout.getShowHistogram) | ||
} | ||
|
||
private async parseQueryText() { | ||
const {session} = Active | ||
const lakeId = this.select(Current.getLakeId) | ||
const program = this.select(Current.getQueryText) | ||
const history = this.select(Current.getHistory) | ||
|
||
fetchQueryInfo(program).then((info) => { | ||
const {poolName, error} = info | ||
const pool = this.select(Pools.getByName(lakeId, poolName)) | ||
|
||
this.dispatch(QueryInfo.set({isParsed: true, ...info})) | ||
this.invoke("updatePluginSessionOp", {poolName, program}) | ||
if (pool && !pool.hasSpan()) { | ||
this.dispatch(syncPool(pool.id, lakeId)) | ||
} | ||
|
||
if (!error && history.action === "PUSH") { | ||
session.pushHistory() | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.