<commit_before>import React, { Component } from "react";
import gql from "graphql-tag";
import { graphql, withApollo } from "react-apollo";
import * as ViewscreenCards from "../../viewscreens";

import "./style.css";

const VIEWSCREEN_SUB = gql`
  subscription ViewscreenSub($simulatorId: ID) {
    viewscreensUpdate(simulatorId: $simulatorId) {
      id
      name
      component
      data
    }
  }
`;

export class Viewscreen extends Component {
  sub = null;
  componentWillUnmount() {
    this.sub && this.sub();
  }
  componentWillReceiveProps(nextProps) {
    if (nextProps.data && !this.sub && !nextProps.data.loading) {
      this.sub = nextProps.data.subscribeToMore({
        document: VIEWSCREEN_SUB,
        variables: {
          simulatorId: nextProps.simulator.id
        },
        updateQuery: (previousResult, { subscriptionData }) => {
          return Object.assign({}, previousResult, {
            viewscreens: subscriptionData.data.viewscreensUpdate
          });
        }
      });
    }
  }
  render() {
    if (this.props.component) {
      const ViewscreenComponent = ViewscreenCards[this.props.component];
      return <ViewscreenComponent {...this.props} />;
    }
    if (this.props.data.loading || !this.props.data.viewscreens) return null;
    const viewscreen =
      this.props.data.viewscreens &&
      this.props.data.viewscreens.find(v => v.id === this.props.clientObj.id);
    if (!viewscreen) return <div>No Viewscreen</div>;
    if (ViewscreenCards[viewscreen.component]) {
      const ViewscreenComponent = ViewscreenCards[viewscreen.component];
      return <ViewscreenComponent {...this.props} viewscreen={viewscreen} />;
    }
    if (!viewscreen)
      return <div>No Viewscreen Component for {viewscreen.component}</div>;
  }
}

const VIEWSCREEN_QUERY = gql`<commit_msg>Cleanup<commit_after>import React, { Component } from "react";
import gql from "graphql-tag";
import { graphql, withApollo } from "react-apollo";
import * as ViewscreenCards from "../../viewscreens";

import "./style.css";

const VIEWSCREEN_SUB = gql`
  subscription ViewscreenSub($simulatorId: ID) {
    viewscreensUpdate(simulatorId: $simulatorId) {
      id
      name
      component
      data
    }
  }
`;

export class Viewscreen extends Component {
  sub = null;
  componentWillUnmount() {
    this.sub && this.sub();
  }
  componentWillReceiveProps(nextProps) {
    if (nextProps.data && !this.sub && !nextProps.data.loading) {
      this.sub = nextProps.data.subscribeToMore({
        document: VIEWSCREEN_SUB,
        variables: {
          simulatorId: nextProps.simulator.id
        },
        updateQuery: (previousResult, { subscriptionData }) => {
          return Object.assign({}, previousResult, {
            viewscreens: subscriptionData.data.viewscreensUpdate
          });
        }
      });
    }
  }
  render() {
    if (this.props.component) {
      const ViewscreenComponent = ViewscreenCards[this.props.component];
      return <ViewscreenComponent {...this.props} />;
    }
    const { data: { loading, viewscreens } } = this.props;
    if (loading || !viewscreens) return null;
    const viewscreen = viewscreens.find(v => v.id === this.props.clientObj.id);
    if (!viewscreen) return <div>No Viewscreen</div>;
    if (ViewscreenCards[viewscreen.component]) {
      const ViewscreenComponent = ViewscreenCards[viewscreen.component];
      return <ViewscreenComponent {...this.props} viewscreen={viewscreen} />;
    }
    if (!viewscreen)
      return <div>No Viewscreen Component for {viewscreen.component}</div>;
  }
}

const VIEWSCREEN_QUERY = gql`
{'fraction_non_alphanumeric': 0.12853970016657412, 'fraction_numerical': 0.0, 'mean_word_length': 3.030201342281879, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '4029162', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1098, 'n_words': 219}