<commit_before>import { notification, Space, Table, Typography } from "antd";
import React from "react";
import { useGetProjectDetailsQuery } from "../../../../apis/projects/project";
import {
  downloadProjectReferenceFile,
  getProjectReferenceFiles,
  removeProjectReferenceFile,
  uploadProjectReferenceFiles,
} from "../../../../apis/references/reference-files";
import { InfoAlert } from "../../../../components/alerts";
import {
  DownloadTableItemButton,
  RemoveTableItemButton,
} from "../../../../components/Buttons";
import { DragUpload } from "../../../../components/files/DragUpload";
import { ContentLoading } from "../../../../components/loader";

import { formatInternationalizedDateTime } from "../../../../utilities/date-utilities";

const { Title } = Typography;

/**
 * React component for render the reference files page for the project.
 * @returns {*}
 * @constructor
 */
export default function ReferenceFiles({ projectId }) {
  const { data: project = {}, isLoading } = useGetProjectDetailsQuery(
    projectId
  );
  const [projectReferenceFiles, setProjectReferenceFiles] = React.useState([]);
  const [, setProgress] = React.useState(0);

  React.useEffect(updateReferenceFileTable, [projectId]);

  // Object to hold alert messages for if a user can manage the project or not
  const alertMessage = {
    true: {
      text: i18n("ReferenceFile.ownerUploadFileAlert"),
      alertClass: "t-rf-owner",
    },
    false: {
      text: i18n("ReferenceFile.userUploadFileAlert"),
      alertClass: "t-rf-user",
    },
  };

  const uploadHintMessage = {
    true: i18n("ReferenceFile.singleOrMultiple"),
    false: "Supports single file upload",
  };

  // Columns for the reference file table
  const referenceFileTableColumns = [
    {
      title: i18n("ReferenceFile.name"),
      dataIndex: "name",
    },
    {
      title: i18n("ReferenceFile.size"),
      dataIndex: "size",
    },
    {
      title: i18n("ReferenceFile.added"),
      dataIndex: "createdDate",
      render(text) {
        return formatInternationalizedDateTime(text);
      },
    },
    {
      align: "right",
      render(file) {
        let actionButtons = [
          <DownloadTableItemButton
            key={`download-btn-${file.id}`}
            onDownload={() => downloadProjectReferenceFile(file.id)}
            onDownloadSuccess={() => {
              notification.success({
                message: i18n(
                  "ReferenceFile.downloadingFileSuccess",
                  file.name,
                  project.name
                ),
              });
            }}
            tooltipText={i18n("ReferenceFile.downloadTooltip")}
            disableDownloadButton={
              file.size === i18n("server.projects.reference-file.not-found")
            }
          />,
          // Only display remove button for reference files if user can manage project
          project.canManage ? (
            <RemoveTableItemButton
              key={`remove-btn-${file.id}`}
              onRemove={() => removeProjectReferenceFile(projectId, file.id)}
              onRemoveSuccess={() => {
                updateReferenceFileTable();
              }}
              tooltipText={i18n("ReferenceFile.removeTooltip")}
              confirmText={i18n(
                "ReferenceFile.confirmText",
                file.name,
                project.name
              )}
            />
          ) : null,
        ];
        // Return download and remove buttons spaced
        return <Space size="small">{actionButtons}</Space>;
      },
    },
  ];

  // Get the reference files for the project
  function updateReferenceFileTable() {
    getProjectReferenceFiles(projectId)
      .then((files) => {
        setProjectReferenceFiles(files);
      })
      .catch((message) => {
        notification.error({ message });
      });
  }

  /* Custom request for drag upload to get progress of uploads
   * as well as display notifications for reference file upload
   * success/error
   */
  const uploadFiles = async (options) => {
    const { onSuccess, onError, file, onProgress } = options;

    const formData = new FormData();
    const config = {
      headers: { "content-type": "multipart/form-data" },
      onUploadProgress: (event) => {
        const percent = Math.floor((event.loaded / event.total) * 100);
        setProgress(percent);
        if (percent === 100) {
          setTimeout(() => setProgress(0), 1000);
        }
        onProgress({ percent: Math.floor(event.loaded / event.total) * 100 });
      },
    };
    formData.append("file", file);

    uploadProjectReferenceFiles(projectId, formData, config)
      .then(() => {
        onSuccess("Ok");
        notification.success({
          message: `${i18n(
            "ReferenceFile.uploadFileSuccess",
            file.name,
            project.name
          )}`,
        });<commit_msg>Updated project name to project label<commit_after>import { notification, Space, Table, Typography } from "antd";
import React from "react";
import { useGetProjectDetailsQuery } from "../../../../apis/projects/project";
import {
  downloadProjectReferenceFile,
  getProjectReferenceFiles,
  removeProjectReferenceFile,
  uploadProjectReferenceFiles,
} from "../../../../apis/references/reference-files";
import { InfoAlert } from "../../../../components/alerts";
import {
  DownloadTableItemButton,
  RemoveTableItemButton,
} from "../../../../components/Buttons";
import { DragUpload } from "../../../../components/files/DragUpload";
import { ContentLoading } from "../../../../components/loader";

import { formatInternationalizedDateTime } from "../../../../utilities/date-utilities";

const { Title } = Typography;

/**
 * React component for render the reference files page for the project.
 * @returns {*}
 * @constructor
 */
export default function ReferenceFiles({ projectId }) {
  const { data: project = {}, isLoading } = useGetProjectDetailsQuery(
    projectId
  );
  const [projectReferenceFiles, setProjectReferenceFiles] = React.useState([]);
  const [, setProgress] = React.useState(0);

  React.useEffect(updateReferenceFileTable, [projectId]);

  // Object to hold alert messages for if a user can manage the project or not
  const alertMessage = {
    true: {
      text: i18n("ReferenceFile.ownerUploadFileAlert"),
      alertClass: "t-rf-owner",
    },
    false: {
      text: i18n("ReferenceFile.userUploadFileAlert"),
      alertClass: "t-rf-user",
    },
  };

  const uploadHintMessage = {
    true: i18n("ReferenceFile.singleOrMultiple"),
    false: "Supports single file upload",
  };

  // Columns for the reference file table
  const referenceFileTableColumns = [
    {
      title: i18n("ReferenceFile.name"),
      dataIndex: "name",
    },
    {
      title: i18n("ReferenceFile.size"),
      dataIndex: "size",
    },
    {
      title: i18n("ReferenceFile.added"),
      dataIndex: "createdDate",
      render(text) {
        return formatInternationalizedDateTime(text);
      },
    },
    {
      align: "right",
      render(file) {
        let actionButtons = [
          <DownloadTableItemButton
            key={`download-btn-${file.id}`}
            onDownload={() => downloadProjectReferenceFile(file.id)}
            onDownloadSuccess={() => {
              notification.success({
                message: i18n(
                  "ReferenceFile.downloadingFileSuccess",
                  file.name,
                  project.label
                ),
              });
            }}
            tooltipText={i18n("ReferenceFile.downloadTooltip")}
            disableDownloadButton={
              file.size === i18n("server.projects.reference-file.not-found")
            }
          />,
          // Only display remove button for reference files if user can manage project
          project.canManage ? (
            <RemoveTableItemButton
              key={`remove-btn-${file.id}`}
              onRemove={() => removeProjectReferenceFile(projectId, file.id)}
              onRemoveSuccess={() => {
                updateReferenceFileTable();
              }}
              tooltipText={i18n("ReferenceFile.removeTooltip")}
              confirmText={i18n(
                "ReferenceFile.confirmText",
                file.name,
                project.label
              )}
            />
          ) : null,
        ];
        // Return download and remove buttons spaced
        return <Space size="small">{actionButtons}</Space>;
      },
    },
  ];

  // Get the reference files for the project
  function updateReferenceFileTable() {
    getProjectReferenceFiles(projectId)
      .then((files) => {
        setProjectReferenceFiles(files);
      })
      .catch((message) => {
        notification.error({ message });
      });
  }

  /* Custom request for drag upload to get progress of uploads
   * as well as display notifications for reference file upload
   * success/error
   */
  const uploadFiles = async (options) => {
    const { onSuccess, onError, file, onProgress } = options;

    const formData = new FormData();
    const config = {
      headers: { "content-type": "multipart/form-data" },
      onUploadProgress: (event) => {
        const percent = Math.floor((event.loaded / event.total) * 100);
        setProgress(percent);
        if (percent === 100) {
          setTimeout(() => setProgress(0), 1000);
        }
        onProgress({ percent: Math.floor(event.loaded / event.total) * 100 });
      },
    };
    formData.append("file", file);

    uploadProjectReferenceFiles(projectId, formData, config)
      .then(() => {
        onSuccess("Ok");
        notification.success({
          message: `${i18n(
            "ReferenceFile.uploadFileSuccess",
            file.name,
            project.label
          )}`,
        });
{'fraction_non_alphanumeric': 0.1353475553740941, 'fraction_numerical': 0.007961620904358478, 'mean_word_length': 2.233663366336634, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7253465', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2557, 'n_words': 563}