/** * CommandsHistory * @author: oldj * @homepage: https://oldj.net */ import { Alert, AlertDescription, AlertIcon, AlertTitle, Box, Button, Center, HStack, IconButton, Spacer, VStack, } from '@chakra-ui/react' import { actions } from '@renderer/core/agent' import { ICommandRunResult } from '@common/data' import useI18n from '@renderer/models/useI18n' import dayjs from 'dayjs' import React, { useEffect, useState } from 'react' import { BiTrash } from 'react-icons/bi' interface Props { is_show: boolean } const CommandsHistory = (props: Props) => { const { is_show } = props const [list, setList] = useState([]) const { lang } = useI18n() const loadData = async () => { let data = await actions.cmdGetHistoryList() data = data.reverse() setList(data) } const deleteOneRecord = async (_id: string) => { await actions.cmdDeleteHistory(_id) setList(list.filter((i) => i._id !== _id)) } const clearAll = async () => { await actions.cmdClearHistory() setList([]) } useEffect(() => { if (is_show) { loadData() } }, [is_show]) if (!is_show) { return null } if (list.length === 0) { return
{lang.no_record}
} return ( {list.map((item, idx) => { return ( #{item._id} {dayjs(item.add_time_ms).format('YYYY-MM-DD HH:mm:ss')} } size="sm" variant="ghost" onClick={() => item._id && deleteOneRecord(item._id)} /> {item.stdout ? ( <> stdout:
{item.stdout}
) : null} {item.stderr ? ( <> stderr:
{item.stderr}
) : null}
) })}
) } export default CommandsHistory