Skip to content

Commit 6b008c3

Browse files
committed
fix: try to import ink only at the top level
1 parent 4dcde5d commit 6b008c3

File tree

5 files changed

+29
-58
lines changed

5 files changed

+29
-58
lines changed

Diff for: plugins/plugin-codeflare-dashboard/src/components/Job/index.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import React from "react"
1818
import prettyMillis from "pretty-ms"
19-
import { Box, Spacer, Text } from "ink"
19+
import { Box, Spacer, Text, render } from "ink"
2020

2121
import type { GridSpec, UpdatePayload, LogLineUpdate, TimestampedLine, WorkersUpdate, Worker } from "./types.js"
2222

@@ -62,7 +62,7 @@ export type State = Pick<WorkersUpdate, "events"> &
6262
workers: Worker[][]
6363
}
6464

65-
export default class Dashboard extends React.PureComponent<Props, State> {
65+
class Job extends React.PureComponent<Props, State> {
6666
public componentDidMount() {
6767
this.setState({
6868
workers: [],
@@ -315,3 +315,9 @@ export default class Dashboard extends React.PureComponent<Props, State> {
315315
)
316316
}
317317
}
318+
319+
/** Wrap the `grids` in a `<Job/>` UI */
320+
export default async function renderJob(props: Props) {
321+
const { waitUntilExit } = render(<Job {...props} />)
322+
await waitUntilExit()
323+
}

Diff for: plugins/plugin-codeflare-dashboard/src/components/Top/index.tsx

+16-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17+
import Debug from "debug"
1718
import React from "react"
1819
import prettyMillis from "pretty-ms"
1920
import prettyBytes from "pretty-bytes"
20-
import { Box, Text, TextProps } from "ink"
2121
import { emitKeypressEvents } from "readline"
22+
import { Box, Text, TextProps, render } from "ink"
2223

2324
import type { JobRec, HostRec, PodRec, OnData, UpdatePayload, Resource, ResourceSpec } from "./types.js"
2425

@@ -63,7 +64,7 @@ type State = UI & {
6364
refresher: ReturnType<typeof setInterval>
6465
}
6566

66-
export default class NodesDashboard extends React.PureComponent<Props, State> {
67+
class Top extends React.PureComponent<Props, State> {
6768
/** Text to use for one cell's worth of time */
6869
private readonly block = "■" // "▇"
6970

@@ -342,7 +343,10 @@ export default class NodesDashboard extends React.PureComponent<Props, State> {
342343
}
343344

344345
public render() {
345-
if (!this.state?.groups || this.state.groups.length === 0) {
346+
if (!this.state?.groups) {
347+
// TODO spinner? this means we haven't received the first data set, yet
348+
return <React.Fragment />
349+
} else if (this.state.groups.length === 0) {
346350
return <Text>No active jobs</Text>
347351
} else {
348352
return (
@@ -353,3 +357,12 @@ export default class NodesDashboard extends React.PureComponent<Props, State> {
353357
}
354358
}
355359
}
360+
361+
export default async function renderTop(props: Props) {
362+
const debug = Debug("plugin-codeflare-dashboard/components/Top")
363+
364+
debug("rendering")
365+
const { waitUntilExit } = await render(<Top {...props} />)
366+
debug("initial render done")
367+
await waitUntilExit()
368+
}

Diff for: plugins/plugin-codeflare-dashboard/src/controller/dashboard/db.tsx

-36
This file was deleted.

Diff for: plugins/plugin-codeflare-dashboard/src/controller/dashboard/job/index.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import type Options from "./options.js"
2020

2121
import tailf from "../tailf.js"
2222
import usage from "../usage.js"
23-
import dashboardUI from "../db.js"
2423
import status from "./status/index.js"
2524
import utilization from "./utilization/index.js"
2625

@@ -114,19 +113,15 @@ export default async function dashboard(args: Arguments<Options>) {
114113
const grids = await gridForA(kind, historyConfig)
115114
debug("grids", grids)
116115

117-
const db = dashboardUI(profile, jobId, grids, { scale })
118-
119-
if (!db) {
116+
if (grids === null || (Array.isArray(grids) && grids.length === 0)) {
120117
throw new Error(usage("top job"))
121118
} else {
122-
const { render } = await import("ink")
119+
const [{ default: render }] = await Promise.all([import("../../../components/Job/index.js")])
123120

124121
if (process.env.ALT !== "false" && !debug.enabled) {
125122
enterAltBufferMode()
126123
}
127-
128-
const { waitUntilExit } = await render(db)
129-
await waitUntilExit()
124+
await render({ profile, jobId, scale, grids: Array.isArray(grids) ? grids : [grids] })
130125
return true
131126
}
132127
}

Diff for: plugins/plugin-codeflare-dashboard/src/controller/dashboard/top.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,10 @@ export default async function jobsController(args: Arguments<MyOptions>) {
264264
}
265265

266266
debug("loading UI dependencies")
267-
const [{ render }, { createElement }, { default: Top }] = await Promise.all([
268-
import("ink"),
269-
import("react"),
270-
import("../../components/Top/index.js"),
271-
])
267+
const [{ default: render }] = await Promise.all([import("../../components/Top/index.js")])
272268

273269
debug("rendering")
274-
const { waitUntilExit } = await render(createElement(Top, { initWatcher }))
275-
debug("initial render done")
276-
277-
await waitUntilExit()
270+
await render({ initWatcher })
278271
debug("exiting")
279272
return true
280273
}

0 commit comments

Comments
 (0)