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

import { Table } from 'components';
import Notification from 'components/Notification';

class WidgetsPage extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      selectedRow: null,
      deleteWarning: false,
      deleteSuccess: false,
      deleteError: false
    };
  }

  onClickAction(action, row) {
    if (action === 'delete') {
      this.setState({ deleteWarning: true, selectedRow: row });
    } else {
      window.location = row.edit;
    }
  }

  onClickDelete() {
    const { selectedRow } = this.state;
    fetch(selectedRow.delete, {
      method: 'DELETE',
      credentials: 'include'
    }).then(() => {
      window.location.reload();
    }).catch(() => {
      this.setState({
        deleteSuccess: false,
        deleteError: true,
        deleteWarning: false
      });
    });
  }

  render() {
    // eslint-disable-next-line camelcase
    const rows = this.props.widgets.map(({ widget, delete_url, edit_url }) => ({
      id: { value: widget.id },
      name: { value: widget.name, sortable: true },
      description: { value: widget.description },
      ...(edit_url ? { edit: edit_url } : {}),
      ...(delete_url ? { delete: delete_url } : {})
    }));<commit_msg>Fix a bug that prevent the managers from editing or deleting the widgets<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';

import { Table } from 'components';
import Notification from 'components/Notification';

class WidgetsPage extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      selectedRow: null,
      deleteWarning: false,
      deleteSuccess: false,
      deleteError: false
    };
  }

  onClickAction(action, row) {
    if (action === 'delete') {
      this.setState({ deleteWarning: true, selectedRow: row });
    } else {
      window.location = row.edit.value;
    }
  }

  onClickDelete() {
    const { selectedRow } = this.state;
    fetch(selectedRow.delete.value, {
      method: 'DELETE',
      credentials: 'include'
    }).then(() => {
      window.location.reload();
    }).catch(() => {
      this.setState({
        deleteSuccess: false,
        deleteError: true,
        deleteWarning: false
      });
    });
  }

  render() {
    // eslint-disable-next-line camelcase
    const rows = this.props.widgets.map(({ widget, delete_url, edit_url }) => ({
      id: { value: widget.id },
      name: { value: widget.name, sortable: true },
      description: { value: widget.description },
      ...(edit_url ? { edit: { value: edit_url } } : {}),
      ...(delete_url ? { delete: { value: delete_url } } : {})
    }));
{'fraction_non_alphanumeric': 0.14873078298176617, 'fraction_numerical': 0.0, 'mean_word_length': 2.6384915474642394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1082515', 'n_tokens_mistral': 829, 'n_tokens_neox': 831, 'n_words': 200}