Skip to content

Commit b7b0daf

Browse files
authored
Add audit log extra to table and improve UX (#50100)
* Add Audit Log events extra * Rearrange audit log columns for readability * Add expand/collapse all button for extra json
1 parent 0258f0a commit b7b0daf

File tree

1 file changed

+75
-30
lines changed
  • airflow-core/src/airflow/ui/src/pages/Events

1 file changed

+75
-30
lines changed

airflow-core/src/airflow/ui/src/pages/Events/Events.tsx

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,27 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { Box } from "@chakra-ui/react";
19+
import { Box, ButtonGroup, Code, Flex, Heading, IconButton, useDisclosure } from "@chakra-ui/react";
2020
import type { ColumnDef } from "@tanstack/react-table";
21+
import { MdCompress, MdExpand } from "react-icons/md";
2122
import { useParams } from "react-router-dom";
2223

2324
import { useEventLogServiceGetEventLogs } from "openapi/queries";
2425
import type { EventLogResponse } from "openapi/requests/types.gen";
2526
import { DataTable } from "src/components/DataTable";
2627
import { useTableURLState } from "src/components/DataTable/useTableUrlState";
2728
import { ErrorAlert } from "src/components/ErrorAlert";
29+
import RenderedJsonField from "src/components/RenderedJsonField";
2830
import Time from "src/components/Time";
2931

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>> => [
3540
{
3641
accessorKey: "when",
3742
cell: ({ row: { original } }) => <Time datetime={original.when} />,
@@ -41,6 +46,43 @@ const eventsColumn = (
4146
skeletonWidth: 10,
4247
},
4348
},
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+
},
4486
...(Boolean(dagId)
4587
? []
4688
: [
@@ -93,38 +135,18 @@ const eventsColumn = (
93135
skeletonWidth: 10,
94136
},
95137
},
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-
},
112138
];
113139

114140
export const Events = () => {
115141
const { dagId, runId, taskId } = useParams();
116142
const { setTableURLState, tableURLState } = useTableURLState();
117143
const { pagination, sorting } = tableURLState;
118144
const [sort] = sorting;
145+
const { onClose, onOpen, open } = useDisclosure();
119146

120147
const orderBy = sort ? `${sort.desc ? "-" : ""}${sort.id}` : "-when";
121148

122-
const {
123-
data,
124-
error: EventsError,
125-
isFetching,
126-
isLoading,
127-
} = useEventLogServiceGetEventLogs(
149+
const { data, error, isFetching, isLoading } = useEventLogServiceGetEventLogs(
128150
{
129151
dagId,
130152
limit: pagination.pageSize,
@@ -139,9 +161,32 @@ export const Events = () => {
139161

140162
return (
141163
<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} />
143188
<DataTable
144-
columns={eventsColumn(dagId, runId, taskId)}
189+
columns={eventsColumn({ dagId, open, runId, taskId })}
145190
data={data ? data.event_logs : []}
146191
displayMode="table"
147192
initialState={tableURLState}

0 commit comments

Comments
 (0)