<commit_before>import React, { useEffect, useState } from "react";
import { Avatar, Switch, Table, Typography } from "antd";
import { createProjectLink } from "../../../utilities/link-utilities";
import {
  addAssociatedProject,
  getAssociatedProjects,
  removeAssociatedProject
} from "../../../apis/projects/projects";
import { TextFilter } from "../../../components/Tables/fitlers";
import { createListFilterByUniqueAttribute } from "../../../components/Tables/filter-utilities";
import { SPACE_MD } from "../../../styles/spacing";

const { Text } = Typography;

export default function ViewAssociatedProjects() {
  const [projects, setProjects] = useState([]);
  const [organismFilters, setOrganismFilters] = useState([]);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    getAssociatedProjects(window.project.id).then(data => {
      setProjects(data.associatedProjectList);
      setOrganismFilters(
        createListFilterByUniqueAttribute({
          list: data.associatedProjectList,
          attr: "organism"
        })
      );
      setLoading(false);
    });
  }, [getAssociatedProjects]);

  function updateProject(checked, project) {
    setLoading(true);
    let promise;
    if (checked) {
      promise = addAssociatedProject(window.project.id, project.id);
    } else {
      promise = removeAssociatedProject(window.project.id, project.id);
    }
    promise.then(() => {
      project.associated = checked;
      setProjects([...projects]);
      setLoading(false);
    });
  }

  const columns = [
    {
      key: "project",
      render: project => (
        <>
          <span style={{ marginRight: SPACE_MD }}>
            {window.PAGE.permissions ? (
              <Switch
                checked={project.associated}
                loading={project.updating}
                onClick={checked => updateProject(checked, project)}
              />
            ) : (
              <Avatar icon="folder" />
            )}
          </span>{" "}
          {createProjectLink(project)}
        </>
      ),
      title: "Project",
      filterDropdown: props => <TextFilter {...props} />,
      onFilter: (value, project) => {
        return project.label
          .toString()
          .toLowerCase()
          .includes(value.toLowerCase());
      },
      sorter: (a, b) => ("" + a.label).localeCompare("" + b.label)
    },
    {
      key: "organism",
      dataIndex: "organism",
      align: "right",
      title: "Organism",
      render: text => <Text type="secondary">{text}</Text>,
      filters: organismFilters,
      onFilter: (value, record) =>
        record.organism === value || (!record.organism && value === "unknown"),
      sorter: (a, b) => ("" + a.organism).localeCompare("" + b.organism)
    }
  ];

  return (
    <Table
      bordered
      rowKey="id"
      loading={loading}<commit_msg>Fixed eslint issue with unnamed render method<commit_after>import React, { useEffect, useState } from "react";
import { Avatar, Switch, Table, Typography } from "antd";
import { createProjectLink } from "../../../utilities/link-utilities";
import {
  addAssociatedProject,
  getAssociatedProjects,
  removeAssociatedProject
} from "../../../apis/projects/projects";
import { TextFilter } from "../../../components/Tables/fitlers";
import { createListFilterByUniqueAttribute } from "../../../components/Tables/filter-utilities";
import { SPACE_MD } from "../../../styles/spacing";

const { Text } = Typography;

export default function ViewAssociatedProjects() {
  const [projects, setProjects] = useState([]);
  const [organismFilters, setOrganismFilters] = useState([]);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    getAssociatedProjects(window.project.id).then(data => {
      setProjects(data.associatedProjectList);
      setOrganismFilters(
        createListFilterByUniqueAttribute({
          list: data.associatedProjectList,
          attr: "organism"
        })
      );
      setLoading(false);
    });
  }, [getAssociatedProjects]);

  function updateProject(checked, project) {
    setLoading(true);
    let promise;
    if (checked) {
      promise = addAssociatedProject(window.project.id, project.id);
    } else {
      promise = removeAssociatedProject(window.project.id, project.id);
    }
    promise.then(() => {
      project.associated = checked;
      setProjects([...projects]);
      setLoading(false);
    });
  }

  const columns = [
    {
      key: "project",
      render(project) {
        return (
          <>
            <span style={{ marginRight: SPACE_MD }}>
              {window.PAGE.permissions ? (
                <Switch
                  checked={project.associated}
                  loading={project.updating}
                  onClick={checked => updateProject(checked, project)}
                />
              ) : (
                <Avatar icon="folder" />
              )}
            </span>{" "}
            {createProjectLink(project)}
          </>
        );
      },
      title: "Project",
      filterDropdown: props => <TextFilter {...props} />,
      onFilter: (value, project) => {
        return project.label
          .toString()
          .toLowerCase()
          .includes(value.toLowerCase());
      },
      sorter: (a, b) => ("" + a.label).localeCompare("" + b.label)
    },
    {
      key: "organism",
      dataIndex: "organism",
      align: "right",
      title: "Organism",
      render(text) {
        return <Text type="secondary">{text}</Text>;
      },
      filters: organismFilters,
      onFilter: (value, record) =>
        record.organism === value || (!record.organism && value === "unknown"),
      sorter: (a, b) => ("" + a.organism).localeCompare("" + b.organism)
    }
  ];

  return (
    <Table
      bordered
      rowKey="id"
      loading={loading}
{'fraction_non_alphanumeric': 0.15495371957490572, 'fraction_numerical': 0.0, 'mean_word_length': 2.3134582623509368, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 41, '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': '7155298', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1662, 'n_words': 319}