All files / src/components/Playbooks/task/taskConfiguration/bulkTasks ExecutionVarFieldSelection.tsx

0% Statements 0/22
0% Branches 0/3
0% Functions 0/3
0% Lines 0/22

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                                                                                                           
import { useSelector } from "react-redux";
import { InputTypes } from "../../../../../types/inputs";
import CustomInput from "../../../../Inputs/CustomInput";
import { currentPlaybookSelector } from "../../../../../store/features/playbook/selectors";
import { isCSV } from "../../../../../utils/common/isCSV";
import { updateCardById } from "../../../../../utils/execution/updateCardById";
import useCurrentTask from "../../../../../hooks/playbooks/task/useCurrentTask";
import useIsPrefetched from "../../../../../hooks/playbooks/useIsPrefetched";
 
const key = "execution_configuration.bulk_execution_var_field";
 
type ExecutionVarFieldSelectionProps = {
  id?: string;
};
 
function ExecutionVarFieldSelection({ id }: ExecutionVarFieldSelectionProps) {
  const currentPlaybook = useSelector(currentPlaybookSelector);
  const [task] = useCurrentTask(id);
  const value = task?.execution_configuration?.bulk_execution_var_field;
  const global_variable_set = currentPlaybook?.global_variable_set ?? {};
  const variableOptions = Object.entries(global_variable_set).reduce(
    (acc: any, [key, value]) => {
      Iif (isCSV(value)) {
        acc.push({
          id: key,
          label: key,
        });
      }
      return acc;
    },
    [],
  );
  const isPrefetched = useIsPrefetched();
 
  const handleChange = (optionId: string) => {
    updateCardById(key, optionId, id);
  };
 
  return (
    <div className="mt-1">
      <CustomInput
        inputType={InputTypes.DROPDOWN}
        options={variableOptions}
        value={value}
        handleChange={handleChange}
        placeholder="Select an array variable"
        disabled={!!isPrefetched}
      />
    </div>
  );
}
 
export default ExecutionVarFieldSelection;