@@ -23,11 +23,11 @@ import sortRow from './sort'
23
23
import Card from '../../spi/Card'
24
24
import renderBody from './TableBody'
25
25
import renderHeader from './TableHeader'
26
+ import SequenceDiagram from './SequenceDiagram'
26
27
import Toolbar , { Props as ToolbarProps } from './Toolbar'
27
- import Grid , { findGridableColumn , durationCss } from './Grid'
28
+ import Grid , { findGridableColumn } from './Grid'
28
29
import kui2carbon , { NamedDataTableRow } from './kui2carbon'
29
30
import { BreadcrumbView } from '../../spi/Breadcrumb'
30
- import Bar from './Bar'
31
31
32
32
/** carbon styling */
33
33
import 'carbon-components/scss/components/data-table/_data-table-core.scss'
@@ -249,98 +249,12 @@ export default class PaginatedTable<P extends Props, S extends State> extends Re
249
249
} , { } as Record < string , boolean > )
250
250
}
251
251
252
- private transformTableWithTimestamp ( kuiTable : KuiTable ) {
253
- const table = JSON . parse ( JSON . stringify ( kuiTable ) ) // deep copy
254
- const startIdx = table . startColumnIdx
255
- const endIdx = table . completeColumnIdx
256
-
257
- // add 'hide-with-sidecar' css to start column and remove end column
258
- table . header . attributes [ startIdx ] . outerCSS = `${ table . header . attributes [ startIdx ] . outerCSS || '' } hide-with-sidecar`
259
- table . header . attributes . splice ( endIdx , 1 )
260
-
261
- // add duration header column if needed
262
- if ( table . durationColumnIdx === undefined ) {
263
- table . header . attributes . push ( { key : 'Duration' , value : 'Duration' } )
264
- }
265
-
266
- // add interval header column
267
- /* table.header.attributes.push({ key: 'Interval', value: 'Interval' })
268
-
269
- // compute the max completion time and min start time
270
- let minStart = -1
271
- let maxEnd = -1
272
-
273
- table.body.forEach(row => {
274
- const start = new Date(row.attributes[startIdx].value).getTime()
275
- const end = new Date(row.attributes[endIdx].value).getTime()
276
-
277
- minStart = start < minStart || minStart === -1 ? start : minStart
278
- maxEnd = end > maxEnd || maxEnd === -1 ? end : maxEnd
279
- })
280
-
281
- const getFraction = (numerator: number) => {
282
- return `${((numerator / (maxEnd - minStart)) * 100).toFixed(10).toString()}%`
283
- } */
284
- const maxDuration = table . body . reduce ( ( max , row ) => {
285
- const durationCol = table . durationColumnIdx >= 0 && parseInt ( row . attributes [ table . durationColumnIdx ] . value , 10 )
286
- return Math . max (
287
- max ,
288
- durationCol ||
289
- new Date ( row . attributes [ endIdx ] . value ) . getTime ( ) - new Date ( row . attributes [ startIdx ] . value ) . getTime ( )
290
- )
291
- } , 0 )
292
-
293
- const getFraction = ( numerator : number ) => {
294
- return `${ ( ( numerator / maxDuration ) * 100 ) . toFixed ( 10 ) . toString ( ) } %`
295
- }
296
-
297
- table . body . forEach ( row => {
298
- const durationCol = table . durationColumnIdx >= 0 && parseInt ( row . attributes [ table . durationColumnIdx ] . value , 10 )
299
-
300
- const start = new Date ( row . attributes [ startIdx ] . value ) . getTime ( )
301
- const end = new Date ( row . attributes [ endIdx ] . value ) . getTime ( )
302
-
303
- const duration = durationCol || end - start
304
- const width = getFraction ( duration )
305
- const left = '0%' // getFraction(start - minStart)
306
- const right = width // getFraction(maxEnd - end)
307
- const className = durationCss ( duration , false )
308
-
309
- // add duration column if needed
310
- if ( table . durationColumnIdx === undefined ) {
311
- row . attributes . push ( {
312
- key : 'Duration' ,
313
- value : duration . toString ( ) ,
314
- valueDom : < Bar left = { left } right = { right } width = { width } className = { className } />
315
- } )
316
- } else {
317
- row . attributes [ table . durationColumnIdx ] . valueDom = (
318
- < Bar left = { left } right = { right } width = { width } className = { className } />
319
- )
320
- }
321
-
322
- // add 'hide-with-sidecar' css to start column and remove end column
323
- row . attributes [ startIdx ] . outerCSS = `${ row . attributes [ startIdx ] . outerCSS || '' } hide-with-sidecar`
324
- row . attributes [ startIdx ] . value = new Date ( row . attributes [ startIdx ] . value ) . toLocaleString ( )
325
- row . attributes . splice ( endIdx , 1 )
326
- } )
327
-
328
- // add durationColumnIdx if needed
329
- if ( table . durationColumnIdx === undefined ) {
330
- table . durationColumnIdx = table . header . attributes . findIndex ( _ => _ . key === 'Duration' )
331
- }
332
-
333
- return table
334
- }
335
-
336
252
private table ( ) {
337
253
const { tab, repl } = this . props
338
254
const { page } = this . state
339
255
340
- const response = ! this . state . asSequence
341
- ? this . props . response
342
- : this . transformTableWithTimestamp ( this . props . response )
343
- const { headers, rows } = ! this . state . asSequence ? this . state : kui2carbon ( response )
256
+ const response = this . props . response
257
+ const { headers, rows } = this . state
344
258
345
259
const isSortable = response . body . length > 1
346
260
const dataTable = ( visibleRows : NamedDataTableRow [ ] , offset = 0 ) => (
@@ -386,11 +300,15 @@ export default class PaginatedTable<P extends Props, S extends State> extends Re
386
300
)
387
301
}
388
302
303
+ private sequence ( ) {
304
+ return < SequenceDiagram { ...this . props } />
305
+ }
306
+
389
307
private content ( includeToolbars = false , lightweightTables = false ) {
390
308
return (
391
309
< React . Fragment >
392
310
{ includeToolbars && this . topToolbar ( lightweightTables ) }
393
- { this . state . asGrid ? this . grid ( this . state . rows ) : this . table ( ) }
311
+ { this . state . asGrid ? this . grid ( this . state . rows ) : this . state . asSequence ? this . sequence ( ) : this . table ( ) }
394
312
{ includeToolbars && this . bottomToolbar ( lightweightTables ) }
395
313
</ React . Fragment >
396
314
)
0 commit comments