debian-mirror-gitlab/app/assets/javascripts/search/store/getters.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-05-27 22:25:52 +05:30
import { findKey, has } from 'lodash';
2023-06-20 00:43:36 +05:30
import { languageFilterData } from '~/search/sidebar/components/language_filter/data';
import { formatSearchResultCount, addCountOverLimit } from '~/search/store/utils';
2023-05-27 22:25:52 +05:30
2023-06-20 00:43:36 +05:30
import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY, ICON_MAP } from './constants';
2021-09-30 23:02:18 +05:30
export const frequentGroups = (state) => {
return state.frequentItems[GROUPS_LOCAL_STORAGE_KEY];
};
export const frequentProjects = (state) => {
return state.frequentItems[PROJECTS_LOCAL_STORAGE_KEY];
};
2023-04-23 21:23:45 +05:30
2023-05-27 22:25:52 +05:30
export const languageAggregationBuckets = (state) => {
2023-04-23 21:23:45 +05:30
return (
state.aggregations.data.find(
(aggregation) => aggregation.name === languageFilterData.filterParam,
)?.buckets || []
);
};
2023-05-27 22:25:52 +05:30
export const currentScope = (state) => findKey(state.navigation, { active: true });
export const queryLanguageFilters = (state) => state.query[languageFilterData.filterParam] || [];
export const currentUrlQueryHasLanguageFilters = (state) =>
has(state.urlQuery, languageFilterData.filterParam) &&
state.urlQuery[languageFilterData.filterParam]?.length > 0;
2023-06-20 00:43:36 +05:30
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: [],
}));