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
|
import { findKey, has } 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 { GROUPS_LOCAL_STORAGE_KEY, PROJECTS_LOCAL_STORAGE_KEY, ICON_MAP } from './constants';
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) => state?.urlQuery?.labels?.includes(label.key));
export const appliedSelectedLabels = (state) => {
return labelAggregationBuckets(state)?.filter((label) =>
state?.urlQuery?.labels?.includes(label.key),
);
};
export const filteredUnappliedSelectedLabels = (state) =>
filteredLabels(state)?.filter((label) => state?.query?.labels?.includes(label.key));
export const filteredUnselectedLabels = (state) => {
if (!state?.urlQuery?.labels) {
return filteredLabels(state);
}
return filteredLabels(state)?.filter((label) => !state?.urlQuery?.labels?.includes(label.key));
};
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: [],
}));
|