16
16
* specific language governing permissions and limitations
17
17
* under the License.
18
18
*/
19
- import { Box } from "@chakra-ui/react" ;
19
+ import { Box , ButtonGroup , Code , Flex , Heading , IconButton , useDisclosure } from "@chakra-ui/react" ;
20
20
import type { ColumnDef } from "@tanstack/react-table" ;
21
+ import { MdCompress , MdExpand } from "react-icons/md" ;
21
22
import { useParams } from "react-router-dom" ;
22
23
23
24
import { useEventLogServiceGetEventLogs } from "openapi/queries" ;
24
25
import type { EventLogResponse } from "openapi/requests/types.gen" ;
25
26
import { DataTable } from "src/components/DataTable" ;
26
27
import { useTableURLState } from "src/components/DataTable/useTableUrlState" ;
27
28
import { ErrorAlert } from "src/components/ErrorAlert" ;
29
+ import RenderedJsonField from "src/components/RenderedJsonField" ;
28
30
import Time from "src/components/Time" ;
29
31
30
- const eventsColumn = (
31
- dagId ?: string ,
32
- runId ?: string ,
33
- taskId ?: string ,
34
- ) : Array < ColumnDef < EventLogResponse > > => [
32
+ type EventsColumn = {
33
+ dagId ?: string ;
34
+ open ?: boolean ;
35
+ runId ?: string ;
36
+ taskId ?: string ;
37
+ } ;
38
+
39
+ const eventsColumn = ( { dagId, open, runId, taskId } : EventsColumn ) : Array < ColumnDef < EventLogResponse > > => [
35
40
{
36
41
accessorKey : "when" ,
37
42
cell : ( { row : { original } } ) => < Time datetime = { original . when } /> ,
@@ -41,6 +46,43 @@ const eventsColumn = (
41
46
skeletonWidth : 10 ,
42
47
} ,
43
48
} ,
49
+ {
50
+ accessorKey : "event" ,
51
+ enableSorting : true ,
52
+ header : "Event" ,
53
+ meta : {
54
+ skeletonWidth : 10 ,
55
+ } ,
56
+ } ,
57
+ {
58
+ accessorKey : "owner" ,
59
+ enableSorting : true ,
60
+ header : "User" ,
61
+ meta : {
62
+ skeletonWidth : 10 ,
63
+ } ,
64
+ } ,
65
+ {
66
+ accessorKey : "extra" ,
67
+ cell : ( { row : { original } } ) => {
68
+ if ( original . extra !== null ) {
69
+ try {
70
+ const parsed = JSON . parse ( original . extra ) as Record < string , unknown > ;
71
+
72
+ return < RenderedJsonField content = { parsed } jsonProps = { { collapsed : ! open } } /> ;
73
+ } catch {
74
+ return < Code > { original . extra } </ Code > ;
75
+ }
76
+ }
77
+
78
+ return undefined ;
79
+ } ,
80
+ enableSorting : false ,
81
+ header : "Extra" ,
82
+ meta : {
83
+ skeletonWidth : 200 ,
84
+ } ,
85
+ } ,
44
86
...( Boolean ( dagId )
45
87
? [ ]
46
88
: [
@@ -93,38 +135,18 @@ const eventsColumn = (
93
135
skeletonWidth : 10 ,
94
136
} ,
95
137
} ,
96
- {
97
- accessorKey : "event" ,
98
- enableSorting : true ,
99
- header : "Event" ,
100
- meta : {
101
- skeletonWidth : 10 ,
102
- } ,
103
- } ,
104
- {
105
- accessorKey : "owner" ,
106
- enableSorting : true ,
107
- header : "User" ,
108
- meta : {
109
- skeletonWidth : 10 ,
110
- } ,
111
- } ,
112
138
] ;
113
139
114
140
export const Events = ( ) => {
115
141
const { dagId, runId, taskId } = useParams ( ) ;
116
142
const { setTableURLState, tableURLState } = useTableURLState ( ) ;
117
143
const { pagination, sorting } = tableURLState ;
118
144
const [ sort ] = sorting ;
145
+ const { onClose, onOpen, open } = useDisclosure ( ) ;
119
146
120
147
const orderBy = sort ? `${ sort . desc ? "-" : "" } ${ sort . id } ` : "-when" ;
121
148
122
- const {
123
- data,
124
- error : EventsError ,
125
- isFetching,
126
- isLoading,
127
- } = useEventLogServiceGetEventLogs (
149
+ const { data, error, isFetching, isLoading } = useEventLogServiceGetEventLogs (
128
150
{
129
151
dagId,
130
152
limit : pagination . pageSize ,
@@ -139,9 +161,32 @@ export const Events = () => {
139
161
140
162
return (
141
163
< Box >
142
- < ErrorAlert error = { EventsError } />
164
+ < Flex alignItems = "center" justifyContent = "space-between" >
165
+ < Heading > Audit Log Events</ Heading >
166
+ < ButtonGroup attached size = "sm" variant = "surface" >
167
+ < IconButton
168
+ aria-label = "Expand all extra json"
169
+ onClick = { onOpen }
170
+ size = "sm"
171
+ title = "Expand all extra json"
172
+ variant = "surface"
173
+ >
174
+ < MdExpand />
175
+ </ IconButton >
176
+ < IconButton
177
+ aria-label = "Collapse all extra json"
178
+ onClick = { onClose }
179
+ size = "sm"
180
+ title = "Collapse all extra json"
181
+ variant = "surface"
182
+ >
183
+ < MdCompress />
184
+ </ IconButton >
185
+ </ ButtonGroup >
186
+ </ Flex >
187
+ < ErrorAlert error = { error } />
143
188
< DataTable
144
- columns = { eventsColumn ( dagId , runId , taskId ) }
189
+ columns = { eventsColumn ( { dagId, open , runId, taskId } ) }
145
190
data = { data ? data . event_logs : [ ] }
146
191
displayMode = "table"
147
192
initialState = { tableURLState }
0 commit comments