diff options
Diffstat (limited to 'app/assets/javascripts/search/store/getters.js')
-rw-r--r-- | app/assets/javascripts/search/store/getters.js | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/app/assets/javascripts/search/store/getters.js b/app/assets/javascripts/search/store/getters.js index 0278239c144..135c9a3d67c 100644 --- a/app/assets/javascripts/search/store/getters.js +++ b/app/assets/javascripts/search/store/getters.js @@ -1,5 +1,8 @@ -import { languageFilterData } from '~/search/sidebar/constants/language_filter_data'; -import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY } from './constants'; +import { findKey, has } from 'lodash'; +import { languageFilterData } from '~/search/sidebar/components/language_filter/data'; +import { formatSearchResultCount, addCountOverLimit } from '~/search/store/utils'; + +import { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY, ICON_MAP } from './constants'; export const frequentGroups = (state) => { return state.frequentItems[GROUPS_LOCAL_STORAGE_KEY]; @@ -9,10 +12,28 @@ export const frequentProjects = (state) => { return state.frequentItems[PROJECTS_LOCAL_STORAGE_KEY]; }; -export const langugageAggregationBuckets = (state) => { +export const languageAggregationBuckets = (state) => { return ( state.aggregations.data.find( (aggregation) => aggregation.name === languageFilterData.filterParam, )?.buckets || [] ); }; + +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; + +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: [], + })); |