2021-03-11 19:13:27 +05:30
|
|
|
import { mergeUrlParams } from '../lib/utils/url_utility';
|
|
|
|
import DropdownAjaxFilter from './dropdown_ajax_filter';
|
|
|
|
import DropdownEmoji from './dropdown_emoji';
|
2019-07-07 11:18:12 +05:30
|
|
|
import DropdownHint from './dropdown_hint';
|
|
|
|
import DropdownNonUser from './dropdown_non_user';
|
2020-03-13 15:44:24 +05:30
|
|
|
import DropdownOperator from './dropdown_operator';
|
2021-03-11 19:13:27 +05:30
|
|
|
import DropdownUser from './dropdown_user';
|
2019-07-07 11:18:12 +05:30
|
|
|
import DropdownUtils from './dropdown_utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import NullDropdown from './null_dropdown';
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
export default class AvailableDropdownMappings {
|
2020-04-08 14:13:33 +05:30
|
|
|
constructor({
|
2019-09-04 21:01:54 +05:30
|
|
|
container,
|
2019-09-30 21:07:59 +05:30
|
|
|
runnerTagsEndpoint,
|
2019-09-04 21:01:54 +05:30
|
|
|
labelsEndpoint,
|
|
|
|
milestonesEndpoint,
|
2019-12-26 22:10:19 +05:30
|
|
|
releasesEndpoint,
|
2021-01-03 14:25:43 +05:30
|
|
|
environmentsEndpoint,
|
2019-09-04 21:01:54 +05:30
|
|
|
groupsOnly,
|
|
|
|
includeAncestorGroups,
|
|
|
|
includeDescendantGroups,
|
2020-04-08 14:13:33 +05:30
|
|
|
}) {
|
2019-07-07 11:18:12 +05:30
|
|
|
this.container = container;
|
2019-09-30 21:07:59 +05:30
|
|
|
this.runnerTagsEndpoint = runnerTagsEndpoint;
|
2019-09-04 21:01:54 +05:30
|
|
|
this.labelsEndpoint = labelsEndpoint;
|
|
|
|
this.milestonesEndpoint = milestonesEndpoint;
|
2019-12-26 22:10:19 +05:30
|
|
|
this.releasesEndpoint = releasesEndpoint;
|
2021-01-03 14:25:43 +05:30
|
|
|
this.environmentsEndpoint = environmentsEndpoint;
|
2019-07-07 11:18:12 +05:30
|
|
|
this.groupsOnly = groupsOnly;
|
|
|
|
this.includeAncestorGroups = includeAncestorGroups;
|
|
|
|
this.includeDescendantGroups = includeDescendantGroups;
|
|
|
|
this.filteredSearchInput = this.container.querySelector('.filtered-search');
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllowedMappings(supportedTokens) {
|
|
|
|
return this.buildMappings(supportedTokens, this.getMappings());
|
|
|
|
}
|
|
|
|
|
|
|
|
buildMappings(supportedTokens, availableMappings) {
|
|
|
|
const allowedMappings = {
|
|
|
|
hint: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownHint,
|
|
|
|
element: this.container.querySelector('#js-dropdown-hint'),
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
operator: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownOperator,
|
|
|
|
element: this.container.querySelector('#js-dropdown-operator'),
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
supportedTokens.forEach((type) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
if (availableMappings[type]) {
|
|
|
|
allowedMappings[type] = availableMappings[type];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return allowedMappings;
|
|
|
|
}
|
|
|
|
|
|
|
|
getMappings() {
|
|
|
|
return {
|
|
|
|
author: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownUser,
|
|
|
|
element: this.container.querySelector('#js-dropdown-author'),
|
|
|
|
},
|
|
|
|
assignee: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownUser,
|
|
|
|
element: this.container.querySelector('#js-dropdown-assignee'),
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
reviewer: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownUser,
|
|
|
|
element: this.container.querySelector('#js-dropdown-reviewer'),
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
'approved-by': {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownUser,
|
|
|
|
element: this.container.querySelector('#js-dropdown-approved-by'),
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
milestone: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownNonUser,
|
|
|
|
extraArguments: {
|
|
|
|
endpoint: this.getMilestoneEndpoint(),
|
|
|
|
symbol: '%',
|
|
|
|
},
|
|
|
|
element: this.container.querySelector('#js-dropdown-milestone'),
|
|
|
|
},
|
2019-12-26 22:10:19 +05:30
|
|
|
release: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownNonUser,
|
|
|
|
extraArguments: {
|
|
|
|
endpoint: this.getReleasesEndpoint(),
|
|
|
|
symbol: '',
|
|
|
|
|
|
|
|
// The DropdownNonUser class is hardcoded to look for and display a
|
|
|
|
// "title" property, so we need to add this property to each release object
|
2021-03-08 18:12:59 +05:30
|
|
|
preprocessing: (releases) => releases.map((r) => ({ ...r, title: r.tag })),
|
2019-12-26 22:10:19 +05:30
|
|
|
},
|
|
|
|
element: this.container.querySelector('#js-dropdown-release'),
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
label: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownNonUser,
|
|
|
|
extraArguments: {
|
|
|
|
endpoint: this.getLabelsEndpoint(),
|
|
|
|
symbol: '~',
|
|
|
|
preprocessing: DropdownUtils.duplicateLabelPreprocessing,
|
|
|
|
},
|
|
|
|
element: this.container.querySelector('#js-dropdown-label'),
|
|
|
|
},
|
|
|
|
'my-reaction': {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownEmoji,
|
|
|
|
element: this.container.querySelector('#js-dropdown-my-reaction'),
|
|
|
|
},
|
2020-10-24 23:57:45 +05:30
|
|
|
draft: {
|
2019-07-07 11:18:12 +05:30
|
|
|
reference: null,
|
|
|
|
gl: DropdownNonUser,
|
|
|
|
element: this.container.querySelector('#js-dropdown-wip'),
|
|
|
|
},
|
|
|
|
confidential: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownNonUser,
|
|
|
|
element: this.container.querySelector('#js-dropdown-confidential'),
|
|
|
|
},
|
|
|
|
status: {
|
|
|
|
reference: null,
|
|
|
|
gl: NullDropdown,
|
|
|
|
element: this.container.querySelector('#js-dropdown-admin-runner-status'),
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
reference: null,
|
|
|
|
gl: NullDropdown,
|
|
|
|
element: this.container.querySelector('#js-dropdown-admin-runner-type'),
|
|
|
|
},
|
|
|
|
tag: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownAjaxFilter,
|
|
|
|
extraArguments: {
|
|
|
|
endpoint: this.getRunnerTagsEndpoint(),
|
|
|
|
symbol: '~',
|
|
|
|
},
|
|
|
|
element: this.container.querySelector('#js-dropdown-runner-tag'),
|
|
|
|
},
|
|
|
|
'target-branch': {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownNonUser,
|
|
|
|
extraArguments: {
|
|
|
|
endpoint: this.getMergeRequestTargetBranchesEndpoint(),
|
|
|
|
symbol: '',
|
|
|
|
},
|
|
|
|
element: this.container.querySelector('#js-dropdown-target-branch'),
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
environment: {
|
|
|
|
reference: null,
|
|
|
|
gl: DropdownNonUser,
|
|
|
|
extraArguments: {
|
|
|
|
endpoint: this.getEnvironmentsEndpoint(),
|
|
|
|
symbol: '',
|
2021-03-08 18:12:59 +05:30
|
|
|
preprocessing: (data) => data.map((env) => ({ title: env })),
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
|
|
|
element: this.container.querySelector('#js-dropdown-environment'),
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getMilestoneEndpoint() {
|
2019-09-04 21:01:54 +05:30
|
|
|
return `${this.milestonesEndpoint}.json`;
|
2019-07-07 11:18:12 +05:30
|
|
|
}
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
getReleasesEndpoint() {
|
|
|
|
return `${this.releasesEndpoint}.json`;
|
|
|
|
}
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
getLabelsEndpoint() {
|
2019-09-04 21:01:54 +05:30
|
|
|
let endpoint = `${this.labelsEndpoint}.json?`;
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
if (this.groupsOnly) {
|
|
|
|
endpoint = `${endpoint}only_group_labels=true&`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.includeAncestorGroups) {
|
|
|
|
endpoint = `${endpoint}include_ancestor_groups=true&`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.includeDescendantGroups) {
|
|
|
|
endpoint = `${endpoint}include_descendant_groups=true`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return endpoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
getRunnerTagsEndpoint() {
|
2019-09-30 21:07:59 +05:30
|
|
|
return `${this.runnerTagsEndpoint}.json`;
|
2019-07-07 11:18:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
getMergeRequestTargetBranchesEndpoint() {
|
2021-03-08 18:12:59 +05:30
|
|
|
const endpoint = `${
|
|
|
|
gon.relative_url_root || ''
|
|
|
|
}/autocomplete/merge_request_target_branches.json`;
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
const params = {
|
|
|
|
group_id: this.getGroupId(),
|
|
|
|
project_id: this.getProjectId(),
|
|
|
|
};
|
|
|
|
|
|
|
|
return mergeUrlParams(params, endpoint);
|
|
|
|
}
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
getEnvironmentsEndpoint() {
|
|
|
|
return `${this.environmentsEndpoint}.json`;
|
|
|
|
}
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
getGroupId() {
|
|
|
|
return this.filteredSearchInput.getAttribute('data-group-id') || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
getProjectId() {
|
|
|
|
return this.filteredSearchInput.getAttribute('data-project-id') || '';
|
|
|
|
}
|
|
|
|
}
|