feat(ui): download workflow run logs

This commit is contained in:
Fu Diwei 2025-04-02 13:40:55 +08:00
parent daa5b44f8e
commit 0edcd9174f
3 changed files with 40 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import {
CheckOutlined as CheckOutlinedIcon, CheckOutlined as CheckOutlinedIcon,
ClockCircleOutlined as ClockCircleOutlinedIcon, ClockCircleOutlined as ClockCircleOutlinedIcon,
CloseCircleOutlined as CloseCircleOutlinedIcon, CloseCircleOutlined as CloseCircleOutlinedIcon,
DownloadOutlined as DownloadOutlinedIcon,
RightOutlined as RightOutlinedIcon, RightOutlined as RightOutlinedIcon,
SelectOutlined as SelectOutlinedIcon, SelectOutlined as SelectOutlinedIcon,
SettingOutlined as SettingOutlinedIcon, SettingOutlined as SettingOutlinedIcon,
@ -188,6 +189,34 @@ const WorkflowRunLogs = ({ runId, runStatus }: { runId: string; runStatus: strin
); );
}; };
const handleDownloadClick = () => {
const NEWLINE = "\n";
const logstr = listData
.map((group) => {
return (
group.name +
NEWLINE +
group.records
.map((record) => {
const datetime = dayjs(record.timestamp).format("YYYY-MM-DDTHH:mm:ss.SSSZ");
const level = record.level;
const message = record.message.trim().replaceAll("\r", "\\r").replaceAll("\n", "\\n");
return `[${datetime}] [${level}] ${message}`;
})
.join(NEWLINE)
);
})
.join(NEWLINE + NEWLINE);
const blob = new Blob([logstr], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `certimate_workflow_run_#${runId}_logs.txt`;
a.click();
URL.revokeObjectURL(url);
a.remove();
};
return ( return (
<> <>
<Typography.Title level={5}>{t("workflow_run.logs")}</Typography.Title> <Typography.Title level={5}>{t("workflow_run.logs")}</Typography.Title>
@ -210,6 +239,15 @@ const WorkflowRunLogs = ({ runId, runStatus }: { runId: string; runStatus: strin
icon: <CheckOutlinedIcon className={showWhitespace ? "visible" : "invisible"} />, icon: <CheckOutlinedIcon className={showWhitespace ? "visible" : "invisible"} />,
onClick: () => setShowWhitespace(!showWhitespace), onClick: () => setShowWhitespace(!showWhitespace),
}, },
{
type: "divider",
},
{
key: "download-logs",
label: t("workflow_run.logs.menu.download_logs"),
icon: <DownloadOutlinedIcon className="invisible" />,
onClick: handleDownloadClick,
},
], ],
}} }}
trigger={["click"]} trigger={["click"]}

View File

@ -21,6 +21,7 @@
"workflow_run.logs": "Logs", "workflow_run.logs": "Logs",
"workflow_run.logs.menu.show_timestamps": "Show timestamps", "workflow_run.logs.menu.show_timestamps": "Show timestamps",
"workflow_run.logs.menu.show_whitespaces": "Show whitespaces", "workflow_run.logs.menu.show_whitespaces": "Show whitespaces",
"workflow_run.logs.menu.download_logs": "Download logs",
"workflow_run.artifacts": "Artifacts", "workflow_run.artifacts": "Artifacts",
"workflow_run_artifact.props.type": "Type", "workflow_run_artifact.props.type": "Type",

View File

@ -21,6 +21,7 @@
"workflow_run.logs": "日志", "workflow_run.logs": "日志",
"workflow_run.logs.menu.show_timestamps": "显示日期时间", "workflow_run.logs.menu.show_timestamps": "显示日期时间",
"workflow_run.logs.menu.show_whitespaces": "显示转义换行符", "workflow_run.logs.menu.show_whitespaces": "显示转义换行符",
"workflow_run.logs.menu.download_logs": "下载日志",
"workflow_run.artifacts": "输出产物", "workflow_run.artifacts": "输出产物",
"workflow_run_artifact.props.type": "类型", "workflow_run_artifact.props.type": "类型",