|
| 1 | +import { useQuery } from "@tanstack/react-query"; |
| 2 | + |
| 3 | +import CopyText from "@/components/CopyText"; |
| 4 | +import PanelHeader from "@/components/Panel/Header"; |
| 5 | +import { formatDate } from "@/utils/format"; |
| 6 | + |
| 7 | +import useFunctionStore from "../../store"; |
| 8 | + |
| 9 | +import { LogControllerGetLogs } from "@/apis/v1/apps"; |
| 10 | + |
| 11 | +function ConsolePanel() { |
| 12 | + const { currentRequestId } = useFunctionStore(); |
| 13 | + |
| 14 | + const logControllerGetLogsQuery = useQuery( |
| 15 | + ["LogControllerGetLogs", currentRequestId], |
| 16 | + () => { |
| 17 | + return LogControllerGetLogs({ requestId: currentRequestId, limit: 100 }); |
| 18 | + }, |
| 19 | + { |
| 20 | + enabled: typeof currentRequestId !== "undefined", |
| 21 | + }, |
| 22 | + ); |
| 23 | + |
| 24 | + return ( |
| 25 | + <div className="flex-1 "> |
| 26 | + <PanelHeader className="bg-slate-100 !mb-1">Console</PanelHeader> |
| 27 | + <div className="relative overflow-y-auto px-2 font-mono text-sm" style={{ height: "200px" }}> |
| 28 | + {currentRequestId && ( |
| 29 | + <p className="mb-1 ml-1"> |
| 30 | + ReqeustID: {currentRequestId} <CopyText text={String(currentRequestId)} /> |
| 31 | + </p> |
| 32 | + )} |
| 33 | + {(logControllerGetLogsQuery.data?.data?.list || []).map((item: any) => { |
| 34 | + return ( |
| 35 | + <div key={item._id} className="flex "> |
| 36 | + <span className=" text-slate-500 min-w-[160px]"> |
| 37 | + [{formatDate(item.created_at, "YYYY-MM-DD hh:mm:ss")}] |
| 38 | + </span> |
| 39 | + <pre className="flex-1">{item.data}</pre> |
| 40 | + </div> |
| 41 | + ); |
| 42 | + })} |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + ); |
| 46 | +} |
| 47 | + |
| 48 | +export default ConsolePanel; |
0 commit comments