/
columns.tsx
137 lines (134 loc) · 3.61 KB
/
columns.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import {
Badge,
Button,
ControlGroup,
Panel,
Separator,
TableColumn,
Text,
} from '@siafoundation/design-system'
import { AlertData, TableColumnId } from './types'
import { dataFields } from './data'
import { Checkmark16 } from '@carbon/icons-react'
import { formatRelative } from 'date-fns'
import { Fragment, useMemo } from 'react'
type Context = never
type KeysTableColumn = TableColumn<TableColumnId, AlertData, Context> & {
fixed?: boolean
category?: string
}
export const columns: KeysTableColumn[] = [
{
id: 'actions',
label: '',
fixed: true,
cellClassName: 'w-[50px] !pr-4 [&+*]:!pl-0',
render: ({ data: { dismiss } }) => (
<ControlGroup>
<Button tip="Dismiss alert" onClick={dismiss}>
<Checkmark16 />
</Button>
{/* <AlertContextMenu id={id} buttonProps={{ variant: 'gray' }} /> */}
</ControlGroup>
),
},
{
id: 'overview',
label: 'overview',
category: 'general',
contentClassName: 'min-w-[200px] max-w-[500px]',
render: ({ data: { message, severity, data } }) => {
return (
<div className="flex flex-col gap-1 py-4">
<div className="flex gap-1 items-center">
<Badge
variant={
severity === 'error' || severity === 'critical'
? 'red'
: severity === 'warning'
? 'amber'
: 'gray'
}
size="small"
>
{severity}
</Badge>
<Text weight="medium" noWrap>
{message}
</Text>
</div>
{data['hint'] && (
<Text size="12" color="subtle">
{data['hint'] as string}
</Text>
)}
{data['error'] && (
<Text size="12" color="subtle">
{data['error'] as string}
</Text>
)}
</div>
)
},
},
{
id: 'data',
label: 'data',
contentClassName: 'w-[400px]',
category: 'general',
render: function DataColumn({ data: { data } }) {
const datums = useMemo(
() =>
Object.keys(dataFields)
.map((key) => {
const value = data[key]
if (
value === undefined ||
value === null ||
(typeof value === 'object' && !Object.keys(value).length)
) {
return null
}
return { key, value }
})
.filter(Boolean),
[data]
)
return (
<div className="py-4 w-full">
<Panel color="subtle" className="flex flex-col gap-1 w-full py-1">
{datums.map(({ key, value }, i) => {
const Component = dataFields?.[key]?.render
if (!Component) {
return null
}
return (
<Fragment key={key}>
<div className="py-1 px-2">
<Component key={key} value={value} />
</div>
{datums.length > 1 && i < datums.length - 1 && (
<Separator color="verySubtle" className="w-full" />
)}
</Fragment>
)
})}
</Panel>
</div>
)
},
},
{
id: 'time',
label: 'time',
category: 'general',
contentClassName: 'w-[120px] justify-end',
render: ({ data: { timestamp } }) => {
return (
<Text color="subtle" size="12" ellipsis>
{formatRelative(new Date(timestamp), new Date())}
</Text>
)
},
},
]