<commit_before>/* SPDX-License-Identifier: Apache-2.0
 *
 * BenchExec is a framework for reliable benchmarking.
 * This file is part of BenchExec.
 * Copyright (C) <NAME>. All rights reserved.
 */
import React from "react";
import { HashRouter as Router, Switch, Route, Link } from "react-router-dom";
import Table from "./ReactTable.js";
import Summary from "./Summary.js";
import Info from "./Info.js";
import SelectColumn from "./SelectColumn.js";
import ScatterPlot from "./ScatterPlot.js";
import QuantilePlot from "./QuantilePlot.js";
import LinkOverlay from "./LinkOverlay.js";
import Reset from "./Reset.js";
import { prepareTableData } from "../utils/utils";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faQuestionCircle } from "@fortawesome/free-solid-svg-icons";

const menuItems = [
  { key: "summary", title: "Summary", path: "/" },
  { key: "table", title: "Table", path: "/table" },
  { key: "quantile", title: "Quantile Plot", path: "/quantile" },
  { key: "scatter", title: "Scatter Plot", path: "/scatter" },
  {
    key: "info",
    title: "Info",
    path: "/info",
    icon: <FontAwesomeIcon icon={faQuestionCircle} />
  }
];

const getCurrentPath = () => document.location.hash.substr(1);

export default class Overview extends React.Component {
  constructor(props) {
    super(props);
    //imported data
    const { tableHeader, tools, columns, table, stats } = prepareTableData(
      props.data
    );

    this.originalTable = table;
    this.originalTools = tools;

    this.columns = columns;
    this.stats = stats;
    this.tableHeader = tableHeader;

    this.filteredData = [];

    //data is handled and changed here; To use it in other components hand it over with component
    //To change data in component (e.g. filter): function to change has to be in overview
    this.state = {
      tools,
      table,

      showSelectColumns: false,
      showLinkOverlay: false,
      filtered: [],
      tabIndex: 0,

      active: menuItems.find(i => i.path === getCurrentPath()).key,

      quantilePreSelection: tools[0].columns[1]
    };
  }

  // -----------------------SelectColumns-----------------------
  toggleSelectColumns = ev => {
    this.setState(prevState => ({
      showSelectColumns: !prevState.showSelectColumns
    }));
  };

  // -----------------------Link Overlay-----------------------
  toggleLinkOverlay = (ev, hrefRow) => {
    ev.preventDefault();

    this.setState(prevState => ({
      showLinkOverlay: !prevState.showLinkOverlay,
      link: hrefRow
    }));
  };

  // -----------------------Filter-----------------------
  setFilter = filteredData => {<commit_msg>Fix selection of active tab on initial load<commit_after>/* SPDX-License-Identifier: Apache-2.0
 *
 * BenchExec is a framework for reliable benchmarking.
 * This file is part of BenchExec.
 * Copyright (C) <NAME>. All rights reserved.
 */
import React from "react";
import { HashRouter as Router, Switch, Route, Link } from "react-router-dom";
import Table from "./ReactTable.js";
import Summary from "./Summary.js";
import Info from "./Info.js";
import SelectColumn from "./SelectColumn.js";
import ScatterPlot from "./ScatterPlot.js";
import QuantilePlot from "./QuantilePlot.js";
import LinkOverlay from "./LinkOverlay.js";
import Reset from "./Reset.js";
import { prepareTableData } from "../utils/utils";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faQuestionCircle } from "@fortawesome/free-solid-svg-icons";

const menuItems = [
  { key: "summary", title: "Summary", path: "/" },
  { key: "table", title: "Table", path: "/table" },
  { key: "quantile", title: "Quantile Plot", path: "/quantile" },
  { key: "scatter", title: "Scatter Plot", path: "/scatter" },
  {
    key: "info",
    title: "Info",
    path: "/info",
    icon: <FontAwesomeIcon icon={faQuestionCircle} />
  }
];

const getCurrentPath = () => document.location.hash.split("?")[0].substr(1);

export default class Overview extends React.Component {
  constructor(props) {
    super(props);
    //imported data
    const { tableHeader, tools, columns, table, stats } = prepareTableData(
      props.data
    );

    this.originalTable = table;
    this.originalTools = tools;

    this.columns = columns;
    this.stats = stats;
    this.tableHeader = tableHeader;

    this.filteredData = [];

    //data is handled and changed here; To use it in other components hand it over with component
    //To change data in component (e.g. filter): function to change has to be in overview
    this.state = {
      tools,
      table,

      showSelectColumns: false,
      showLinkOverlay: false,
      filtered: [],
      tabIndex: 0,

      active: (
        menuItems.find(i => i.path === getCurrentPath()) || { key: "summary" }
      ).key,

      quantilePreSelection: tools[0].columns[1]
    };
  }

  // -----------------------SelectColumns-----------------------
  toggleSelectColumns = ev => {
    this.setState(prevState => ({
      showSelectColumns: !prevState.showSelectColumns
    }));
  };

  // -----------------------Link Overlay-----------------------
  toggleLinkOverlay = (ev, hrefRow) => {
    ev.preventDefault();

    this.setState(prevState => ({
      showLinkOverlay: !prevState.showLinkOverlay,
      link: hrefRow
    }));
  };

  // -----------------------Filter-----------------------
  setFilter = filteredData => {
{'fraction_non_alphanumeric': 0.18560325684678017, 'fraction_numerical': 0.0024056254626202813, 'mean_word_length': 2.652027027027027, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '4939111', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1547, 'n_words': 440}