<commit_before>import ReactDOM from 'react-dom';
import { Popup } from 'react-leaflet';
import cn from 'classnames';
import Marker from '../location/marker';
import Component from '../../../pure-render-component';
import translatable from '../../../translatable';
import OverviewChart from '../../../visualizations/charts/overview';
import CostEffectiveness from '../../../visualizations/charts/cost-effectiveness';
import { cacheFn, download } from '../../../tools';
import ProcurementMethodChart from '../../../visualizations/charts/procurement-method';
// eslint-disable-next-line no-unused-vars
import styles from './style.less';

const addTenderDeliveryLocationId = cacheFn(
  (filters, id) => filters.set('tenderLoc', id),
);

class Tab extends translatable(Component) {}

export class ChartTab extends Tab {
  constructor(props) {
    super(props);
    this.state = {
      chartData: null,
    };
  }

  static getMargins() {
    return {
      t: 0,
      l: 50,
      r: 50,
      b: 50,
    };
  }

  static getChartClass() { return ''; }

  render() {
    const { filters, styling, years, translations, data, monthly, months } = this.props;
    const decoratedFilters = addTenderDeliveryLocationId(filters, data._id);
    const doExcelExport = () => download({
      ep: this.constructor.Chart.excelEP,
      filters: decoratedFilters,
      years,
      months,
      t: translationKey => this.t(translationKey),
    });
    return (
      <div className={cn('map-chart', this.constructor.getChartClass())}>
        <this.constructor.Chart
          filters={decoratedFilters}
          styling={styling}
          years={years}
          monthly={monthly}
          months={months}
          translations={translations}
          data={this.state.chartData}
          requestNewData={(_, chartData) => this.setState({ chartData })}
          width={500}
          height={350}
          margin={this.constructor.getMargins()}
          legend="h"
        />
      </div>
    );
  }
}

class LocationWrapper extends translatable(Component) {
  constructor(props) {
    super(props);
    this.state = {
      currentTab: 0,
    };
  }

  render() {
    const { currentTab } = this.state;
    const { data, translations, filters, years, styling, monthly, months } = this.props;
    const CurrentTab = this.constructor.TABS[currentTab];
    const t = translationKey => this.t(translationKey);
    return (
      <Marker {...this.props}>
        <Popup className="tender-locations-popup">
          <div>
            <header>
              {CurrentTab.prototype instanceof ChartTab &&
                <span className="chart-tools">
                  <a tabIndex={-1} role="button">
                    <img
                      src="assets/icons/export-very-black.svg"
                      alt="Export"
                      width="16"
                      height="16"
                    />
                  </a><commit_msg>OCE-354 Refactored the excel export functionality<commit_after>import ReactDOM from 'react-dom';
import { Popup } from 'react-leaflet';
import cn from 'classnames';
import Marker from '../location/marker';
import Component from '../../../pure-render-component';
import translatable from '../../../translatable';
import OverviewChart from '../../../visualizations/charts/overview';
import CostEffectiveness from '../../../visualizations/charts/cost-effectiveness';
import { cacheFn, download } from '../../../tools';
import ProcurementMethodChart from '../../../visualizations/charts/procurement-method';
// eslint-disable-next-line no-unused-vars
import styles from './style.less';

const addTenderDeliveryLocationId = cacheFn(
  (filters, id) => filters.set('tenderLoc', id),
);

class Tab extends translatable(Component) {}

export class ChartTab extends Tab {
  constructor(props) {
    super(props);
    this.state = {
      chartData: null,
    };
  }

  static getMargins() {
    return {
      t: 0,
      l: 50,
      r: 50,
      b: 50,
    };
  }

  static getChartClass() { return ''; }

  render() {
    const { filters, styling, years, translations, data, monthly, months } = this.props;
    const decoratedFilters = addTenderDeliveryLocationId(filters, data._id);
    return (
      <div className={cn('map-chart', this.constructor.getChartClass())}>
        <this.constructor.Chart
          filters={decoratedFilters}
          styling={styling}
          years={years}
          monthly={monthly}
          months={months}
          translations={translations}
          data={this.state.chartData}
          requestNewData={(_, chartData) => this.setState({ chartData })}
          width={500}
          height={350}
          margin={this.constructor.getMargins()}
          legend="h"
        />
      </div>
    );
  }
}

class LocationWrapper extends translatable(Component) {
  constructor(props) {
    super(props);
    this.state = {
      currentTab: 0,
    };
  }

  doExcelExport() {
    const { currentTab } = this.state;
    const { data, filters, years, months } = this.props;
    const CurrentTab = this.constructor.TABS[currentTab];
    download({
      ep: CurrentTab.Chart.excelEP,
      filters: addTenderDeliveryLocationId(filters, data._id),
      years,
      months,
      t: translationKey => this.t(translationKey),
    });
  }

  render() {
    const { currentTab } = this.state;
    const { data, translations, filters, years, styling, monthly, months } = this.props;
    const CurrentTab = this.constructor.TABS[currentTab];
    const t = translationKey => this.t(translationKey);
    return (
      <Marker {...this.props}>
        <Popup className="tender-locations-popup">
          <div>
            <header>
              {CurrentTab.prototype instanceof ChartTab &&
                <span className="chart-tools">
                  <a tabIndex={-1} role="button" onClick={() => this.doExcelExport()}>
                    <img
                      src="assets/icons/export-very-black.svg"
                      alt="Export"
                      width="16"
                      height="16"
                    />
                  </a>
{'fraction_non_alphanumeric': 0.14075767472240366, 'fraction_numerical': 0.006694970607446114, 'mean_word_length': 2.282422293676313, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3015679', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1697, 'n_words': 376}