All files / src/pages/playbooks PlaybookLog.tsx

0% Statements 0/31
0% Branches 0/8
0% Functions 0/5
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 66 67 68 69 70 71                                                                                                                                             
import { useDispatch } from "react-redux";
import { useParams } from "react-router-dom";
import { useLazyGetPlaybookExecutionQuery } from "../../store/features/playbook/api";
import { useEffect } from "react";
import {
  resetTimeRange,
  updateCustomTimeRange,
} from "../../store/features/timeRange/timeRangeSlice";
import {
  setPlaybookData,
  resetState,
} from "../../store/features/playbook/playbookSlice";
import Loading from "../../components/common/Loading";
import Heading from "../../components/Heading";
import Builder from "../../components/Playbooks/create/Builder";
 
function PlaybookLog() {
  const { playbook_run_id } = useParams();
  const dispatch = useDispatch();
  const [triggerGetPlaybookLog, { data, isLoading }] =
    useLazyGetPlaybookExecutionQuery();
  const playbook = (data as any)?.playbook_execution?.playbook;
  const timeRange = (data as any)?.playbook_execution?.time_range;
 
  useEffect(() => {
    Iif (playbook_run_id) {
      triggerGetPlaybookLog();
    }
  }, [playbook_run_id]);
 
  useEffect(() => {
    Iif (playbook && Object.keys(playbook).length > 0) {
      dispatch(setPlaybookData(playbook));
      dispatch(
        updateCustomTimeRange({
          startTime: timeRange.time_geq,
          endTime: timeRange.time_geq,
        }),
      );
    }
  }, [playbook]);
 
  useEffect(() => {
    return () => {
      dispatch(resetState());
      dispatch(resetTimeRange());
    };
  }, [dispatch]);
 
  Iif (isLoading || !playbook_run_id) {
    return <Loading />;
  }
 
  Iif (!data) {
    return <></>;
  }
 
  return (
    <div className="h-screen overflow-hidden">
      <Heading heading={playbook.name} />
      <div className="flex flex-col h-[calc(100%-80px)]">
        <main className="relative flex flex-1">
          <Builder />
        </main>
      </div>
    </div>
  );
}
 
export default PlaybookLog;