import { useState } from "react";
import { useTranslation } from "react-i18next";
import { SelectOutlined as SelectOutlinedIcon } from "@ant-design/icons";
import { useRequest } from "ahooks";
import { Alert, Button, Divider, Empty, Space, Table, type TableProps, Tooltip, Typography, notification } from "antd";
import dayjs from "dayjs";
import { ClientResponseError } from "pocketbase";
import CertificateDetailDrawer from "@/components/certificate/CertificateDetailDrawer";
import Show from "@/components/Show";
import { type CertificateModel } from "@/domain/certificate";
import { WORKFLOW_RUN_STATUSES, type WorkflowRunModel } from "@/domain/workflowRun";
import { listByWorkflowRunId as listCertificateByWorkflowRunId } from "@/repository/certificate";
import { getErrMsg } from "@/utils/error";
export type WorkflowRunDetailProps = {
className?: string;
style?: React.CSSProperties;
data: WorkflowRunModel;
};
const WorkflowRunDetail = ({ data, ...props }: WorkflowRunDetailProps) => {
const { t } = useTranslation();
return (
{t("workflow_run.props.status.succeeded")}} />
{t("workflow_run.props.status.failed")}} />
{t("workflow_run.logs")}
{data.logs?.map((item, i) => {
return (
{item.nodeName}
{item.records?.map((output, j) => {
return (
[{dayjs(output.time).format("YYYY-MM-DD HH:mm:ss")}]
{output.error ?
{output.error}
:
{output.content}
}
);
})}
);
})}
);
};
const WorkflowRunArtifacts = ({ runId }: { runId: string }) => {
const { t } = useTranslation();
const [notificationApi, NotificationContextHolder] = notification.useNotification();
const tableColumns: TableProps["columns"] = [
{
key: "$index",
align: "center",
fixed: "left",
width: 50,
render: (_, __, index) => index + 1,
},
{
key: "type",
title: t("workflow_run_artifact.props.type"),
render: () => t("workflow_run_artifact.props.type.certificate"),
},
{
key: "name",
title: t("workflow_run_artifact.props.name"),
ellipsis: true,
render: (_, record) => {
return (
{record.subjectAltNames}
);
},
},
{
key: "$action",
align: "end",
width: 120,
render: (_, record) => (
} variant="text" />
}
/>
),
},
];
const [tableData, setTableData] = useState([]);
const { loading: tableLoading } = useRequest(
() => {
return listCertificateByWorkflowRunId(runId);
},
{
refreshDeps: [runId],
onBefore: () => {
setTableData([]);
},
onSuccess: (res) => {
setTableData(res.items);
},
onError: (err) => {
if (err instanceof ClientResponseError && err.isAbort) {
return;
}
console.error(err);
notificationApi.error({ message: t("common.text.request_error"), description: getErrMsg(err) });
throw err;
},
}
);
return (
<>
{NotificationContextHolder}
{t("workflow_run.artifacts")}
columns={tableColumns}
dataSource={tableData}
loading={tableLoading}
locale={{
emptyText: ,
}}
pagination={false}
rowKey={(record) => record.id}
size="small"
/>
>
);
};
export default WorkflowRunDetail;