Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-02 03:08:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-02 03:08:07 +0300
commit2e2cd0ea3e50af738049eccde210713f976a6d7c (patch)
treee549e791b815fae06f6ec905f3877ec7f5f55e2a /app/assets/javascripts/search_autocomplete.js
parent3902d464d6045c2f5f6b687c0acf3254d7458928 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/search_autocomplete.js')
-rw-r--r--app/assets/javascripts/search_autocomplete.js122
1 files changed, 70 insertions, 52 deletions
diff --git a/app/assets/javascripts/search_autocomplete.js b/app/assets/javascripts/search_autocomplete.js
index d8eb981c106..05e0b9e7089 100644
--- a/app/assets/javascripts/search_autocomplete.js
+++ b/app/assets/javascripts/search_autocomplete.js
@@ -2,7 +2,7 @@
import $ from 'jquery';
import { escape, throttle } from 'lodash';
-import { s__, __ } from '~/locale';
+import { s__, __, sprintf } from '~/locale';
import { getIdenticonBackgroundClass, getIdenticonTitle } from '~/helpers/avatar_helper';
import axios from './lib/utils/axios_utils';
import {
@@ -170,33 +170,24 @@ export class SearchAutocomplete {
},
})
.then(response => {
- // Hide dropdown menu if no suggestions returns
- if (!response.data.length) {
- this.disableAutocomplete();
- return;
- }
+ const options = this.scopedSearchOptions(term);
- const data = [];
// List results
- let firstCategory = true;
- let lastCategory;
+ let lastCategory = null;
for (let i = 0, len = response.data.length; i < len; i += 1) {
const suggestion = response.data[i];
// Add group header before list each group
if (lastCategory !== suggestion.category) {
- if (!firstCategory) {
- data.push({ type: 'separator' });
- }
- if (firstCategory) {
- firstCategory = false;
- }
- data.push({
+ options.push({ type: 'separator' });
+ options.push({
type: 'header',
content: suggestion.category,
});
lastCategory = suggestion.category;
}
- data.push({
+
+ // Add the suggestion
+ options.push({
id: `${suggestion.category.toLowerCase()}-${suggestion.id}`,
icon: this.getAvatar(suggestion),
category: suggestion.category,
@@ -204,39 +195,8 @@ export class SearchAutocomplete {
url: suggestion.url,
});
}
- // Add option to proceed with the search
- if (data.length) {
- const icon = spriteIcon('search', 's16 inline-search-icon');
- let template;
-
- if (this.projectInputEl.val()) {
- template = s__('SearchAutocomplete|in this project');
- }
- if (this.groupInputEl.val()) {
- template = s__('SearchAutocomplete|in this group');
- }
-
- data.unshift({ type: 'separator' });
- data.unshift({
- icon,
- text: term,
- template: s__('SearchAutocomplete|in all GitLab'),
- url: `${gon.relative_url_root}/search?search=${term}`,
- });
-
- if (template) {
- data.unshift({
- icon,
- text: term,
- template,
- url: `${
- gon.relative_url_root
- }/search?search=${term}&project_id=${this.projectInputEl.val()}&group_id=${this.groupInputEl.val()}`,
- });
- }
- }
- callback(data);
+ callback(options);
this.loadingSuggestions = false;
this.highlightFirstRow();
@@ -253,10 +213,10 @@ export class SearchAutocomplete {
// Get options
let options;
- if (isInGroupsPage() && groupOptions) {
- options = groupOptions[getGroupSlug()];
- } else if (isInProjectPage() && projectOptions) {
+ if (isInProjectPage() && projectOptions) {
options = projectOptions[getProjectSlug()];
+ } else if (isInGroupsPage() && groupOptions) {
+ options = groupOptions[getGroupSlug()];
} else if (dashboardOptions) {
options = dashboardOptions;
}
@@ -301,6 +261,64 @@ export class SearchAutocomplete {
return items;
}
+ // Add option to proceed with the search for each
+ // scope that is currently available, namely:
+ //
+ // - Search in this project
+ // - Search in this group (or project's group)
+ // - Search in all GitLab
+ scopedSearchOptions(term) {
+ const icon = spriteIcon('search', 's16 inline-search-icon');
+ const projectId = this.projectInputEl.val();
+ const groupId = this.groupInputEl.val();
+ const options = [];
+
+ if (projectId) {
+ const projectOptions = gl.projectOptions[getProjectSlug()];
+ const url = groupId
+ ? `${gon.relative_url_root}/search?search=${term}&project_id=${projectId}&group_id=${groupId}`
+ : `${gon.relative_url_root}/search?search=${term}&project_id=${projectId}`;
+
+ options.push({
+ icon,
+ text: term,
+ template: sprintf(
+ s__(`SearchAutocomplete|in project %{projectName}`),
+ {
+ projectName: `<i>${projectOptions.name}</i>`,
+ },
+ false,
+ ),
+ url,
+ });
+ }
+
+ if (groupId) {
+ const groupOptions = gl.groupOptions[getGroupSlug()];
+ options.push({
+ icon,
+ text: term,
+ template: sprintf(
+ s__(`SearchAutocomplete|in group %{groupName}`),
+ {
+ groupName: `<i>${groupOptions.name}</i>`,
+ },
+ false,
+ ),
+ url: `${gon.relative_url_root}/search?search=${term}&group_id=${groupId}`,
+ });
+ }
+
+ options.push({
+ icon,
+ text: term,
+ template: s__('SearchAutocomplete|in all GitLab'),
+ url: `${gon.relative_url_root}/search?search=${term}`,
+ });
+
+ return options;
+ }
+
serializeState() {
return {
// Search Criteria