Skip to content

Commit 5267b4d

Browse files
committed
chore: improve method comments in Dashboard component
1 parent c5c7ae6 commit 5267b4d

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

plugins/plugin-codeflare-dashboard/src/components/Dashboard/index.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ export type State = {
5858
}
5959

6060
export default class Dashboard extends React.PureComponent<Props, State> {
61-
private get grids(): GridSpec[] {
62-
return this.props.grids.filter((_) => _ !== null) as GridSpec[]
63-
}
64-
6561
public componentDidMount() {
6662
this.setState({
6763
workers: [],
@@ -93,6 +89,13 @@ export default class Dashboard extends React.PureComponent<Props, State> {
9389
}))
9490
}
9591

92+
/** @return the grid models, excluding the `null` linebreak indicators */
93+
private get grids(): GridSpec[] {
94+
// [email protected] does not seem to be smart enough here, hence the
95+
// type conversion :(
96+
return this.props.grids.filter((_) => _ !== null) as GridSpec[]
97+
}
98+
9699
/** @return current `lines` model */
97100
private get lines(): UpdatePayload["lines"] {
98101
return this.state?.lines
@@ -164,28 +167,27 @@ export default class Dashboard extends React.PureComponent<Props, State> {
164167
)
165168
}
166169

167-
private ago(millis: number) {
168-
return prettyMillis(millis, { compact: true }) + " ago"
170+
/** @return pretty-printed milliseconds delta as e.g. "5m ago" */
171+
private ago(millisDelta: number): string {
172+
return prettyMillis(millisDelta, { compact: true }) + " ago"
169173
}
170174

175+
/** @return pretty-printed millis since epoch as delta from this moment in time e.g. "5m ago" */
171176
private agos(millis: number) {
172177
return this.ago(Date.now() - millis)
173178
}
174179

180+
/** Render log lines */
175181
private footer() {
176182
if (!this.lines) {
177183
return <React.Fragment />
178184
} else {
179185
const rows = this.lines.map(({ line, timestamp }) => {
186+
// the controller (controller/dashboard/utilization/Live)
187+
// leaves a {timestamp} breadcrumb in the raw line text, so
188+
// that we,as the view, can inject a "5m ago" text, while
189+
// preserving the ansi formatting that surrounds the timestamp
180190
const txt = line.replace("{timestamp}", () => this.agos(timestamp))
181-
// .replace(/pod\/torchx-\S+ /, "") // worker name in torchx
182-
// .replace(/pod\/ray-(head|worker)-\S+ /, "") // worker name in ray
183-
// .replace(/\* /, "") // wildcard worker name (codeflare)
184-
// .replace(/\x1b\x5B\[2J/g, "")
185-
// TODO timestamp
186-
187-
// [2J is part of clear screen; we don't want those to flow through
188-
// eslint-disable-next-line no-control-regex
189191
return <Text key={txt}>{txt}</Text>
190192
})
191193
return (
@@ -196,6 +198,11 @@ export default class Dashboard extends React.PureComponent<Props, State> {
196198
}
197199
}
198200

201+
/**
202+
* We allow the controller to break the grids into rows via a `null`
203+
* entry. This method performs that row decomposition, it does not
204+
* do any react rendering.
205+
*/
199206
private gridRows() {
200207
const rows: { widx: number; grid: NonNullable<Props["grids"][number]> }[][] = []
201208
for (let idx = 0, ridx = 0, widx = 0; idx < this.props.grids.length; idx++) {
@@ -212,6 +219,7 @@ export default class Dashboard extends React.PureComponent<Props, State> {
212219
return rows
213220
}
214221

222+
/** Render the grids */
215223
private body() {
216224
return this.gridRows().map((row, ridx) => (
217225
<Box key={ridx} justifyContent="space-around">

plugins/plugin-codeflare-dashboard/src/components/Dashboard/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import type { TextProps } from "ink"
1818

19+
/** Model of an individual worker on a job */
1920
export type Worker = {
2021
/** Identifier of this worker */
2122
name: string
@@ -33,7 +34,7 @@ export type Worker = {
3334
lastUpdate: number
3435
}
3536

36-
/** Updated info from controller */
37+
/** Model that allows the controllers to pass updated `Worker` info */
3738
export type UpdatePayload = {
3839
/** Per-worker status info */
3940
workers: Worker[]
@@ -45,6 +46,10 @@ export type UpdatePayload = {
4546
/** Callback from controller when it has updated data */
4647
export type OnData = (payload: UpdatePayload) => void
4748

49+
/**
50+
* The controllers will populate this model for each of the grid/heat
51+
* map UIs.
52+
*/
4853
export type GridSpec = {
4954
/** title of grid */
5055
title: string

0 commit comments

Comments
 (0)