<commit_before>import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import { sortBy } from 'lodash';
import getDecorators from './decorators/get-decorators';

export default (WrappedComponent) => {
  @graphql(
    gql`
      query schema {
        schema: __schema {
          types {
            name
            description
            interfaces {
              name
            }
            fields {
              name
              type {
                kind
                name
              }
            }
          }
        }
      }
    `,
  )
  class WithCollectionsComponent extends Component {
    list() {
      const { data = {} } = this.props;
      const { schema } = data;

      return schema && schema.types
        ? schema.types.filter(
          x =>
            (x.interfaces || []).filter(
              y => y.name === 'CollectionType' || y.name === 'CollectionInterface',
            ).length,
        )
        : [];
    }

    group() {
      const { data = {} } = this.props;
      const { schema } = data;
      const collections = this.list();

      if (!schema || !collections.length) {
        return {};
      }

      // Von Collections Attribute (icon, group, order) extrahieren und Collections gruppieren
      const groups = {};
      collections.map(({ name, description }, i) => {
        const attributes = {};
        description.split('\n').forEach((x) => {
          const y = x.split(':');

          if (y.length === 2) {
            attributes[y[0]] = y[1];
          }
        });

        // Attribute verfügbar machen
        collections[i] = {
          ...collections[i],
          ...attributes,
        };

        // Gruppieren
        if (!groups[attributes.group]) {
          groups[attributes.group] = [];
        }
        groups[attributes.group].push(collections[i]);
      });

      // Collections innerhalb Gruppe sortieren
      Object.keys(groups).forEach((key) => {
        groups[key] = sortBy(groups[key], ['order', 'name']);
      });

      // Undefined-Gruppe auflösen
      if (groups.undefined) {
        groups.undefined.forEach((collection) => {
          if (!groups[collection.name]) {
            groups[collection.name] = [];
          }

          groups[collection.name].push(collection);
        });

        delete groups.undefined;
      }

      return groups;
    }

    render() {
      const { data, ...rest } = this.props;
      const list = this.list();
      const group = this.group();

      return (
        <WrappedComponent
          {...rest}
          collectionList={list.map(x => ({ ...x, decorators: getDecorators(x.description) }))}
          collectionTree={group}
        />
      );
    }
  }

  return WithCollectionsComponent;
};<commit_msg>add @group and @icon to collections<commit_after>import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import { sortBy, get } from 'lodash';
import getDecorators from './decorators/get-decorators';

export default WrappedComponent => {
  @graphql(
    gql`
      query schema {
        schema: __schema {
          types {
            name
            description
            interfaces {
              name
            }
            fields {
              name
              type {
                kind
                name
              }
            }
          }
        }
      }
    `,
  )
  class WithCollectionsComponent extends Component {
    list = () => {
      const { data = {} } = this.props;
      const { schema } = data;

      return schema && schema.types
        ? schema.types
            .filter(
              x =>
                (x.interfaces || []).filter(
                  y =>
                    y.name === 'CollectionType' ||
                    y.name === 'CollectionInterface',
                ).length,
            )
            .map(x => ({ ...x, decorators: getDecorators(x.description) }))
        : [];
    };

    group = (list = []) => {
      const groups = {};
      list.forEach(collection => {
        const group = get(collection, 'decorators.group.value');

        if (!groups[group]) {
          groups[group] = [];
        }
        groups[group].push(collection);
      });

      // Collections innerhalb Gruppe sortieren
      Object.keys(groups).forEach(key => {
        groups[key] = sortBy(groups[key], ['order', 'name']);
      });

      // Undefined-Gruppe auflösen
      if (groups.undefined) {
        groups.undefined.forEach(collection => {
          const name = get(
            collection,
            'decorators.label.value',
            collection.name,
          );

          if (!groups[name]) {
            groups[name] = [];
          }

          groups[name].push(collection);
        });

        delete groups.undefined;
      }

      // Gruppen sortieren
      const orderedGroups = {};
      Object.keys(groups)
        .sort()
        .forEach(key => {
          orderedGroups[key] = groups[key];
        });

      return orderedGroups;
    };

    render() {
      const { data, ...rest } = this.props;
      const list = this.list();
      const group = this.group(list);

      return (
        <WrappedComponent
          {...rest}
          collectionList={list}
          collectionTree={group}
        />
      );
    }
  }

  return WithCollectionsComponent;
};
{'fraction_non_alphanumeric': 0.13524967753823475, 'fraction_numerical': 0.000552791597567717, 'mean_word_length': 1.4650317892824705, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '7236179', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1450, 'n_words': 302}