<commit_before>import React from 'react';
import {Label, OverlayTrigger, Popover} from 'react-bootstrap';

export default class ElementCollectionLabels extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      element: props.element
    }
  }

  render() {
    return (
      <div>
        {this.collectionLabels(this.state.element)}
      </div>
    );
  }

  labelStyle(label) {
    if(label.is_shared == false) {
      return "info";
    } else {
      return "warning";
    }
  }

  format_labels(labels) {
    return labels.map((label, index) => {
      return (
        <span className="collection-label" key={index}>
          <Label bsStyle={this.labelStyle(label)}>{label.name}</Label>
          &nbsp;
        </span>
      )
    });
  }

  collectionLabels(element) {
    if(element.collection_labels) {
      let shared_labels = [];
      let labels = [];
      element.collection_labels.map((label, index) => {
        if (label.is_shared) {
          shared_labels.push(label)
        } else {
          labels.push(label)
        }
      });

      let shared_label_popover = <Popover title="Shared Collections">{this.format_labels(shared_labels)}</Popover>

      let label_popover = <Popover title="Collections">{this.format_labels(labels)}</Popover>

      let shared_label = shared_labels.length > 0 ?
        <OverlayTrigger trigger="hover" placement="top" overlay={shared_label_popover}>
          <span className="collection-label" key={element.id+"_shared_labels_"+shared_labels.length}>
            <Label bsStyle="warning">In {shared_labels.length} Shared Collections</Label>
            &nbsp;
          </span>
        </OverlayTrigger> : undefined

      let collection_label = labels.length > 0 ?
        <OverlayTrigger trigger="hover" placement="top" overlay={label_popover}>
          <span className="collection-label" key={element.id+"_labels_"+shared_labels.length}>
            <Label bsStyle="info">In {labels.length} Collections</Label>
            &nbsp;
          </span> 
        </OverlayTrigger>: undefined

      return (
        <div>
          {collection_label}
          {shared_label}
        </div>
      )
    }
  }
}
<commit_msg>Refactors compact collection label view<commit_after>import React from 'react';
import {Label, OverlayTrigger, Popover} from 'react-bootstrap';

export default class ElementCollectionLabels extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      element: props.element
    }
  }

  render() {
    return (
      this.collectionLabels(this.state.element)
    );
  }

  labelStyle(label) {
    return label.is_shared ? "warning" : "info";
  }

  format_labels(labels) {
    return labels.map((label, index) => {
      return (
        <span className="collection-label" key={index}>
          <Label bsStyle={this.labelStyle(label)}>{label.name}</Label>
          &nbsp;
        </span>
      )
    });
  }

  labelWithPopover(title, labels) {
    let {element} = this.state;
    let label_popover = <Popover title={title}>{this.format_labels(labels)}</Popover>
    return (
      labels.length > 0 ?
        <OverlayTrigger trigger="click" rootClose placement="left" overlay={label_popover}>
          <span className="collection-label" key={element.type+element.id+title+labels.length}>
            <Label bsStyle={this.labelStyle(labels[0])}>In {labels.length} {title}</Label>
            &nbsp;
          </span> 
        </OverlayTrigger> : undefined
    );
  }

  collectionLabels(element) {
    if(element.collection_labels) {

      let shared_labels = [];
      let labels = [];
      element.collection_labels.map((label, index) => {
        if (label.is_shared) {
          shared_labels.push(label)
        } else {
          labels.push(label)
        }
      });

      return (
        <div>
          {this.labelWithPopover("Collections", labels)}
          {this.labelWithPopover("Shared Collections", shared_labels)}
        </div>
      )
    }
  }
}

{'fraction_non_alphanumeric': 0.13461059965165464, 'fraction_numerical': 0.0009952724558347848, 'mean_word_length': 2.526315789473684, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 48, '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': '415376', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1165, 'n_words': 206}