import {Button, Checkbox, Group, Table} from "@mantine/core"; import React, {useState} from "react"; import {Order} from "../types"; import moment from "moment"; interface OrderListTableProps { orders: Order[]; onClick?: (order: Order) => void; limit?: number; } const OrderListTable = (props: OrderListTableProps) => { let orders = props.orders; const [showCanceledOrders, setShowCanceledOrders] = useState(false); const [limit, setLimit] = useState(props.limit || 100); if (!showCanceledOrders) { orders = orders.filter((order: Order) => { return order.status != "CANCELED" }) } if (orders.length > limit) { orders = orders.slice(0, limit) } const rows = orders.map((order: Order) => ( { props.onClick ? props.onClick(order) : null; const nodes = e.currentTarget?.parentNode?.querySelectorAll(".selected") nodes?.forEach((node, i) => { node.classList.remove("selected") }) e.currentTarget.classList.add("selected") }}> {order.order_id} {order.symbol} {order.side} {order.order_type} {order.price} {order.quantity} {order.status} {formatDate(order.creation_time)} {order.tag} )); return
setShowCanceledOrders(event.currentTarget.checked)}/> {rows}
Order ID Symbol Side Order Type Price Quantity Status Creation Time Tag
} const formatDate = (d : Date) : string => { return moment(d).format("MMM Do YY hh:mm:ss A Z"); } export default OrderListTable;