From de784ac10516ec1e1c93d164f3d99b2ff09e5889 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sat, 9 Mar 2019 12:22:58 +0000 Subject: Filter merge requests by target branch --- .../filtered_search/available_dropdown_mappings.js | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'app/assets/javascripts/filtered_search/available_dropdown_mappings.js') diff --git a/app/assets/javascripts/filtered_search/available_dropdown_mappings.js b/app/assets/javascripts/filtered_search/available_dropdown_mappings.js index e2f9c03ee65..be867a3838d 100644 --- a/app/assets/javascripts/filtered_search/available_dropdown_mappings.js +++ b/app/assets/javascripts/filtered_search/available_dropdown_mappings.js @@ -5,6 +5,7 @@ import DropdownEmoji from './dropdown_emoji'; import NullDropdown from './null_dropdown'; import DropdownAjaxFilter from './dropdown_ajax_filter'; import DropdownUtils from './dropdown_utils'; +import { mergeUrlParams } from '../lib/utils/url_utility'; export default class AvailableDropdownMappings { constructor(container, baseEndpoint, groupsOnly, includeAncestorGroups, includeDescendantGroups) { @@ -13,6 +14,7 @@ export default class AvailableDropdownMappings { this.groupsOnly = groupsOnly; this.includeAncestorGroups = includeAncestorGroups; this.includeDescendantGroups = includeDescendantGroups; + this.filteredSearchInput = this.container.querySelector('.filtered-search'); } getAllowedMappings(supportedTokens) { @@ -102,6 +104,15 @@ export default class AvailableDropdownMappings { }, 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'), + }, }; } @@ -130,4 +141,24 @@ export default class AvailableDropdownMappings { getRunnerTagsEndpoint() { return `${this.baseEndpoint}/admin/runners/tag_list.json`; } + + getMergeRequestTargetBranchesEndpoint() { + const endpoint = `${gon.relative_url_root || + ''}/autocomplete/merge_request_target_branches.json`; + + const params = { + group_id: this.getGroupId(), + project_id: this.getProjectId(), + }; + + return mergeUrlParams(params, endpoint); + } + + getGroupId() { + return this.filteredSearchInput.getAttribute('data-group-id') || ''; + } + + getProjectId() { + return this.filteredSearchInput.getAttribute('data-project-id') || ''; + } } -- cgit v1.2.1