// Copyright (C) 2019 Intel Corporation. All rights reserved. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception import { Button, Modal, Table, Card, TableColumnsType, Tooltip, Tag, Form, message, Input, Progress } from "antd"; import React, { useEffect, useState } from "react"; import "antd/dist/antd.css"; import type { ColumnsType } from "antd/es/table"; import { SyncOutlined, ArrowDownOutlined } from "@ant-design/icons"; import { useSearchParams } from "react-router-dom"; const { TextArea } = Input; const tabList2 = [ { key: "error", tab: "error" }, { key: "stdout", tab: "stdout" }, { key: "stderr", tab: "stderr" } ]; interface ErrorDataType { id: number; name: string; fuzzing_id: number; data: any; status: string; create_time: string; update_time: string; comment: any; } const CardMenu: React.FC<{ result: any; detail_result: any; tableLoading: boolean; resultReload: number; setResultReload: any; }> = ({ result, detail_result, tableLoading, resultReload, setResultReload }) => { const [selectedRowKeys, setSelectedRowKeys] = useState([]); const [modalVisible, setModalVisible] = useState(false); const [modal2Visible, setModal2Visible] = useState(false); const [modal3Visible, setModal3Visible] = useState(false); const [reloadLoading, setRelLoading] = useState(false); const [errorTabData, setErrorTabData] = useState(""); const [downloadLoading, setDownLoading] = useState(false); result.results && (result.results = result.results.map((t: any) => ({ key: t.id, ...t }))); const error_columns: ColumnsType = [ { title: "ErrorName", width: "13%", dataIndex: "name", render: (value) => { return (
{value}
); } }, { title: "CreateTime", dataIndex: "create_time", width: "13%", render: (value) => { return (
{value}
); } }, { title: "UpdateTime", dataIndex: "update_time", width: "13.5%", render: (value) => { return (
{value}
); } }, { title: "Comment", dataIndex: "comment", width: "12%", render: (value) => { return (
{value?.comment}
); } }, { title: "Assign", dataIndex: "comment", width: "9%", render: (value) => { return (
{value?.assign}
); } }, { title: "Status", dataIndex: "status", width: "14%", filters: [ { text: "Pending", value: 2 }, { text: "Error", value: 1 }, { text: "OK", value: 0 } ], onFilter: (value, record) => { return record.status === value; }, render: (value, Object) => { var colors: string = ""; var val: string = ""; if (value === 1) { colors = "red"; val = `Error(${Object.name.split("-")[0]})`; } else if (value === 0) { colors = "green"; val = "OK"; } else if (value === 2) { colors = ""; val = "pending"; } return ( <> {/* */}
{val} {/* {Object?.wamr_commit} */}
); } }, { title: "Action", dataIndex: "", // width: "15%", render: (value, Object) => { return ( <> ); } } ]; const onSelectChange = (newSelectedRowKeys: React.Key[]) => { console.log("selectedRowKeys changed: ", selectedRowKeys); setSelectedRowKeys(newSelectedRowKeys); }; const start = (repo: string, branch: string, build_args: string) => { setRelLoading(true); fetch(import.meta.env.VITE_SERVER_URL + "/error_restart", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json" }, body: JSON.stringify({ id: selectedRowKeys, repo: repo, branch: branch, build_args: build_args }) }) .then((res) => { return res.json(); }) .then((body) => { setRelLoading(false); if (body?.status === 1) { setResultReload(resultReload + 1); message.loading("pending"); } else { message.error(body?.msg ? body?.msg : "Server Error"); } }); }; const rowSelection = { selectedRowKeys, onChange: onSelectChange, getCheckboxProps: (record: ErrorDataType) => ({ disabled: Number(record.status) === 2 }) }; const hasSelected = selectedRowKeys.length > 0; const [form] = Form.useForm(); const set_comment = (comment: string, assign: string) => { setRelLoading(true); fetch(import.meta.env.VITE_SERVER_URL + "/set_commend", { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json" }, body: JSON.stringify({ id: selectedRowKeys, comment: { comment: comment, assign: assign } }) }) .then((res) => { return res.json(); }) .then((body) => { setRelLoading(false); if (body?.status === 1) { setResultReload(resultReload + 1); message.success("success"); } else { message.error("Server Error"); } }); }; const get_cases = async (response: Response, name: string) => { try { if (response.headers.get("content-type") !== "application/json") { response .blob() .then((blob) => { const a = window.document.createElement("a"); const downUrl = window.URL.createObjectURL( new Blob([blob], { type: "multipart/form-data" }) ); //定义导出文件的命名 let filename = name; if ( response.headers.get("content-disposition") && response.headers?.get("content-disposition")?.indexOf("filename=") !== -1 ) { filename = response.headers?.get("content-disposition")?.split("filename=")[1] || name; a.href = downUrl; a.download = `${decodeURI(filename.split('"')[1])}` || name; a.click(); window.URL.revokeObjectURL(downUrl); } else { a.href = downUrl; a.download = name; a.click(); window.URL.revokeObjectURL(downUrl); } }) .catch((error) => { message.error(error); }); } else { let res = await response.json(); message.error(res.msg); } } catch (err) { console.log(err); message.error("Download timeout"); } }; return ( <>
More} // tabList={tabList} loading={tableLoading} >
<> <> <>
{" "} {" "} } // onOk={() => setModal3Visible(false)} onCancel={() => setModal3Visible(false)} >
{errorTabData}
{ let repo = form.getFieldsValue(["repo", "branch", "build_args"]).repo; let branch = form.getFieldsValue(["repo", "branch", "build_args"]).branch; let build_args = form.getFieldsValue(["repo", "branch", "build_args"]).build_args; if (repo === "" || branch === "") { message.error("repo and branch cannot be empty"); return; } if (repo === undefined) { repo = detail_result.repo; } if (branch === undefined) { branch = detail_result.branch; } if (build_args === undefined) { build_args = detail_result.build_args; } start(repo, branch, build_args); setModalVisible(false); setSelectedRowKeys([]); }} onCancel={() => { setModalVisible(false); }} >