All files / src/components/Playbooks/executions PlaybookExecutions.tsx

0% Statements 0/31
0% Branches 0/8
0% Functions 0/3
0% Lines 0/31

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                                                                                                                                 
/* eslint-disable react-hooks/exhaustive-deps */
import { useNavigate, useParams } from "react-router-dom";
import Heading from "../../Heading.js";
import { useEffect } from "react";
import SuspenseLoader from "../../Skeleton/SuspenseLoader.js";
import TableSkeleton from "../../Skeleton/TableLoader.js";
import ExecutionsTable from "./ExecutionsTable.js";
import Loading from "../../common/Loading/index.tsx";
import { useSelector } from "react-redux";
import { ChevronLeft } from "@mui/icons-material";
import { useGetPlaybookExecutionsQuery } from "../../../store/features/playbook/api/getPlaybookExecutionsApi.ts";
import { playbookSelector } from "../../../store/features/playbook/playbookSlice.ts";
import { useLazyGetPlaybookQuery } from "../../../store/features/playbook/api/getPlaybookApi.ts";
import PaginatedTable from "../../PaginatedTable.tsx";
import usePaginationComponent from "../../../hooks/common/usePaginationComponent.ts";
 
const PlaybookExecutions = () => {
  const { id: playbookId } = useParams();
  const navigate = useNavigate();
  const { data, isFetching, refetch } = useGetPlaybookExecutionsQuery({
    playbookId: playbookId ?? "",
  });
  const [triggerGetPlaybook, { isLoading: workflowLoading }] =
    useLazyGetPlaybookQuery();
  const { currentPlaybook } = useSelector(playbookSelector);
  const playbooksList = data?.playbook_executions;
  const total = data?.meta?.total_count;
  usePaginationComponent(refetch);
 
  useEffect(() => {
    Iif (playbookId != null) {
      triggerGetPlaybook({ playbookId });
    }
  }, [playbookId]);
 
  Iif (workflowLoading) {
    return <Loading title="Your playbook executions is loading..." />;
  }
 
  return (
    <div>
      <Heading heading={"Playbook Executions-" + currentPlaybook?.name} />
      <button
        onClick={() => navigate(-1)}
        className="p-1 text-sm border border-violet-500 rounded m-2 text-violet-500 flex items-center cursor-pointer hover:text-white hover:bg-violet-500 transition-all">
        <ChevronLeft /> All Playbooks
      </button>
      <SuspenseLoader loading={isFetching} loader={<TableSkeleton />}>
        <PaginatedTable
          renderTable={ExecutionsTable}
          data={playbooksList ?? []}
          total={total}
          tableContainerStyles={
            playbooksList?.length
              ? {}
              : { maxHeight: "35vh", minHeight: "35vh" }
          }
        />
      </SuspenseLoader>
    </div>
  );
};
 
export default PlaybookExecutions;