<commit_before>import React from 'react';
import PropTypes from 'prop-types';

import { VegaChart, getVegaTheme } from 'widget-editor';

// /widget_data.json?widget_id=
class WidgetBlock extends React.Component {
  constructor(props) {
    super(props);
    this.widgetConfig = null;
    this.state = {
      loading: true,
      widget: null
    };
  }

  componentWillMount() {
    const { item } = this.props;
    this.getChart(item.content.widgetId);
  }

  shouldComponentUpdate(nextProps, nextState) {
    // This fixes a bug where the widgets would reload when hovering them
    return this.state !== nextState
      || this.props.item.content.widgetId !== nextProps.item.content.widgetId;
  }

  getChart(widgetId) {
    fetch(`${window.location.origin}/widget_data.json?widget_id=${widgetId}`).then((res) => {
      return res.json();
    }).then((w) => {
      const widget = w;
      if (widget.visualization.width !== undefined) delete widget.visualization.width;
      if (widget.visualization.height !== undefined) delete widget.visualization.height;

      this.setState({
        loading: false,
        widget
      });
    });
  }

  render() {
    if (this.state.loading) { return null; }
    return (
      <VegaChart
        data={this.state.widget.visualization}
        theme={getVegaTheme()}
        reloadOnResize
      />
    );
  }
}

WidgetBlock.propTypes = {
  item: PropTypes.object.isRequired
};

export default WidgetBlock;
<commit_msg>Fix a bug where widgets wouldn't be rendered w/ their themes in wysiwyg<commit_after>import React from 'react';
import PropTypes from 'prop-types';

import { VegaChart } from 'widget-editor';

// /widget_data.json?widget_id=
class WidgetBlock extends React.Component {
  constructor(props) {
    super(props);
    this.widgetConfig = null;
    this.state = {
      loading: true,
      widget: null
    };
  }

  componentWillMount() {
    const { item } = this.props;
    this.getChart(item.content.widgetId);
  }

  shouldComponentUpdate(nextProps, nextState) {
    // This fixes a bug where the widgets would reload when hovering them
    return this.state !== nextState
      || this.props.item.content.widgetId !== nextProps.item.content.widgetId;
  }

  getChart(widgetId) {
    fetch(`${window.location.origin}/widget_data.json?widget_id=${widgetId}`).then((res) => {
      return res.json();
    }).then((w) => {
      const widget = w;
      if (widget.visualization.width !== undefined) delete widget.visualization.width;
      if (widget.visualization.height !== undefined) delete widget.visualization.height;

      this.setState({
        loading: false,
        widget
      });
    });
  }

  render() {
    if (this.state.loading) { return null; }
    return (
      <VegaChart
        data={this.state.widget.visualization}
        reloadOnResize
      />
    );
  }
}

WidgetBlock.propTypes = {
  item: PropTypes.object.isRequired
};

export default WidgetBlock;

{'fraction_non_alphanumeric': 0.12953543574092913, 'fraction_numerical': 0.0, 'mean_word_length': 2.933333333333333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '7550772', 'n_tokens_mistral': 908, 'n_tokens_neox': 893, 'n_words': 188}