All files / app/assets/javascripts/search/store getters.js

100% Statements 51/51
62.5% Branches 10/16
100% Functions 30/30
100% Lines 41/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91                300x 522x   3x 100x   3x 200x   3x 208x   3x   3x 1x     3x 1x     3x 1x   1x         3x 325x   132x         3x 105x 102x   3x 12x       3x 57x   3x 73x 100x       3x 57x   3x 73x 100x     3x 73x 100x     3x   3x 10x                 3x  
import { findKey, intersection } from 'lodash';
import { languageFilterData } from '~/search/sidebar/components/language_filter/data';
import { labelFilterData } from '~/search/sidebar/components/label_filter/data';
import { formatSearchResultCount, addCountOverLimit } from '~/search/store/utils';
 
import { PROJECT_DATA } from '~/search/sidebar/constants';
import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY, ICON_MAP } from './constants';
 
const queryLabelFilters = (state) => state?.query?.[labelFilterData.filterParam] || [];
const urlQueryLabelFilters = (state) => state?.urlQuery?.[labelFilterData.filterParam] || [];
 
const appliedSelectedLabelsKeys = (state) =>
  intersection(urlQueryLabelFilters(state), queryLabelFilters(state));
 
const unselectedLabelsKeys = (state) =>
  urlQueryLabelFilters(state)?.filter((label) => !queryLabelFilters(state)?.includes(label));
 
const unappliedNewLabelKeys = (state) =>
  state?.query?.labels?.filter((label) => !urlQueryLabelFilters(state)?.includes(label));
 
export const queryLanguageFilters = (state) => state.query[languageFilterData.filterParam] || [];
 
export const frequentGroups = (state) => {
  return state.frequentItems[GROUPS_LOCAL_STORAGE_KEY];
};
 
export const frequentProjects = (state) => {
  return state.frequentItems[PROJECTS_LOCAL_STORAGE_KEY];
};
 
export const languageAggregationBuckets = (state) => {
  return (
    state.aggregations.data.find(
      (aggregation) => aggregation.name === languageFilterData.filterParam,
    )?.buckets || []
  );
};
 
export const labelAggregationBuckets = (state) => {
  return (
    state?.aggregations?.data?.find(
      (aggregation) => aggregation.name === labelFilterData.filterParam,
    )?.buckets || []
  );
};
 
export const filteredLabels = (state) => {
  if (state.searchLabelString === '') {
    return labelAggregationBuckets(state);
  }
  return labelAggregationBuckets(state).filter((label) => {
    return label.title.toLowerCase().includes(state.searchLabelString.toLowerCase());
  });
};
 
export const filteredAppliedSelectedLabels = (state) =>
  filteredLabels(state)?.filter((label) => urlQueryLabelFilters(state)?.includes(label.key));
 
export const appliedSelectedLabels = (state) => {
  return labelAggregationBuckets(state)?.filter((label) =>
    appliedSelectedLabelsKeys(state)?.includes(label.key),
  );
};
 
export const filteredUnselectedLabels = (state) =>
  filteredLabels(state)?.filter((label) => !urlQueryLabelFilters(state)?.includes(label.key));
 
export const unselectedLabels = (state) =>
  labelAggregationBuckets(state).filter((label) =>
    unselectedLabelsKeys(state)?.includes(label.key),
  );
 
export const unappliedNewLabels = (state) =>
  labelAggregationBuckets(state).filter((label) =>
    unappliedNewLabelKeys(state)?.includes(label.key),
  );
 
export const currentScope = (state) => findKey(state.navigation, { active: true });
 
export const navigationItems = (state) =>
  Object.values(state.navigation).map((item) => ({
    title: item.label,
    icon: ICON_MAP[item.scope] || '',
    link: item.link,
    is_active: Boolean(item?.active),
    pill_count: `${formatSearchResultCount(item?.count)}${addCountOverLimit(item?.count)}` || '',
    items: [],
  }));
 
export const showArchived = (state) => !state.query?.[PROJECT_DATA.queryParam];