<commit_before>/**
 * @file
 *
 * @brief shows errors in a small snackbar on the bottom of the UI
 *
 * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
 */

import React from 'react'
import Snackbar from 'material-ui/Snackbar'
import Dialog from 'material-ui/Dialog'
import FlatButton from 'material-ui/FlatButton'

export default class ErrorSnackbar extends React.Component {
  constructor (...args) {
    super(...args)
    this.state = { dialogOpen: false }
  }

  handleOpen = () => {
    this.setState({ dialogOpen: true })
  }

  handleClose = () => {
    const { dismissError } = this.props
    this.setState({ dialogOpen: false })
    dismissError()
  }

  render () {
    const { error, dismissError } = this.props
    const { dialogOpen } = this.state

    if (error) console.error(error)

    const message = typeof error === 'string' ? error : error.message
    const name = (error && error.name) ? error.name : 'Error'
    if (typeof message !== 'string' || message.length <= 0) {
      return null
    }

    const fullStr = name + ': ' + message

    let str = fullStr
    let action = 'dismiss'
    let onClick = dismissError
    if (str.length > 37) {
      str = str.slice(0, 37) + '...'
      action = 'view & ' + action
      onClick = this.handleOpen
    }

    const actions = [
      <FlatButton
        label="dismiss"
        primary={true}
        onClick={this.handleClose}
      />,
    ]

    return [
      <Snackbar
        open={!!error}
        message={str}
        onRequestClose={() => {/* do nothing */}}
        action={action}
        onActionClick={onClick}
      />,
      <Dialog
        actions={actions}
        modal={false}
        open={dialogOpen}
        onRequestClose={this.handleClose}
      ><commit_msg>error dialog: add link to report issue<commit_after>/**
 * @file
 *
 * @brief shows errors in a small snackbar on the bottom of the UI
 *
 * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
 */

import React from 'react'
import Snackbar from 'material-ui/Snackbar'
import Dialog from 'material-ui/Dialog'
import FlatButton from 'material-ui/FlatButton'

export default class ErrorSnackbar extends React.Component {
  constructor (...args) {
    super(...args)
    this.state = { dialogOpen: false }
  }

  handleOpen = () => {
    this.setState({ dialogOpen: true })
  }

  handleClose = () => {
    const { dismissError } = this.props
    this.setState({ dialogOpen: false })
    dismissError()
  }

  render () {
    const { error, dismissError } = this.props
    const { dialogOpen } = this.state

    if (error) console.error(error)

    const message = typeof error === 'string' ? error : error.message
    const name = (error && error.name) ? error.name : 'Error'
    if (typeof message !== 'string' || message.length <= 0) {
      return null
    }

    const fullStr = name + ': ' + message

    let str = fullStr
    let action = 'dismiss'
    let onClick = dismissError
    if (str.length > 37) {
      str = str.slice(0, 37) + '...'
      action = 'view & ' + action
      onClick = this.handleOpen
    }

    const actions = [
      <FlatButton
        label="report issue"
        onClick={() => window.open('http://issues.libelektra.org/new', '_blank')}
      />,
      <FlatButton
        label="dismiss"
        primary={true}
        onClick={this.handleClose}
      />,
    ]

    return [
      <Snackbar
        open={!!error}
        message={str}
        onRequestClose={() => {/* do nothing */}}
        action={action}
        onActionClick={onClick}
      />,
      <Dialog
        actions={actions}
        modal={false}
        open={dialogOpen}
        onRequestClose={this.handleClose}
      >
{'fraction_non_alphanumeric': 0.13621708758731865, 'fraction_numerical': 0.0032240730789897904, 'mean_word_length': 2.3420107719928187, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5007757', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1115, 'n_words': 288}