<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';

import { SaveWidgetModal, modalActions } from 'widget-editor';
import * as shareModalActions from 'components/share-modal/share-modal-actions';


// Redux
import { toggleTooltip } from 'actions/tooltip';

class ShareNexgddpTooltip extends React.Component {
  constructor(props) {
    super(props);
    this.onClickOutside = this.onClickOutside.bind(this);
    this.onClickSave = this.onClickSave.bind(this);
    this.onClickShare = this.onClickShare.bind(this);
  }

  componentDidMount() {
    window.addEventListener('click', this.onClickOutside);
  }

  componentWillUnmount() {
    window.removeEventListener('click', this.onClickOutside);
  }

  onClickOutside(e) {
    const el = document.querySelector('.c-tooltip-tether');
    const clickOutside = el && el.contains && !el.contains(e.target);
    if (clickOutside) {
      this.props.toggleTooltip(false);
    }
  }

  onClickSave() {
    this.props.toggleTooltip(false);
    this.props.toggleModal(true, {
      children: SaveWidgetModal,
      childrenProps: {
        datasetId: this.props.datasetId,
        getWidgetConfig: this.props.getWidgetConfig,
        onClickCheckWidgets: this.props.onClickCheckWidgets
      }
    });
  }

  onClickShare() {
    const { open, datasetSlug, render } = this.props;
    const { origin, search } = window.location;
    this.props.setOpen(!open);
    this.props.setLinks({ embed: `${origin}/embed/nexgddp/${datasetSlug}${search}&render=${render}` });
    this.props.setTab('embed');
  }

  render() {
    return (
      <div className="c-share-nexgddp-chart-tooltip">
        <ul>
          <li><button type="button" onClick={this.onClickSave}>Save widget</button></li>
          <li><button type="button" onClick={this.onClickShare}>Embed</button></li>
        </ul>
      </div>
    );
  }
}
<commit_msg>Fix an issue where a non-logged user would be able to save the vis.<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';

import { SaveWidgetModal, modalActions, getConfig } from 'widget-editor';
import * as shareModalActions from 'components/share-modal/share-modal-actions';


// Redux
import { toggleTooltip } from 'actions/tooltip';

class ShareNexgddpTooltip extends React.Component {
  constructor(props) {
    super(props);
    this.onClickOutside = this.onClickOutside.bind(this);
    this.onClickSave = this.onClickSave.bind(this);
    this.onClickShare = this.onClickShare.bind(this);
  }

  componentDidMount() {
    window.addEventListener('click', this.onClickOutside);
  }

  componentWillUnmount() {
    window.removeEventListener('click', this.onClickOutside);
  }

  onClickOutside(e) {
    const el = document.querySelector('.c-tooltip-tether');
    const clickOutside = el && el.contains && !el.contains(e.target);
    if (clickOutside) {
      this.props.toggleTooltip(false);
    }
  }

  onClickSave() {
    this.props.toggleTooltip(false);
    this.props.toggleModal(true, {
      children: SaveWidgetModal,
      childrenProps: {
        datasetId: this.props.datasetId,
        getWidgetConfig: this.props.getWidgetConfig,
        onClickCheckWidgets: this.props.onClickCheckWidgets
      }
    });
  }

  onClickShare() {
    const { open, datasetSlug, render } = this.props;
    const { origin, search } = window.location;
    this.props.setOpen(!open);
    this.props.setLinks({ embed: `${origin}/embed/nexgddp/${datasetSlug}${search}&render=${render}` });
    this.props.setTab('embed');
  }

  render() {
    return (
      <div className="c-share-nexgddp-chart-tooltip">
        <ul>
          { getConfig().userToken && <li><button type="button" onClick={this.onClickSave}>Save widget</button></li> }
          <li><button type="button" onClick={this.onClickShare}>Embed</button></li>
        </ul>
      </div>
    );
  }
}

{'fraction_non_alphanumeric': 0.14350912778904665, 'fraction_numerical': 0.0, 'mean_word_length': 3.5240825688073394, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '1884875', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1221, 'n_words': 211}