<commit_before>React = require 'react'
handleInputChange = require '../../lib/handle-input-change'
PromiseRenderer = require '../../components/promise-renderer'
apiClient = require '../../api/client'
ChangeListener = require '../../components/change-listener'
Papa = require 'papaparse'
{Navigation} = require 'react-router'
alert = require '../../lib/alert'
SubjectViewer = require '../../components/subject-viewer'
SubjectUploader = require '../../partials/subject-uploader'
BoundResourceMixin = require '../../lib/bound-resource-mixin'
UploadDropTarget = require '../../components/upload-drop-target'
ManifestView = require '../../components/manifest-view'

NOOP = Function.prototype

VALID_SUBJECT_EXTENSIONS = ['.jpg', '.png', '.gif', '.svg']
INVALID_FILENAME_CHARS = ['/', '\\', ':']

SubjectSetListingRow = React.createClass
  displayName: 'SubjectSetListingRow'

  getDefaultProps: ->
    subject: {}
    onPreview: Function.prototype # No-op
    onRemove: Function.prototype

  getInitialState: ->
    beingDeleted: false

  render: ->
    <tr key={@props.subject.id}>
      <td>
        <small className="form-help">{@props.subject.id}</small>
      </td>
      <td>
        <button type="button" disabled={@state.beingDeleted} onClick={@props.onPreview.bind null, @props.subject}><i className="fa fa-eye fa-fw"></i></button>
        <button type="button" disabled={@state.beingDeleted} onClick={@handleRemove}><i className="fa fa-trash-o fa-fw"></i></button>
      </td>
    </tr>

  handleRemove: ->
    @setState beingDeleted: true
    @props.onRemove @props.subject

SubjectSetListingTable = React.createClass
  displayName: 'SubjectSetListing'

  getDefaultProps: ->
    subjects: []
    onPreview: Function.prototype
    onRemove: Function.prototype

  render: ->
    <table>
      <tbody>
        {for subject in @props.subjects
          <SubjectSetListingRow key={subject.id} subject={subject} onPreview={@props.onPreview} onRemove={@props.onRemove} />}
      </tbody>
    </table>

SubjectSetListing = React.createClass
  displayName: 'SubjectSetListing'

  getDefaultProps: ->
    subjectSet: {}

  getInitialState: ->
    page: 1
    pageCount: NaN

  render: ->
    gettingSetMemberSubjects = apiClient.type('set_member_subjects').get
      subject_set_id: @props.subjectSet.id
      include: 'subject'
      page: @state.page

    gettingSetMemberSubjects.then ([setMemberSubject]) =>
      newPageCount = setMemberSubject?.getMeta().page_count
      unless newPageCount is @state.pageCount
        @setState pageCount: newPageCount

    gettingSubjects = gettingSetMemberSubjects.get 'subject'

    <div>
      <PromiseRenderer promise={gettingSubjects} then={(subjects) =>
        <SubjectSetListingTable subjects={subjects} onPreview={@previewSubject} onRemove={@removeSubject} />
      } />
      <nav className="pagination">
        Page <select value={@state.page} disabled={@state.pageCount < 2 or isNaN @state.pageCount} onChange={(e) => @setState page: e.target.value}>
          {if isNaN @state.pageCount
            <option>?</option><commit_msg>Don't use `include` with set_member_subject request<commit_after>React = require 'react'
handleInputChange = require '../../lib/handle-input-change'
PromiseRenderer = require '../../components/promise-renderer'
apiClient = require '../../api/client'
ChangeListener = require '../../components/change-listener'
Papa = require 'papaparse'
{Navigation} = require 'react-router'
alert = require '../../lib/alert'
SubjectViewer = require '../../components/subject-viewer'
SubjectUploader = require '../../partials/subject-uploader'
BoundResourceMixin = require '../../lib/bound-resource-mixin'
UploadDropTarget = require '../../components/upload-drop-target'
ManifestView = require '../../components/manifest-view'

NOOP = Function.prototype

VALID_SUBJECT_EXTENSIONS = ['.jpg', '.png', '.gif', '.svg']
INVALID_FILENAME_CHARS = ['/', '\\', ':']

SubjectSetListingRow = React.createClass
  displayName: 'SubjectSetListingRow'

  getDefaultProps: ->
    subject: {}
    onPreview: Function.prototype # No-op
    onRemove: Function.prototype

  getInitialState: ->
    beingDeleted: false

  render: ->
    <tr key={@props.subject.id}>
      <td>
        <small className="form-help">{@props.subject.id}</small>
      </td>
      <td>
        <button type="button" disabled={@state.beingDeleted} onClick={@props.onPreview.bind null, @props.subject}><i className="fa fa-eye fa-fw"></i></button>
        <button type="button" disabled={@state.beingDeleted} onClick={@handleRemove}><i className="fa fa-trash-o fa-fw"></i></button>
      </td>
    </tr>

  handleRemove: ->
    @setState beingDeleted: true
    @props.onRemove @props.subject

SubjectSetListingTable = React.createClass
  displayName: 'SubjectSetListing'

  getDefaultProps: ->
    subjects: []
    onPreview: Function.prototype
    onRemove: Function.prototype

  render: ->
    <table>
      <tbody>
        {for subject in @props.subjects
          <SubjectSetListingRow key={subject.id} subject={subject} onPreview={@props.onPreview} onRemove={@props.onRemove} />}
      </tbody>
    </table>

SubjectSetListing = React.createClass
  displayName: 'SubjectSetListing'

  getDefaultProps: ->
    subjectSet: {}

  getInitialState: ->
    page: 1
    pageCount: NaN

  render: ->
    gettingSetMemberSubjects = apiClient.type('set_member_subjects').get
      subject_set_id: @props.subjectSet.id
      page: @state.page

    gettingSetMemberSubjects.then ([setMemberSubject]) =>
      newPageCount = setMemberSubject?.getMeta().page_count
      unless newPageCount is @state.pageCount
        @setState pageCount: newPageCount

    gettingSubjects = gettingSetMemberSubjects.get 'subject'

    <div>
      <PromiseRenderer promise={gettingSubjects} then={(subjects) =>
        <SubjectSetListingTable subjects={subjects} onPreview={@previewSubject} onRemove={@removeSubject} />
      } />
      <nav className="pagination">
        Page <select value={@state.page} disabled={@state.pageCount < 2 or isNaN @state.pageCount} onChange={(e) => @setState page: e.target.value}>
          {if isNaN @state.pageCount
            <option>?</option>
{'fraction_non_alphanumeric': 0.1512060870972964, 'fraction_numerical': 0.0006475635421725757, 'mean_word_length': 3.5967261904761907, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 83, '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': '3687774', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1840, 'n_words': 356}