Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 1e2fb41

Browse files
committed
feat(plugins/plugin-client-common): improved SequenceDiagram view
Fixes #5342
1 parent ea21221 commit 1e2fb41

File tree

7 files changed

+315
-103
lines changed

7 files changed

+315
-103
lines changed

packages/test/src/api/table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export class TestTable {
191191
if (validation.switchToList) {
192192
await res.app.client.waitForVisible(Selectors.TABLE_SHOW_AS_LIST(res.count))
193193
await res.app.client.click(Selectors.TABLE_SHOW_AS_LIST(res.count))
194+
await res.app.client.waitForVisible(Selectors.TABLE_AS_LIST(res.count))
194195
}
195196
}
196197

plugins/plugin-client-common/src/components/Content/Table/Bar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import '../../../../web/scss/components/Table/Bar.scss'
1919

2020
interface Props {
2121
left: string
22-
right: string
2322
width: string
2423
className?: string
24+
title?: string
2525
}
2626

2727
export default class Bar extends React.PureComponent<Props> {
@@ -30,12 +30,11 @@ export default class Bar extends React.PureComponent<Props> {
3030
<div className="kui--bar-wrapper">
3131
<div
3232
className={'kui--bar ' + (this.props.className || 'kui--bar-default-color')}
33+
title={this.props.title}
3334
data-left={this.props.left}
34-
data-right={this.props.right}
3535
data-width={this.props.width}
3636
style={{
3737
left: this.props.left,
38-
right: this.props.right,
3938
width: this.props.width
4039
}}
4140
/>

plugins/plugin-client-common/src/components/Content/Table/PaginatedTable.tsx

Lines changed: 9 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import sortRow from './sort'
2323
import Card from '../../spi/Card'
2424
import renderBody from './TableBody'
2525
import renderHeader from './TableHeader'
26+
import SequenceDiagram from './SequenceDiagram'
2627
import Toolbar, { Props as ToolbarProps } from './Toolbar'
27-
import Grid, { findGridableColumn, durationCss } from './Grid'
28+
import Grid, { findGridableColumn } from './Grid'
2829
import kui2carbon, { NamedDataTableRow } from './kui2carbon'
2930
import { BreadcrumbView } from '../../spi/Breadcrumb'
30-
import Bar from './Bar'
3131

3232
/** carbon styling */
3333
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
249249
}, {} as Record<string, boolean>)
250250
}
251251

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-
336252
private table() {
337253
const { tab, repl } = this.props
338254
const { page } = this.state
339255

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
344258

345259
const isSortable = response.body.length > 1
346260
const dataTable = (visibleRows: NamedDataTableRow[], offset = 0) => (
@@ -386,11 +300,15 @@ export default class PaginatedTable<P extends Props, S extends State> extends Re
386300
)
387301
}
388302

303+
private sequence() {
304+
return <SequenceDiagram {...this.props} />
305+
}
306+
389307
private content(includeToolbars = false, lightweightTables = false) {
390308
return (
391309
<React.Fragment>
392310
{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()}
394312
{includeToolbars && this.bottomToolbar(lightweightTables)}
395313
</React.Fragment>
396314
)

0 commit comments

Comments
 (0)