<commit_before>import React from 'react'
import Nav from '../Nav/component.js'
import {Box, cube, Table, TableData, TableRow, TableHead, Bullet} from '../theme.js'
import { connect } from 'react-redux';
import styled from 'styled-components';
import { Link } from 'react-router';

const LinkBullet = ({link})=>{
  let required = link.required == true ? 'Yes':'No'
  return(
    <TableRow>

    <TableData>
      <Link to={'/dd/' + link.target_type }> {link.name} </Link>
    </TableData>

    <TableData>
      {required}
    </TableData>

    <TableData>
      {link.label}
    </TableData>

    </TableRow>
 )
}


const LinkTable = ({links, node}) =>{
  let fields = ['Name', 'Required', 'Label']
  return(
  <Table>
    <TableHead>
      <TableRow>
      {fields.map((field, i) =>
              <TableData first_cr key={i}>{field}</TableData>)}
      </TableRow>
    </TableHead>

    <tbody>
      {links.map( (link, i) => <LinkBullet key={i} link={link} /> )}
    </tbody>
  </Table>
 )
}

const getType = ( schema ) => {
  if ('type' in schema) {
    if (typeof schema.type == 'string'){
      return schema.type;
    }
    else {
      return schema.type.join(', ');
    }
  }
  else if ('enum' in schema) {
    return schema.enum.join(', ');
  }
}

const NodeTable = ({node}) => {
  return(
  <Table>
    <TableRow>
      <TableData first_cr> Title </TableData>
      <TableData right>{ node['title'] }</TableData>
    </TableRow>

    <TableRow>
      <TableData first_cr> Category </TableData>
      <TableData right>{ node['category']}</TableData>
    </TableRow>

    <TableRow>
      <TableData first_cr> Description </TableData>
      <TableData right>{ node['description']}</TableData>
    </TableRow>

    <TableRow>
      <TableData first_cr> Unique Keys </TableData>
      <TableData right>{
        <ul>
        {node['uniqueKeys'].map( (key, i) => <Bullet key={i}>{key.join(', ')}</Bullet> )} 
        </ul>
      }</TableData>
    </TableRow>

    <tbody></tbody>
  </Table>
  )
}
const Required = styled(TableData)`
`;
const Col1 = styled(TableData)`
  width: 35%;
`;
const Col2 = styled(TableData)`
  width: 15%;
`;
const Col3 = styled(TableData)`
  width: 10%;
`;
const Col4 = styled(TableData)`
  width: 40%;
`;


const PropertyBullet = ({property_name, property, required}) =>{
  let description = 'No Description';
  if ('description' in property){
    description = property.description;
  }
  if ('term' in property){
    description = property.term.description;
  }

  let type = getType(property);
  if (type == undefined){
    if ('oneOf' in property){
      type = property['oneOf'].map((item, i) => getType(item)).join(', ');
    }
  }

  return(
    <TableRow>
      <Col1><div> { property_name }</div> </Col1>
      <Col2> <ul>{ (type.indexOf(',') == -1) ? type : type.split(', ').map((item) => <Bullet>{item}</Bullet>)} </ul></Col2>
      <Col3> { required ? "Yes" : "No" } </Col3>
      <Col4> { description } </Col4>
    </TableRow>
  )
}

const PropertiesTable = ({node, required, links}) =>{
  let properties_fields = ['Property','Type','Required', 'Description']
  let linknames = links.map((link, i) => link['name']);
  let properties = Object.keys(node['properties'])
  return(
    <Table>
      <TableHead>
        <TableRow>
          <Col1 first_cr>Property</Col1>
          <Col2 first_cr>Type</Col2>
          <Col3 first_cr>Required</Col3>
          <Col4 first_cr>Description</Col4>
        </TableRow>
      </TableHead>

      <tbody>
        {
        properties.map( (property, i) =>
          (linknames.indexOf(property) == -1) &&
          <PropertyBullet key={i} required={property in required} property_name={property} property={node['properties'][property]}/>
         )
        }

      </tbody>
    </Table>

  )
}

