Commit 5ae494c0 authored by Fatih Acet's avatar Fatih Acet

Merge branch 'winh-eslint-promise/no-nesting-project_select.js' into 'master'

Remove nested Promise from project select

See merge request gitlab-org/gitlab!17687
parents e707d8f1 8eefe4cd
...@@ -5,102 +5,103 @@ import Api from './api'; ...@@ -5,102 +5,103 @@ import Api from './api';
import ProjectSelectComboButton from './project_select_combo_button'; import ProjectSelectComboButton from './project_select_combo_button';
import { s__ } from './locale'; import { s__ } from './locale';
export default function projectSelect() { const projectSelect = () => {
import(/* webpackChunkName: 'select2' */ 'select2/select2') $('.ajax-project-select').each(function(i, select) {
.then(() => { var placeholder;
$('.ajax-project-select').each(function(i, select) { const simpleFilter = $(select).data('simpleFilter') || false;
var placeholder; this.groupId = $(select).data('groupId');
const simpleFilter = $(select).data('simpleFilter') || false; this.includeGroups = $(select).data('includeGroups');
this.groupId = $(select).data('groupId'); this.allProjects = $(select).data('allProjects') || false;
this.includeGroups = $(select).data('includeGroups'); this.orderBy = $(select).data('orderBy') || 'id';
this.allProjects = $(select).data('allProjects') || false; this.withIssuesEnabled = $(select).data('withIssuesEnabled');
this.orderBy = $(select).data('orderBy') || 'id'; this.withMergeRequestsEnabled = $(select).data('withMergeRequestsEnabled');
this.withIssuesEnabled = $(select).data('withIssuesEnabled'); this.withShared =
this.withMergeRequestsEnabled = $(select).data('withMergeRequestsEnabled'); $(select).data('withShared') === undefined ? true : $(select).data('withShared');
this.withShared = this.includeProjectsInSubgroups = $(select).data('includeProjectsInSubgroups') || false;
$(select).data('withShared') === undefined ? true : $(select).data('withShared'); this.allowClear = $(select).data('allowClear') || false;
this.includeProjectsInSubgroups = $(select).data('includeProjectsInSubgroups') || false;
this.allowClear = $(select).data('allowClear') || false;
placeholder = s__('ProjectSelect|Search for project'); placeholder = s__('ProjectSelect|Search for project');
if (this.includeGroups) { if (this.includeGroups) {
placeholder += s__('ProjectSelect| or group'); placeholder += s__('ProjectSelect| or group');
} }
$(select).select2({ $(select).select2({
placeholder, placeholder,
minimumInputLength: 0, minimumInputLength: 0,
query: (function(_this) { query: (function(_this) {
return function(query) { return function(query) {
var finalCallback, projectsCallback; var finalCallback, projectsCallback;
finalCallback = function(projects) { finalCallback = function(projects) {
var data;
data = {
results: projects,
};
return query.callback(data);
};
if (_this.includeGroups) {
projectsCallback = function(projects) {
var groupsCallback;
groupsCallback = function(groups) {
var data; var data;
data = { data = groups.concat(projects);
results: projects, return finalCallback(data);
};
return query.callback(data);
}; };
if (_this.includeGroups) { return Api.groups(query.term, {}, groupsCallback);
projectsCallback = function(projects) {
var groupsCallback;
groupsCallback = function(groups) {
var data;
data = groups.concat(projects);
return finalCallback(data);
};
return Api.groups(query.term, {}, groupsCallback);
};
} else {
projectsCallback = finalCallback;
}
if (_this.groupId) {
return Api.groupProjects(
_this.groupId,
query.term,
{
with_issues_enabled: _this.withIssuesEnabled,
with_merge_requests_enabled: _this.withMergeRequestsEnabled,
with_shared: _this.withShared,
include_subgroups: _this.includeProjectsInSubgroups,
},
projectsCallback,
);
} else {
return Api.projects(
query.term,
{
order_by: _this.orderBy,
with_issues_enabled: _this.withIssuesEnabled,
with_merge_requests_enabled: _this.withMergeRequestsEnabled,
membership: !_this.allProjects,
},
projectsCallback,
);
}
}; };
})(this), } else {
id(project) { projectsCallback = finalCallback;
if (simpleFilter) return project.id; }
return JSON.stringify({ if (_this.groupId) {
name: project.name, return Api.groupProjects(
url: project.web_url, _this.groupId,
}); query.term,
}, {
text(project) { with_issues_enabled: _this.withIssuesEnabled,
return project.name_with_namespace || project.name; with_merge_requests_enabled: _this.withMergeRequestsEnabled,
}, with_shared: _this.withShared,
include_subgroups: _this.includeProjectsInSubgroups,
},
projectsCallback,
);
} else {
return Api.projects(
query.term,
{
order_by: _this.orderBy,
with_issues_enabled: _this.withIssuesEnabled,
with_merge_requests_enabled: _this.withMergeRequestsEnabled,
membership: !_this.allProjects,
},
projectsCallback,
);
}
};
})(this),
id(project) {
if (simpleFilter) return project.id;
return JSON.stringify({
name: project.name,
url: project.web_url,
});
},
text(project) {
return project.name_with_namespace || project.name;
},
initSelection(el, callback) { initSelection(el, callback) {
return Api.project(el.val()).then(({ data }) => callback(data)); return Api.project(el.val()).then(({ data }) => callback(data));
}, },
allowClear: this.allowClear, allowClear: this.allowClear,
dropdownCssClass: 'ajax-project-dropdown', dropdownCssClass: 'ajax-project-dropdown',
}); });
if (simpleFilter) return select; if (simpleFilter) return select;
return new ProjectSelectComboButton(select); return new ProjectSelectComboButton(select);
}); });
}) };
export default () =>
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(projectSelect)
.catch(() => {}); .catch(() => {});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment