<commit_before>import * as React from 'react';
import { connect, Dispatch } from 'react-redux';
import { Stack } from '@shopify/polaris';
import { RootState, Watcher, Primitive } from '../../types';
import {
  scheduleWatcher,
  cancelNextWatcherTick,
  deleteWatcher,
  EditableWatcherField,
  WatcherAction,
  editWatcher
} from '../../actions/watcher';
import WatcherHeading from './WatcherHeading';
import WatcherInfo from './WatcherInfo';
import WatcherSettings from './WatcherSettings';
import InfoCallout from './InfoCallout';
import WatcherActions from './WatcherActions';
import WatcherProgressBar from './WatcherProgressBar';
import { normalizedWatchers } from '../../selectors/watchers';

interface OwnProps {
  readonly watcherId: string;
}

interface Props {
  readonly watcher: Watcher;
  readonly watcherActive: boolean;
}

interface Handlers {
  readonly onDelete: (id: string) => void;
  readonly onSchedule: (id: string) => void;
  readonly onCancel: (id: string) => void;
  readonly onEdit: (
    id: string,
    field: EditableWatcherField,
    value: string | number
  ) => void;
}

class WatcherView extends React.PureComponent<
  OwnProps & Props & Handlers,
  never
> {
  private handleDelete = () => this.props.onDelete(this.props.watcher.groupId);

  private handleToggle = () => {
    const { watcherActive, onCancel, watcherId, onSchedule } = this.props;
    watcherActive ? onCancel(watcherId) : onSchedule(watcherId);
  };

  public render() {
    const { watcher, watcherActive } = this.props;

    return (
      <Stack vertical>
        <WatcherHeading
          title={watcher.title}
          onChange={(value: string) =>
            this.props.onEdit(this.props.watcherId, 'title', value)
          }
        />
        <WatcherInfo
          id={watcher.groupId}
          description={watcher.description}
          onChangeDescription={(value: string) =>
            this.props.onEdit(this.props.watcherId, 'description', value)
          }
        />
        <WatcherSettings
          watcher={watcher}
          onEdit={this.props.onEdit}
          onToggle={this.handleToggle}
        />
        <InfoCallout />
        <WatcherProgressBar id={watcher.groupId} />
        <WatcherActions
          watcherActive={watcherActive}
          onDelete={this.handleDelete}
          onToggle={this.handleToggle}
        />
      </Stack>
    );
  }
}

const mapState = (state: RootState, ownProps: OwnProps): Props => ({
  watcher: normalizedWatchers(state).get(ownProps.watcherId),
  watcherActive: state.watcherTimers.has(ownProps.watcherId)<commit_msg>WatcherView no longer receives the map of all watchers.<commit_after>import * as React from 'react';
import { connect, Dispatch } from 'react-redux';
import { Stack } from '@shopify/polaris';
import { RootState, Primitive } from '../../types';
import {
  scheduleWatcher,
  cancelNextWatcherTick,
  deleteWatcher,
  EditableWatcherField,
  WatcherAction,
  editWatcher
} from '../../actions/watcher';
import WatcherHeading from './WatcherHeading';
import WatcherInfo from './WatcherInfo';
import WatcherSettings from './WatcherSettings';
import InfoCallout from './InfoCallout';
import WatcherActions from './WatcherActions';
import WatcherProgressBar from './WatcherProgressBar';

interface OwnProps {
  readonly watcherId: string;
}

interface Props {
  readonly watcherActive: boolean;
}

interface Handlers {
  readonly onDelete: (id: string) => void;
  readonly onSchedule: (id: string) => void;
  readonly onCancel: (id: string) => void;
  readonly onEdit: (
    id: string,
    field: EditableWatcherField,
    value: string | number
  ) => void;
}

class WatcherView extends React.PureComponent<
  OwnProps & Props & Handlers,
  never
> {
  private handleDelete = () => this.props.onDelete(this.props.watcherId);

  private handleToggle = () => {
    const { watcherActive, onCancel, watcherId, onSchedule } = this.props;
    watcherActive ? onCancel(watcherId) : onSchedule(watcherId);
  };

  public render() {
    const { watcherId, watcherActive } = this.props;

    return (
      <Stack vertical>
        <WatcherHeading
          watcherId={watcherId}
          onChange={(value: string) =>
            this.props.onEdit(this.props.watcherId, 'title', value)
          }
        />
        <WatcherInfo
          watcherId={watcherId}
          onChangeDescription={(value: string) =>
            this.props.onEdit(this.props.watcherId, 'description', value)
          }
        />
        <WatcherSettings
          watcherId={watcherId}
          onEdit={this.props.onEdit}
          onToggle={this.handleToggle}
        />
        <InfoCallout />
        <WatcherProgressBar id={watcherId} />
        <WatcherActions
          watcherActive={watcherActive}
          onDelete={this.handleDelete}
          onToggle={this.handleToggle}
        />
      </Stack>
    );
  }
}

const mapState = (state: RootState, ownProps: OwnProps): Props => ({
  watcherActive: state.watcherTimers.has(ownProps.watcherId)
{'fraction_non_alphanumeric': 0.12086158755484643, 'fraction_numerical': 0.0, 'mean_word_length': 3.080553295362083, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 39, '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': '5435825', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1488, 'n_words': 328}