{"size": 828, "ext": "js", "max_stars_repo_path": "src/components/TypeComponents/SimpleSearch/Form/validators.js", "max_stars_repo_name": "folio-org/ui-dashboard", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/TypeComponents/SimpleSearch/Form/validators.js", "max_issues_repo_name": "folio-org/ui-dashboard", "max_issues_repo_issues_event_min_datetime": "2021-01-23T01:29:36.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T10:56:14.000Z", "max_forks_repo_path": "src/components/TypeComponents/SimpleSearch/Form/validators.js", "max_forks_repo_name": "folio-org/ui-dashboard", "max_forks_repo_forks_event_min_datetime": "2021-03-17T11:04:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-10-16T12:59:21.000Z"}
{"max_stars_count": null, "max_issues_count": 129, "max_forks_count": 3, "avg_line_length": 23.6571428571, "max_line_length": 94, "alphanum_fraction": 0.5821256039}
import React from 'react';
import { get } from 'lodash';
import { FormattedMessage } from 'react-intl';

const filterPresent = (value, allValues, meta) => {
  if (meta) {
    // Name is something like "filterColumns[3].name" and we want the "filterColumns" array
    const filterColumnCount = get(
      allValues,
      meta.name.substring(0, meta.name.lastIndexOf('[')), []
    ).map(fc => fc.name).reduce(
      (acc, cur) => {
        if (cur === value) {
          return acc + 1;
        }
        return acc;
      },
      0
    );
    if (filterColumnCount > 1) {
      return (
        <div data-test-error-multiple-open-ended>
          <FormattedMessage id="ui-dashboard.simpleSearchForm.filters.filterAlreadyPresent" />
        </div>
      );
    }
  }

  return undefined;
};

export default {
  filterPresent
};
