{"size": 1225, "ext": "js", "max_stars_repo_path": "src/components/search_bar/filters/filters.js", "max_stars_repo_name": "naveed-ahmad/eui", "max_stars_repo_stars_event_min_datetime": "2020-02-27T05:17:30.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-04T15:01:28.000Z", "max_issues_repo_path": "src/components/search_bar/filters/filters.js", "max_issues_repo_name": "naveed-ahmad/eui", "max_issues_repo_issues_event_min_datetime": "2020-07-18T09:25:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-08T23:39:24.000Z", "max_forks_repo_path": "src/components/search_bar/filters/filters.js", "max_forks_repo_name": "naveed-ahmad/eui", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 9, "max_forks_count": null, "avg_line_length": 31.4102564103, "max_line_length": 69, "alphanum_fraction": 0.7420408163}
import React from 'react';
import { IsFilter, IsFilterConfigType } from './is_filter';
import {
  FieldValueSelectionFilter,
  FieldValueSelectionFilterConfigType,
} from './field_value_selection_filter';
import {
  FieldValueToggleFilter,
  FieldValueToggleFilterConfigType,
} from './field_value_toggle_filter';
import {
  FieldValueToggleGroupFilter,
  FieldValueToggleGroupFilterConfigType,
} from './field_value_toggle_group_filter';
import PropTypes from 'prop-types';

export const createFilter = (index, config, query, onChange) => {
  const props = { index, config, query, onChange };
  switch (config.type) {
    case 'is':
      return <IsFilter {...props} />;
    case 'field_value_selection':
      return <FieldValueSelectionFilter {...props} />;
    case 'field_value_toggle':
      return <FieldValueToggleFilter {...props} />;
    case 'field_value_toggle_group':
      return <FieldValueToggleGroupFilter {...props} />;
    default:
      throw new Error(`Unknown search filter type [${config.type}]`);
  }
};

export const FilterConfigType = PropTypes.oneOfType([
  IsFilterConfigType,
  FieldValueSelectionFilterConfigType,
  FieldValueToggleFilterConfigType,
  FieldValueToggleGroupFilterConfigType,
]);
