<commit_before>import React from "react";
import { Form, Input, Modal, notification, Typography } from "antd";
import { navigate } from "@reach/router";
import DnDTable from "../../../components/ant.design/DnDTable";
import { HelpPopover } from "../../../components/popovers";
import { useDispatch, useSelector } from "react-redux";
import { createNewMetadataTemplate } from "../redux/templatesSlice";
import { unwrapResult } from "@reduxjs/toolkit";
import { addKeysToList } from "../../../utilities/http-utilities";

const { Text } = Typography;

/**
 * Component to create a new metadata template with a list of metadata fields
 *
 * @param {JSX.Element} children
 * @param {number} projectId - identifier for the current project
 * @param {Object[]} fields - list of metadata fields for the template
 * @returns {JSX.Element}
 * @constructor
 */
export function MetadataTemplateCreate({ children, projectId, fields = [] }) {
  const dispatch = useDispatch();
  const { templates } = useSelector((state) => state.templates);
  const [names, setNames] = React.useState(undefined);
  const [visible, setVisible] = React.useState(false);
  const [fieldsState, setFieldsState] = React.useState([]);
  const [form] = Form.useForm();

  React.useEffect(() => {
    if (fields.length) {
      setFieldsState(addKeysToList(fields, "field"));
    }
  }, [fields]);

  React.useEffect(() => {
    /*
    Need to get a list of template names so that there can only be distinct
    names.
     */
    if (templates) {
      const templateNames = new Set(
        templates.map((template) => template.label)
      );
      setNames(templateNames);
    }
  }, [templates]);

  /**
   * Create the metadata template.  Ensures the name field is properly validated.
   * Once created the user is redirected to the template details page.
   */
  const onOk = async () => {
    const values = await form.validateFields();
    values.fields = fieldsState;
    dispatch(createNewMetadataTemplate({ projectId, template: values }))
      .then(unwrapResult)<commit_msg>Updated JSDoc<commit_after>import { navigate } from "@reach/router";
import { unwrapResult } from "@reduxjs/toolkit";
import { Form, Input, Modal, notification, Typography } from "antd";
import React from "react";
import { useDispatch, useSelector } from "react-redux";
import DnDTable from "../../../components/ant.design/DnDTable";
import { HelpPopover } from "../../../components/popovers";
import { addKeysToList } from "../../../utilities/http-utilities";
import { createNewMetadataTemplate } from "../redux/templatesSlice";

const { Text } = Typography;

/**
 * Component to create a new metadata template with a list of metadata fields
 *
 * @param {JSX.Element} children
 * @param {number} projectId - identifier for the current project
 * @param {Object[]} fields - list of metadata fields for the template
 * @returns {JSX.Element}
 * @constructor
 */
export function MetadataTemplateCreate({ children, projectId, fields = [] }) {
  const dispatch = useDispatch();
  const { templates } = useSelector((state) => state.templates);
  const [names, setNames] = React.useState(undefined);
  const [visible, setVisible] = React.useState(false);
  const [fieldsState, setFieldsState] = React.useState([]);
  const [form] = Form.useForm();

  React.useEffect(() => {
    if (fields.length) {
      setFieldsState(addKeysToList(fields, "field"));
    }
  }, [fields]);

  React.useEffect(() => {
    /*
    Need to get a list of template names so that there can only be distinct
    names within any given project.
     */
    if (templates) {
      const templateNames = new Set(
        templates.map((template) => template.label)
      );
      setNames(templateNames);
    }
  }, [templates]);

  /**
   * Create the metadata template.  Ensures the name field is properly validated.
   * Once created the user is redirected to the template details page.
   */
  const onOk = async () => {
    const values = await form.validateFields();
    values.fields = fieldsState;
    dispatch(createNewMetadataTemplate({ projectId, template: values }))
      .then(unwrapResult)
{'fraction_non_alphanumeric': 0.13679359689546447, 'fraction_numerical': 0.0, 'mean_word_length': 3.644144144144144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4826893', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1152, 'n_words': 360}