<commit_before>// @flow
import * as React from 'react';
import type { ApiHeaderDoc, HeaderFilterType } from '../../../../../model/livedoc';
import { CodeElementsList } from '../../../../shared/content/CodeElementsList';

export type HeaderRowProps = {
  header: ApiHeaderDoc,
}

export const HeaderRow = ({header}: HeaderRowProps) => {

  const value = getValueDescription(header.type, header.values);

  return <tr>
    <td>
      <code>{header.name}</code>
    </td>
    <td>{value}</td>
    {header.description && <td>{header.description}</td>}
  </tr>;
};

function getValueDescription(type: HeaderFilterType, values: string[]) {
  switch (type) {
    case 'REQUIRED_MATCHING':
      if (values.length > 1) {
        return ['one of ', <CodeElementsList items={values}/>];
      } else {
        return <CodeElementsList items={values}/>;
      }
    case 'OPTIONAL':
      if (values.length === 1) {
        return ['default: ', <code>{values[0]}</code>];
      } else {
        return '(optional)';
      }
    case 'FORBIDDEN':
      return '(forbidden)';
    case 'DIFFERENT':
      return ['not ', <CodeElementsList items={values}/>];
  }
}<commit_msg>Add default case in HeaderRow on header filter type<commit_after>// @flow
import * as React from 'react';
import type { ApiHeaderDoc, HeaderFilterType } from '../../../../../model/livedoc';
import { CodeElementsList } from '../../../../shared/content/CodeElementsList';

export type HeaderRowProps = {
  header: ApiHeaderDoc,
}

export const HeaderRow = ({header}: HeaderRowProps) => {

  const value = getValueDescription(header.type, header.values);

  return <tr>
    <td>
      <code>{header.name}</code>
    </td>
    <td>{value}</td>
    {header.description && <td>{header.description}</td>}
  </tr>;
};

function getValueDescription(type: HeaderFilterType, values: string[]) {
  const valList = <CodeElementsList items={values}/>;

  switch (type) {
    case 'REQUIRED_MATCHING':
      return valList;
    case 'OPTIONAL':
      if (values.length === 1) {
        return ['(optional) Default:', <br/>, valList];
      } else {
        return '(optional)';
      }
    case 'FORBIDDEN':
      return '(forbidden)';
    case 'DIFFERENT':
      return ['not ', valList];
    default:
      return null;
  }
}
{'fraction_non_alphanumeric': 0.17641882974043116, 'fraction_numerical': 0.0017597888253409592, 'mean_word_length': 2.968586387434555, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 33, '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': '3524054', 'n_tokens_mistral': 706, 'n_tokens_neox': 704, 'n_words': 170}