@@ -58,10 +58,6 @@ export type State = {
58
58
}
59
59
60
60
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
-
65
61
public componentDidMount ( ) {
66
62
this . setState ( {
67
63
workers : [ ] ,
@@ -93,6 +89,13 @@ export default class Dashboard extends React.PureComponent<Props, State> {
93
89
} ) )
94
90
}
95
91
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
+
96
99
/** @return current `lines` model */
97
100
private get lines ( ) : UpdatePayload [ "lines" ] {
98
101
return this . state ?. lines
@@ -164,28 +167,27 @@ export default class Dashboard extends React.PureComponent<Props, State> {
164
167
)
165
168
}
166
169
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"
169
173
}
170
174
175
+ /** @return pretty-printed millis since epoch as delta from this moment in time e.g. "5m ago" */
171
176
private agos ( millis : number ) {
172
177
return this . ago ( Date . now ( ) - millis )
173
178
}
174
179
180
+ /** Render log lines */
175
181
private footer ( ) {
176
182
if ( ! this . lines ) {
177
183
return < React . Fragment />
178
184
} else {
179
185
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
180
190
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
189
191
return < Text key = { txt } > { txt } </ Text >
190
192
} )
191
193
return (
@@ -196,6 +198,11 @@ export default class Dashboard extends React.PureComponent<Props, State> {
196
198
}
197
199
}
198
200
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
+ */
199
206
private gridRows ( ) {
200
207
const rows : { widx : number ; grid : NonNullable < Props [ "grids" ] [ number ] > } [ ] [ ] = [ ]
201
208
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> {
212
219
return rows
213
220
}
214
221
222
+ /** Render the grids */
215
223
private body ( ) {
216
224
return this . gridRows ( ) . map ( ( row , ridx ) => (
217
225
< Box key = { ridx } justifyContent = "space-around" >
0 commit comments