<commit_before>import * as React from 'react';
import {
  RootState,
  HitDatabaseEntry,
  WorkerHitDatabaseEntry
} from '../../../types';
import { connect } from 'react-redux';
import { ResourceList } from '@shopify/polaris';
import { generateReviewLink } from '../../../utils/turkopticon';
import { generateHitStatusBadge } from '../../../utils/badges';
import { truncate, formatAsCurrency } from '../../../utils/formatting';
import HitDbEntryCollapsible from './HitDbEntryCollapsible';
import { generateContactLink } from '../../../utils/urls';

export interface OwnProps {
  readonly id: string;
}

export interface Props {
  readonly hit: HitDatabaseEntry;
}

interface State {
  readonly expanded: boolean;
}

class CompletedHitItem extends React.PureComponent<Props & OwnProps, State> {
  state: State = { expanded: false };

  componentWillReceiveProps(nextProps: Props) {
    if (nextProps.hit.id !== this.props.hit.id) {
      this.setState((): Partial<State> => ({
        expanded: false
      }));
    }
  }

  private static displayEarnings = (reward: number, bonus: number) =>
    bonus > 0
      ? `${formatAsCurrency(reward)} + ${formatAsCurrency(bonus)}`
      : `${formatAsCurrency(reward)}`;

  private generateActions = (assignmentId?: string) => [
    {
      content: 'Contact',
      url: assignmentId
        ? generateContactLink(this.props.hit as WorkerHitDatabaseEntry)
        : undefined,
      external: true,
      disabled: this.props.hit.assignmentId ? false : true
    },
    {
      content: 'Review',
      url: generateReviewLink(this.props.hit),
      external: true
    }
  ];

  private handleExpand = () => {
    this.setState((prevState: State): Partial<State> => ({
      expanded: !prevState.expanded
    }));
  };

  public render() {
    const { hit: { title, reward, bonus, status, assignmentId } } = this.props;
    return (
      <React.Fragment>
        <div onClick={this.handleExpand}>
          <ResourceList.Item
            persistActions
            attributeOne={CompletedHitItem.displayEarnings(reward, bonus)}
            attributeTwo={truncate(title, 100)}
            badges={[generateHitStatusBadge(status)]}
            actions={this.generateActions(assignmentId)}
          />
        </div>
        <HitDbEntryCollapsible
          open={this.state.expanded}
          hit={this.props.hit}
        />
      </React.Fragment>
    );
  }
}

const mapState = (state: RootState, ownProps: OwnProps): Props => ({
  hit: state.hitDatabase.get(ownProps.id)
});

export default connect(mapState)(CompletedHitItem);<commit_msg>CompletedHitItem no longer has persisted actions.<commit_after>import * as React from 'react';
import {
  RootState,
  HitDatabaseEntry,
  WorkerHitDatabaseEntry
} from '../../../types';
import { connect } from 'react-redux';
import { ResourceList } from '@shopify/polaris';
import { generateReviewLink } from '../../../utils/turkopticon';
import { generateHitStatusBadge } from '../../../utils/badges';
import { truncate, formatAsCurrency } from '../../../utils/formatting';
import HitDbEntryCollapsible from './HitDbEntryCollapsible';
import { generateContactLink } from '../../../utils/urls';

export interface OwnProps {
  readonly id: string;
}

export interface Props {
  readonly hit: HitDatabaseEntry;
}

interface State {
  readonly expanded: boolean;
}

class CompletedHitItem extends React.PureComponent<Props & OwnProps, State> {
  state: State = { expanded: false };

  componentWillReceiveProps(nextProps: Props) {
    if (nextProps.hit.id !== this.props.hit.id) {
      this.setState((): Partial<State> => ({
        expanded: false
      }));
    }
  }

  private static displayEarnings = (reward: number, bonus: number) =>
    bonus > 0
      ? `${formatAsCurrency(reward)} + ${formatAsCurrency(bonus)}`
      : `${formatAsCurrency(reward)}`;

  private generateActions = (assignmentId?: string) => [
    {
      content: 'Contact',
      url: assignmentId
        ? generateContactLink(this.props.hit as WorkerHitDatabaseEntry)
        : undefined,
      external: true,
      disabled: this.props.hit.assignmentId ? false : true
    },
    {
      content: 'Review',
      url: generateReviewLink(this.props.hit),
      external: true
    }
  ];

  private handleExpand = () => {
    this.setState((prevState: State): Partial<State> => ({
      expanded: !prevState.expanded
    }));
  };

  public render() {
    const {
      hit: { title, requester, reward, bonus, status, assignmentId }
    } = this.props;
    return (
      <React.Fragment>
        <div onClick={this.handleExpand}>
          <ResourceList.Item
            attributeOne={CompletedHitItem.displayEarnings(reward, bonus)}
            attributeTwo={truncate(title, 100)}
            attributeThree={truncate(requester.name, 30)}
            badges={[generateHitStatusBadge(status)]}
            actions={this.generateActions(assignmentId)}
          />
        </div>
        <HitDbEntryCollapsible
          open={this.state.expanded}
          hit={this.props.hit}
        />
      </React.Fragment>
    );
  }
}

const mapState = (state: RootState, ownProps: OwnProps): Props => ({
  hit: state.hitDatabase.get(ownProps.id)
});

export default connect(mapState)(CompletedHitItem);
{'fraction_non_alphanumeric': 0.1417427701674277, 'fraction_numerical': 0.001902587519025875, 'mean_word_length': 2.964555052790347, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, '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': '5829912', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1548, 'n_words': 322}