<commit_before>import React from 'react'
import PropTypes from 'prop-types'
import {
    DeleteIconButton,
    SimpleList
} from 'ui/admin'
import Util from 'client/util'
import {withApollo, Query} from 'react-apollo'
import gql from 'graphql-tag'
import ApolloClient from 'apollo-client'
import {COLLECTIONS_QUERY} from '../../constants'
const gqlCollectionsQuery = gql(COLLECTIONS_QUERY)


class ManageCollectionClones extends React.PureComponent {
    state = {
    }

    /*static getDerivedStateFromProps(nextProps, prevState) {
        if (!prevState.loaded) {
            return Object.assign({}, prevState, {loading: true})
        }
        return prevState
    }*/

    handleDeleteClick(item){
        console.log(item)
    }

    render() {

        const {type} = this.props

        return <Query query={gqlCollectionsQuery}
                   fetchPolicy="cache-first"
                   variables={{filter: '^' + type + '_.*'}}>
                {({loading, error, data}) => {
                    if (loading) return 'Loading...'
                    if (error) return `Error! ${error.message}`

                    if (!data.collections.results) return null

                    const listItems = data.collections.results.reduce((a, item) => {
                        const value = item.name.substring(item.name.indexOf('_') + 1), parts = value.split('_')

                        a.push({
                            selected: false,
                            primary:  (parts.length > 1 ? parts[1] : 'no name'),
                            onClick: (e) => {
                                console.log(e)
                                // this.goTo(post._id, posts.page, posts.limit, this.filter)
                            },
                            secondary: Util.formattedDatetime(parts[0]),
                            actions: <DeleteIconButton onClick={this.handleDeleteClick.bind(this, item)}/>,
                        })
                        return a
                    }, [])

                    return <SimpleList items={listItems}
                                       count={listItems.length}/>
                }}
            </Query><commit_msg>Small improvments<commit_after>import React from 'react'
import PropTypes from 'prop-types'
import {
    DeleteIconButton,
    SimpleList,
    SimpleDialog
} from 'ui/admin'
import Util from 'client/util'
import {withApollo, Query} from 'react-apollo'
import gql from 'graphql-tag'
import ApolloClient from 'apollo-client'
import {COLLECTIONS_QUERY} from '../../constants'
const gqlCollectionsQuery = gql(COLLECTIONS_QUERY)


class ManageCollectionClones extends React.PureComponent {
    state = {
        showConfirmDeletion: false,
        dataToDelete: null
    }

    /*static getDerivedStateFromProps(nextProps, prevState) {
     if (!prevState.loaded) {
     return Object.assign({}, prevState, {loading: true})
     }
     return prevState
     }*/

    handleDeleteClick(item) {
        this.setState({showConfirmDeletion: true, dataToDelete: item})
        console.log(item)
    }

    render() {

        const {type} = this.props
        const {showConfirmDeletion, dataToDelete} = this.state

        return [<Query key="query" query={gqlCollectionsQuery}
                       fetchPolicy="cache-first"
                       variables={{filter: '^' + type + '_.*'}}>
            {({loading, error, data}) => {
                if (loading) return 'Loading...'
                if (error) return `Error! ${error.message}`

                if (!data.collections.results) return null

                const listItems = data.collections.results.reduce((a, item) => {
                    const value = item.name.substring(item.name.indexOf('_') + 1), parts = value.split('_')

                    a.push({
                        selected: false,
                        primary: (parts.length > 1 ? parts[1] : 'no name'),
                        onClick: (e) => {
                            console.log(e)
                            // this.goTo(post._id, posts.page, posts.limit, this.filter)
                        },
                        secondary: Util.formattedDatetime(parts[0]),
                        actions: <DeleteIconButton onClick={this.handleDeleteClick.bind(this, item)}/>,
                    })
                    return a
                }, [])

                return <SimpleList items={listItems}
                                   count={listItems.length}/>
            }}
        </Query>,

            dataToDelete &&
            <SimpleDialog key="deleteDialog" open={showConfirmDeletion} onClose={this.handleConfirmDeletion}
                          actions={[{key: 'yes', label: 'Yes'}, {key: 'no', label: 'No', type: 'primary'}]}
                          title="Confirm deletion">
                Are you sure you want to delete this item?
            </SimpleDialog>]
{'fraction_non_alphanumeric': 0.11781492050550346, 'fraction_numerical': 0.0016306563391765185, 'mean_word_length': 1.628280664167113, 'pattern_counts': {'":': 0, '<': 13, '<?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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3625038', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1243, 'n_words': 283}