2021-12-13 07:12:59 -05:00
|
|
|
import { omitBy, isNil } from 'lodash';
|
2021-09-15 14:11:29 -04:00
|
|
|
import { objectToQuery } from '~/lib/utils/url_utility';
|
|
|
|
|
2021-09-09 23:10:59 -04:00
|
|
|
import {
|
|
|
|
MSG_ISSUES_ASSIGNED_TO_ME,
|
|
|
|
MSG_ISSUES_IVE_CREATED,
|
|
|
|
MSG_MR_ASSIGNED_TO_ME,
|
|
|
|
MSG_MR_IM_REVIEWER,
|
|
|
|
MSG_MR_IVE_CREATED,
|
2021-09-15 14:11:29 -04:00
|
|
|
MSG_IN_PROJECT,
|
|
|
|
MSG_IN_GROUP,
|
|
|
|
MSG_IN_ALL_GITLAB,
|
2021-09-09 23:10:59 -04:00
|
|
|
} from '../constants';
|
|
|
|
|
2021-09-15 14:11:29 -04:00
|
|
|
export const searchQuery = (state) => {
|
2021-12-13 07:12:59 -05:00
|
|
|
const query = omitBy(
|
|
|
|
{
|
|
|
|
search: state.search,
|
|
|
|
nav_source: 'navbar',
|
|
|
|
project_id: state.searchContext.project?.id,
|
|
|
|
group_id: state.searchContext.group?.id,
|
|
|
|
scope: state.searchContext?.scope,
|
|
|
|
},
|
|
|
|
isNil,
|
|
|
|
);
|
2021-09-15 14:11:29 -04:00
|
|
|
|
|
|
|
return `${state.searchPath}?${objectToQuery(query)}`;
|
|
|
|
};
|
|
|
|
|
2021-09-21 14:11:18 -04:00
|
|
|
export const autocompleteQuery = (state) => {
|
2021-12-13 07:12:59 -05:00
|
|
|
const query = omitBy(
|
|
|
|
{
|
|
|
|
term: state.search,
|
|
|
|
project_id: state.searchContext.project?.id,
|
|
|
|
project_ref: state.searchContext?.ref,
|
|
|
|
},
|
|
|
|
isNil,
|
|
|
|
);
|
2021-09-21 14:11:18 -04:00
|
|
|
|
|
|
|
return `${state.autocompletePath}?${objectToQuery(query)}`;
|
|
|
|
};
|
|
|
|
|
2021-09-09 23:10:59 -04:00
|
|
|
export const scopedIssuesPath = (state) => {
|
|
|
|
return (
|
|
|
|
state.searchContext.project_metadata?.issues_path ||
|
|
|
|
state.searchContext.group_metadata?.issues_path ||
|
|
|
|
state.issuesPath
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const scopedMRPath = (state) => {
|
|
|
|
return (
|
|
|
|
state.searchContext.project_metadata?.mr_path ||
|
|
|
|
state.searchContext.group_metadata?.mr_path ||
|
|
|
|
state.mrPath
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const defaultSearchOptions = (state, getters) => {
|
|
|
|
const userName = gon.current_username;
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
2021-11-22 16:10:35 -05:00
|
|
|
html_id: 'default-issues-assigned',
|
2021-09-09 23:10:59 -04:00
|
|
|
title: MSG_ISSUES_ASSIGNED_TO_ME,
|
|
|
|
url: `${getters.scopedIssuesPath}/?assignee_username=${userName}`,
|
|
|
|
},
|
|
|
|
{
|
2021-11-22 16:10:35 -05:00
|
|
|
html_id: 'default-issues-created',
|
2021-09-09 23:10:59 -04:00
|
|
|
title: MSG_ISSUES_IVE_CREATED,
|
|
|
|
url: `${getters.scopedIssuesPath}/?author_username=${userName}`,
|
|
|
|
},
|
|
|
|
{
|
2021-11-22 16:10:35 -05:00
|
|
|
html_id: 'default-mrs-assigned',
|
2021-09-09 23:10:59 -04:00
|
|
|
title: MSG_MR_ASSIGNED_TO_ME,
|
|
|
|
url: `${getters.scopedMRPath}/?assignee_username=${userName}`,
|
|
|
|
},
|
|
|
|
{
|
2021-11-22 16:10:35 -05:00
|
|
|
html_id: 'default-mrs-reviewer',
|
2021-09-09 23:10:59 -04:00
|
|
|
title: MSG_MR_IM_REVIEWER,
|
|
|
|
url: `${getters.scopedMRPath}/?reviewer_username=${userName}`,
|
|
|
|
},
|
|
|
|
{
|
2021-11-22 16:10:35 -05:00
|
|
|
html_id: 'default-mrs-created',
|
2021-09-09 23:10:59 -04:00
|
|
|
title: MSG_MR_IVE_CREATED,
|
|
|
|
url: `${getters.scopedMRPath}/?author_username=${userName}`,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
};
|
2021-09-15 14:11:29 -04:00
|
|
|
|
|
|
|
export const projectUrl = (state) => {
|
2021-12-13 07:12:59 -05:00
|
|
|
const query = omitBy(
|
|
|
|
{
|
|
|
|
search: state.search,
|
|
|
|
nav_source: 'navbar',
|
|
|
|
project_id: state.searchContext?.project?.id,
|
|
|
|
group_id: state.searchContext?.group?.id,
|
|
|
|
scope: state.searchContext?.scope,
|
|
|
|
},
|
|
|
|
isNil,
|
|
|
|
);
|
2021-09-15 14:11:29 -04:00
|
|
|
|
|
|
|
return `${state.searchPath}?${objectToQuery(query)}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const groupUrl = (state) => {
|
2021-12-13 07:12:59 -05:00
|
|
|
const query = omitBy(
|
|
|
|
{
|
|
|
|
search: state.search,
|
|
|
|
nav_source: 'navbar',
|
|
|
|
group_id: state.searchContext?.group?.id,
|
|
|
|
scope: state.searchContext?.scope,
|
|
|
|
},
|
|
|
|
isNil,
|
|
|
|
);
|
2021-09-15 14:11:29 -04:00
|
|
|
|
|
|
|
return `${state.searchPath}?${objectToQuery(query)}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const allUrl = (state) => {
|
2021-12-13 07:12:59 -05:00
|
|
|
const query = omitBy(
|
|
|
|
{
|
|
|
|
search: state.search,
|
|
|
|
nav_source: 'navbar',
|
|
|
|
scope: state.searchContext?.scope,
|
|
|
|
},
|
|
|
|
isNil,
|
|
|
|
);
|
2021-09-15 14:11:29 -04:00
|
|
|
|
|
|
|
return `${state.searchPath}?${objectToQuery(query)}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const scopedSearchOptions = (state, getters) => {
|
|
|
|
const options = [];
|
|
|
|
|
|
|
|
if (state.searchContext.project) {
|
|
|
|
options.push({
|
2021-11-22 16:10:35 -05:00
|
|
|
html_id: 'scoped-in-project',
|
2021-09-15 14:11:29 -04:00
|
|
|
scope: state.searchContext.project.name,
|
|
|
|
description: MSG_IN_PROJECT,
|
|
|
|
url: getters.projectUrl,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.searchContext.group) {
|
|
|
|
options.push({
|
2021-11-22 16:10:35 -05:00
|
|
|
html_id: 'scoped-in-group',
|
2021-09-15 14:11:29 -04:00
|
|
|
scope: state.searchContext.group.name,
|
|
|
|
description: MSG_IN_GROUP,
|
|
|
|
url: getters.groupUrl,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
options.push({
|
2021-11-22 16:10:35 -05:00
|
|
|
html_id: 'scoped-in-all',
|
2021-09-15 14:11:29 -04:00
|
|
|
description: MSG_IN_ALL_GITLAB,
|
|
|
|
url: getters.allUrl,
|
|
|
|
});
|
|
|
|
|
|
|
|
return options;
|
|
|
|
};
|
2021-09-21 14:11:18 -04:00
|
|
|
|
|
|
|
export const autocompleteGroupedSearchOptions = (state) => {
|
|
|
|
const groupedOptions = {};
|
|
|
|
const results = [];
|
|
|
|
|
|
|
|
state.autocompleteOptions.forEach((option) => {
|
|
|
|
const category = groupedOptions[option.category];
|
|
|
|
|
|
|
|
if (category) {
|
|
|
|
category.data.push(option);
|
|
|
|
} else {
|
|
|
|
groupedOptions[option.category] = {
|
|
|
|
category: option.category,
|
|
|
|
data: [option],
|
|
|
|
};
|
|
|
|
|
|
|
|
results.push(groupedOptions[option.category]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return results;
|
|
|
|
};
|
2021-11-22 16:10:35 -05:00
|
|
|
|
|
|
|
export const searchOptions = (state, getters) => {
|
|
|
|
if (!state.search) {
|
|
|
|
return getters.defaultSearchOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sortedAutocompleteOptions = Object.values(getters.autocompleteGroupedSearchOptions).reduce(
|
|
|
|
(options, group) => {
|
|
|
|
return [...options, ...group.data];
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
|
|
|
|
return getters.scopedSearchOptions.concat(sortedAutocompleteOptions);
|
|
|
|
};
|