const DataDictionaryNodeType = ({params,submission}) =>{
  let node = params.node
  let dictionary = submission.dictionary
  let links = [];
  let required = ('required' in dictionary[node]) ? dictionary[node].required : [];
  for (var link of submission.dictionary[node].links){<commit_msg>fix(required): fix dictionary required property<commit_after>import React from 'react'
import Nav from '../Nav/component.js'
import {Box, cube, Table, TableData, TableRow, TableHead, Bullet} from '../theme.js'
import { connect } from 'react-redux';
import styled from 'styled-components';
import { Link } from 'react-router';

const LinkBullet = ({link})=>{
  let required = link.required == true ? 'Yes':'No'
  return(
    <TableRow>

    <TableData>
      <Link to={'/dd/' + link.target_type }> {link.name} </Link>
    </TableData>

    <TableData>
      {required}
    </TableData>

    <TableData>
      {link.label}
    </TableData>

    </TableRow>
 )
}


const LinkTable = ({links, node}) =>{
  let fields = ['Name', 'Required', 'Label']
  return(
  <Table>
    <TableHead>
      <TableRow>
      {fields.map((field, i) =>
              <TableData first_cr key={i}>{field}</TableData>)}
      </TableRow>
    </TableHead>

    <tbody>
      {links.map( (link, i) => <LinkBullet key={i} link={link} /> )}
    </tbody>
  </Table>
 )
}

const getType = ( schema ) => {
  if ('type' in schema) {
    if (typeof schema.type == 'string'){
      return schema.type;
    }
    else {
      return schema.type.join(', ');
    }
  }
  else if ('enum' in schema) {
    return schema.enum.join(', ');
  }
}

const NodeTable = ({node}) => {
  return(
  <Table>
    <TableRow>
      <TableData first_cr> Title </TableData>
      <TableData right>{ node['title'] }</TableData>
    </TableRow>

    <TableRow>
      <TableData first_cr> Category </TableData>
      <TableData right>{ node['category']}</TableData>
    </TableRow>

    <TableRow>
      <TableData first_cr> Description </TableData>
      <TableData right>{ node['description']}</TableData>
    </TableRow>

    <TableRow>
      <TableData first_cr> Unique Keys </TableData>
      <TableData right>{
        <ul>
        {node['uniqueKeys'].map( (key, i) => <Bullet key={i}>{key.join(', ')}</Bullet> )} 
        </ul>
      }</TableData>
    </TableRow>

    <tbody></tbody>
  </Table>
  )
}
const Required = styled(TableData)`
`;
const Col1 = styled(TableData)`
  width: 35%;
`;
const Col2 = styled(TableData)`
  width: 15%;
`;
const Col3 = styled(TableData)`
  width: 10%;
`;
const Col4 = styled(TableData)`
  width: 40%;
`;


const PropertyBullet = ({property_name, property, required}) =>{
  let description = 'No Description';
  if ('description' in property){
    description = property.description;
  }
  if ('term' in property){
    description = property.term.description;
  }

  let type = getType(property);
  if (type == undefined){
    if ('oneOf' in property){
      type = property['oneOf'].map((item, i) => getType(item)).join(', ');
    }
  }

  return(
    <TableRow>
      <Col1><div> { property_name }</div> </Col1>
      <Col2> <ul>{ (type.indexOf(',') == -1) ? type : type.split(', ').map((item) => <Bullet>{item}</Bullet>)} </ul></Col2>
      <Col3> { required ? "Yes" : "No" } </Col3>
      <Col4> { description } </Col4>
    </TableRow>
  )
}

const PropertiesTable = ({node, required, links}) =>{
  let properties_fields = ['Property','Type','Required', 'Description']
  let linknames = links.map((link, i) => link['name']);
  let properties = Object.keys(node['properties'])
  return(
    <Table>
      <TableHead>
        <TableRow>
          <Col1 first_cr>Property</Col1>
          <Col2 first_cr>Type</Col2>
          <Col3 first_cr>Required</Col3>
          <Col4 first_cr>Description</Col4>
        </TableRow>
      </TableHead>

      <tbody>
        {
        properties.map( (property, i) =>
          (! linknames.includes(property)) &&
          <PropertyBullet key={i} required={required.includes(property)} property_name={property} property={node['properties'][property]}/>
         )
        }

      </tbody>
    </Table>

  )
}

const DataDictionaryNodeType = ({params,submission}) =>{
  let node = params.node
  let dictionary = submission.dictionary
  let links = [];
  let required = ('required' in dictionary[node]) ? dictionary[node].required : [];
  for (var link of submission.dictionary[node].links){
{'fraction_non_alphanumeric': 0.1809733431156762, 'fraction_numerical': 0.007214477867449254, 'mean_word_length': 2.8873574144486693, 'pattern_counts': {'":': 0, '<': 175, '<?xml version=': 0, '>': 203, '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': '3093054', 'n_tokens_mistral': 2766, 'n_tokens_neox': 2701, 'n_words': 618}