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

0% Statements 0/17
0% Branches 0/7
0% Functions 0/4
0% Lines 0/17

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                                                                                                                                                                         
import React, { useState } from "react";
import RadioOptions from "../../common/RadioOptions/index.tsx";
import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableRow,
} from "@mui/material";
import CopyCode from "../../common/CopyCode/index.tsx";
 
const options = [
  {
    id: "body",
    label: "Body",
  },
  {
    id: "headers",
    label: "Response Headers",
  },
];
 
function PlaybookAPIActionOutput({ output }) {
  const [selected, setSelected] = useState("body");
 
  const handleChange = (option) => {
    setSelected(option.id);
  };
 
  return (
    <div>
      <RadioOptions
        options={options}
        selectedId={selected}
        handleSelect={handleChange}
      />
 
      <HandleSelectedRender output={output} selectedId={selected} />
    </div>
  );
}
 
export default PlaybookAPIActionOutput;
 
const HandleSelectedRender = ({ selectedId, output }) => {
  const headers = output.response_headers;
  switch (selectedId) {
    case "body":
      return (
        <div style={{ display: "flex", flexDirection: "column" }}>
          <div
            className={
              "my-2 bg-white max-w-xl rounded-lg border resize-none p-2 text-sm overflow-scroll h-48"
            }>
            <CopyCode
              content={JSON.stringify(output.response_body, null, 2) ?? ""}
              language={"json"}
            />
          </div>
        </div>
      );
    case "headers":
      return (
        <Table>
          <TableHead>
            <TableRow>
              <TableCell>Key</TableCell>
              <TableCell>Value</TableCell>
            </TableRow>
          </TableHead>
          <TableBody>
            {Object.keys(headers ?? {}).map((key) => (
              <TableRow key={key}>
                <TableCell>{key}</TableCell>
                <TableCell>{headers[key]}</TableCell>
              </TableRow>
            ))}
          </TableBody>
        </Table>
      );
    default:
      return <></>;
  }
};