All files / src/components/DynamicAlerts/create SelectTaskType.tsx

0% Statements 0/30
0% Branches 0/8
0% Functions 0/5
0% Lines 0/28

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                                                                                                                                   
import CustomInput from "../../Inputs/CustomInput";
import { InputTypes } from "../../../types";
import useCurrentTask from "../../../hooks/playbooks/task/useCurrentTask";
import { useDispatch, useSelector } from "react-redux";
import { commonKeySelector } from "../../../store/features/common/selectors";
import { ResultTypeTypes } from "../../../utils/conditionals/resultTypeOptions";
import { updateCardById } from "../../../utils/execution/updateCardById";
import {
  updateTaskType,
  updateSource,
} from "../../../store/features/playbook/playbookSlice";
import { unsupportedBuilderOptions } from "../../../utils/playbook/unsupportedBuilderOptions";
 
const resultTypeKeysAvailable = [ResultTypeTypes.TIMESERIES];
 
type SelectTaskTypePropTypes = {
  id: string;
};
 
function SelectTaskType({ id }: SelectTaskTypePropTypes) {
  const dispatch = useDispatch();
  const { supportedTaskTypes } = useSelector(commonKeySelector);
  const options = (
    supportedTaskTypes?.filter(
      (type) =>
        resultTypeKeysAvailable.includes(type.result_type) &&
        !unsupportedBuilderOptions.includes(`${type.source} ${type.task_type}`),
    ) ?? []
  ).map((type) => ({
    id: `${type.source}-${type.task_type}`,
    label: type.display_name,
    type: type,
  }));
  const [task, currentId] = useCurrentTask(id);
  const taskType = task?.[task?.source?.toLowerCase()]?.type;
 
  const handleTaskTypeChange = (id: string) => {
    const val = options.find((e) => e.id === id)?.type;
    Iif (!val) return;
    dispatch(updateSource({ id: currentId, value: val.source }));
    dispatch(updateTaskType({ id: currentId, value: val.task_type }));
    updateCardById("ui_requirement.resultType", val.result_type, currentId);
    updateCardById(
      "ui_requirement.model_type",
      val.supported_model_types?.[0]?.model_type ?? task?.source,
      currentId,
    );
    Iif (!task?.ui_requirement?.userEnteredDescription)
      updateCardById("description", val.display_name, currentId);
  };
 
  return (
    <div className="flex flex-col">
      <CustomInput
        inputType={InputTypes.DROPDOWN}
        label="Task Type"
        options={options}
        value={`${task?.source}-${taskType}`}
        handleChange={handleTaskTypeChange}
      />
    </div>
  );
}
 
export default SelectTaskType;