All files / src/components/Playbooks/outputs PlayBookRunDataTable.tsx

0% Statements 0/26
0% Branches 0/22
0% Functions 0/8
0% Lines 0/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135                                                                                                                                                                                                                                                                             
import { useState, useEffect } from "react";
import styles from "./index.module.css";
 
import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableRow,
  Button,
  Dialog,
  DialogActions,
} from "@mui/material";
 
import SeeMoreTextWithoutModal from "../../common/SeeMoreTextWithoutModal/index.tsx";
import { isDate, renderTimestamp } from "../../../utils/common/dateUtils.ts";
 
const PlayBookRunDataTable = ({ title, result, timestamp, showHeading }) => {
  const [showTable, setShowTable] = useState(false);
  const [open, setOpen] = useState(false);
  const [tableLoading, setTableLoading] = useState(true);
 
  const [tableData, setTableData] = useState<any>([]);
 
  useEffect(() => {
    Iif (
      result &&
      result.table &&
      result.table.rows &&
      result.table.rows.length > 0
    ) {
      setShowTable(true);
      setTableData(result.table.rows);
      setTableLoading(false);
    }
  }, [result]);
 
  const handleClose = () => {
    setOpen(false);
  };
 
  Iif (tableLoading)
    return (
      <div>
        <p className="text-xs font-semibold">Loading...</p>
      </div>
    );
 
  return (
    <div
      className={`${
        showHeading ? "h-full" : "h-auto"
      } border p-2 rounded mb-1 overflow-auto`}>
      <p className={styles["graph-title"]}>{title}</p>
      {!showTable && <p className={styles["graph-error"]}>No data available</p>}
      {showTable && (
        <Table
          stickyHeader
          className={`text-xs min-w-[50px] !border !rounded !overflow-hidden mt-2 h-full`}>
          <TableHead>
            <TableRow>
              {tableData[0]?.columns
                ?.filter((x) => x.name !== "@ptr")
                .map((col, index) => {
                  return (
                    <TableCell
                      key={index}
                      className="!w-fit !min-w-[50px] !max-w-[200px] !border">
                      <SeeMoreTextWithoutModal
                        text={col.name}
                        maxLength={50}
                        className={"font-bold text-xs"}
                      />
                    </TableCell>
                  );
                })}
            </TableRow>
          </TableHead>
          <TableBody>
            {tableData?.map((row, rowIndex) => {
              return (
                <TableRow key={rowIndex}>
                  {row?.columns
                    ?.filter((x) => x.name !== "@ptr")
                    .map((col, colIndex) => {
                      return (
                        <TableCell
                          key={colIndex}
                          className={`${
                            col.name === "@message"
                              ? "min-w-[100px]"
                              : "min-w-[50px]"
                          } !text-xs !border !min-w-[max-content]`}>
                          <SeeMoreTextWithoutModal
                            text={
                              isDate(col.value)
                                ? renderTimestamp(
                                    new Date(col.value).getTime() / 1000,
                                  )
                                : col.value
                            }
                            maxLength={200}
                          />
                        </TableCell>
                      );
                    })}
                </TableRow>
              );
            })}
          </TableBody>
        </Table>
      )}
      {!showTable && timestamp && (
        <p className={styles["graph-ts-error"]}>
          <i>Updated at: {renderTimestamp(timestamp)}</i>
        </p>
      )}
      {showTable && timestamp && (
        <p className={styles["graph-ts"]}>
          <i>Updated at: {renderTimestamp(timestamp)}</i>
        </p>
      )}
      <Dialog open={open} onClose={handleClose}>
        <DialogActions>
          <Button onClick={handleClose} color="primary">
            Close
          </Button>
        </DialogActions>
      </Dialog>
    </div>
  );
};
 
export default PlayBookRunDataTable;