Skip to content

Add audit log extra to table and improve UX #50100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 75 additions & 30 deletions airflow-core/src/airflow/ui/src/pages/Events/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Box } from "@chakra-ui/react";
import { Box, ButtonGroup, Code, Flex, Heading, IconButton, useDisclosure } from "@chakra-ui/react";
import type { ColumnDef } from "@tanstack/react-table";
import { MdCompress, MdExpand } from "react-icons/md";
import { useParams } from "react-router-dom";

import { useEventLogServiceGetEventLogs } from "openapi/queries";
import type { EventLogResponse } from "openapi/requests/types.gen";
import { DataTable } from "src/components/DataTable";
import { useTableURLState } from "src/components/DataTable/useTableUrlState";
import { ErrorAlert } from "src/components/ErrorAlert";
import RenderedJsonField from "src/components/RenderedJsonField";
import Time from "src/components/Time";

const eventsColumn = (
dagId?: string,
runId?: string,
taskId?: string,
): Array<ColumnDef<EventLogResponse>> => [
type EventsColumn = {
dagId?: string;
open?: boolean;
runId?: string;
taskId?: string;
};

const eventsColumn = ({ dagId, open, runId, taskId }: EventsColumn): Array<ColumnDef<EventLogResponse>> => [
{
accessorKey: "when",
cell: ({ row: { original } }) => <Time datetime={original.when} />,
Expand All @@ -41,6 +46,43 @@ const eventsColumn = (
skeletonWidth: 10,
},
},
{
accessorKey: "event",
enableSorting: true,
header: "Event",
meta: {
skeletonWidth: 10,
},
},
{
accessorKey: "owner",
enableSorting: true,
header: "User",
meta: {
skeletonWidth: 10,
},
},
{
accessorKey: "extra",
cell: ({ row: { original } }) => {
if (original.extra !== null) {
try {
const parsed = JSON.parse(original.extra) as Record<string, unknown>;

return <RenderedJsonField content={parsed} jsonProps={{ collapsed: !open }} />;
} catch {
return <Code>{original.extra}</Code>;
}
}

return undefined;
},
enableSorting: false,
header: "Extra",
meta: {
skeletonWidth: 200,
},
},
...(Boolean(dagId)
? []
: [
Expand Down Expand Up @@ -93,38 +135,18 @@ const eventsColumn = (
skeletonWidth: 10,
},
},
{
accessorKey: "event",
enableSorting: true,
header: "Event",
meta: {
skeletonWidth: 10,
},
},
{
accessorKey: "owner",
enableSorting: true,
header: "User",
meta: {
skeletonWidth: 10,
},
},
];

export const Events = () => {
const { dagId, runId, taskId } = useParams();
const { setTableURLState, tableURLState } = useTableURLState();
const { pagination, sorting } = tableURLState;
const [sort] = sorting;
const { onClose, onOpen, open } = useDisclosure();

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

const {
data,
error: EventsError,
isFetching,
isLoading,
} = useEventLogServiceGetEventLogs(
const { data, error, isFetching, isLoading } = useEventLogServiceGetEventLogs(
{
dagId,
limit: pagination.pageSize,
Expand All @@ -139,9 +161,32 @@ export const Events = () => {

return (
<Box>
<ErrorAlert error={EventsError} />
<Flex alignItems="center" justifyContent="space-between">
<Heading>Audit Log Events</Heading>
<ButtonGroup attached size="sm" variant="surface">
<IconButton
aria-label="Expand all extra json"
onClick={onOpen}
size="sm"
title="Expand all extra json"
variant="surface"
>
<MdExpand />
</IconButton>
<IconButton
aria-label="Collapse all extra json"
onClick={onClose}
size="sm"
title="Collapse all extra json"
variant="surface"
>
<MdCompress />
</IconButton>
</ButtonGroup>
</Flex>
<ErrorAlert error={error} />
<DataTable
columns={eventsColumn(dagId, runId, taskId)}
columns={eventsColumn({ dagId, open, runId, taskId })}
data={data ? data.event_logs : []}
displayMode="table"
initialState={tableURLState}
Expand Down