<commit_before>import * as React from "react";
import { ResultClickedFn } from "../context/pipeline/context";
import { Link } from "./styled";

const TOKEN_URL = "https://www.sajari.com/token/";

export interface ITokenLinkProps {
  token: string;
  url: string;
  resultClicked: ResultClickedFn;
  text?: string;
  children?: React.ReactNode;

  styles?: React.CSSProperties;
}

export interface ITokenLinkState {
  clicked: boolean;
}

export class TokenLink extends React.PureComponent<
  ITokenLinkProps,
  ITokenLinkState
> {
  public state = { clicked: false };

  public render() {
    const { token, url, text, styles = {}, children } = this.props;

    let decodedText;
    try {
      decodedText = decodeURI(url);
    } catch (e) {
      // encoded url was malformed, fall back to displaying the encoded text
      decodedText = url;
    }

    // if the text prop is provided, use that instead of the decoded URI
    decodedText = text ? text : decodedText;

    return (
      <Link
        href={token ? TOKEN_URL + token : url}
        onMouseDown={this.click}
        styles={styles}
      >
        {decodedText}
        {children}
      </Link>
    );
  }

  private click = () =>
    this.setState(
      state => ({ ...state, clicked: true }),
      () => {
        const { url, resultClicked } = this.props;
        resultClicked(url);
      }
    );
}<commit_msg>components: TokenLink render children<commit_after>import * as React from "react";
import { ResultClickedFn } from "../context/pipeline/context";
import { Link } from "./styled";

const TOKEN_URL = "https://www.sajari.com/token/";

export interface ITokenLinkProps {
  token: string;
  url: string;
  resultClicked: ResultClickedFn;
  text?: string;
  children?: React.ReactNode;

  styles?: React.CSSProperties;
}

export interface ITokenLinkState {
  clicked: boolean;
}

export class TokenLink extends React.PureComponent<
  ITokenLinkProps,
  ITokenLinkState
> {
  public state = { clicked: false };

  public render() {
    const { token, url, text, styles = {}, children } = this.props;

    let decodedText;
    try {
      decodedText = decodeURI(url);
    } catch (e) {
      // encoded url was malformed, fall back to displaying the encoded text
      decodedText = url;
    }

    // if the text prop is provided, use that instead of the decoded URI
    decodedText = text ? text : decodedText;

    let renderChildren = children;
    if (renderChildren === undefined) {
      renderChildren = decodedText;
    }

    return (
      <Link
        href={token ? TOKEN_URL + token : url}
        onMouseDown={this.click}
        styles={styles}
      >
        {renderChildren}
      </Link>
    );
  }

  private click = () =>
    this.setState(
      state => ({ ...state, clicked: true }),
      () => {
        const { url, resultClicked } = this.props;
        resultClicked(url);
      }
    );
}
{'fraction_non_alphanumeric': 0.12016574585635359, 'fraction_numerical': 0.0, 'mean_word_length': 2.616729088639201, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2870012', 'n_tokens_mistral': 887, 'n_tokens_neox': 869, 'n_words': 242}