Commit a8869a57 authored by Brett Walker's avatar Brett Walker

Dynamically store the valid label endpoint

In order to ensure we have the right endpoint to query for an
issue's possible valid labels, we store that url in the issue
object that gets passed to the frontend.
parent 31733b6f
......@@ -30,6 +30,7 @@ class ListIssue {
this.toggleSubscriptionEndpoint = obj.toggle_subscription_endpoint;
this.milestone_id = obj.milestone_id;
this.project_id = obj.project_id;
this.validLabelsEndpoint = obj.valid_labels_endpoint;
if (obj.project) {
this.project = new IssueProject(obj.project);
......
......@@ -59,7 +59,6 @@ export default class LabelsSelect {
$toggleText = $dropdown.find('.dropdown-toggle-text');
namespacePath = $dropdown.data('namespacePath');
projectPath = $dropdown.data('projectPath');
labelUrl = $dropdown.data('labels');
issueUpdateURL = $dropdown.data('issueUpdate');
selectedLabel = $dropdown.data('selected');
if (selectedLabel != null && !$dropdown.hasClass('js-multiselect')) {
......@@ -168,6 +167,7 @@ export default class LabelsSelect {
$dropdown.glDropdown({
showMenuAbove: showMenuAbove,
data: function(term, callback) {
labelUrl = $dropdown.attr('data-labels');
axios
.get(labelUrl)
.then(res => {
......
......@@ -240,7 +240,8 @@ class Issue < ActiveRecord::Base
reference_path: issue_reference,
real_path: url_helper.project_issue_path(project, self),
issue_sidebar_endpoint: url_helper.project_issue_path(project, self, format: :json, serializer: 'sidebar'),
toggle_subscription_endpoint: url_helper.toggle_subscription_project_issue_path(project, self)
toggle_subscription_endpoint: url_helper.toggle_subscription_project_issue_path(project, self),
valid_labels_endpoint: url_helper.project_labels_path(project, format: :json, include_ancestor_groups: true)
)
end
......
......@@ -19,13 +19,13 @@
":value" => "label.id" }
.dropdown
%button.dropdown-menu-toggle.js-label-select.js-multiselect.js-issue-board-sidebar{ type: "button",
"v-bind:data-selected" => "selectedLabels",
":data-selected" => "selectedLabels",
":data-labels" => "issue.validLabelsEndpoint",
data: { toggle: "dropdown",
field_name: "issue[label_names][]",
show_no: "true",
show_any: "true",
project_id: @project&.try(:id),
labels: labels_filter_path_with_defaults,
namespace_path: @namespace_path,
project_path: @project.try(:path) } }
%span.dropdown-toggle-text
......
title: Make Issue Board sidebar show project-specific labels based on selected Issue
merge_request: 22475
author:
type: fixed
# frozen_string_literal: true
require 'rails_helper'
describe 'Group Issue Boards', :js do
include BoardHelpers
let(:group) { create(:group) }
let(:user) { create(:group_member, user: create(:user), group: group ).user }
let!(:project_1) { create(:project, :public, group: group) }
let!(:project_2) { create(:project, :public, group: group) }
let!(:project_1_label) { create(:label, project: project_1, name: 'Development 1') }
let!(:project_2_label) { create(:label, project: project_2, name: 'Development 2') }
let!(:group_label) { create(:group_label, title: 'Bug', description: 'Fusce consequat', group: group) }
let!(:issue_1) { create(:labeled_issue, project: project_1, relative_position: 1) }
let!(:issue_2) { create(:labeled_issue, project: project_2, relative_position: 2) }
let(:board) { create(:board, group: group) }
let!(:list) { create(:list, board: board, label: project_1_label, position: 0) }
let(:card) { find('.board:nth-child(1)').first('.board-card') }
before do
sign_in(user)
visit group_board_path(group, board)
wait_for_requests
end
context 'labels' do
it 'only shows valid labels for the issue project and group' do
click_card(card)
page.within('.labels') do
click_link 'Edit'
wait_for_requests
page.within('.selectbox') do
expect(page).to have_content(project_1_label.title)
expect(page).to have_content(group_label.title)
expect(page).not_to have_content(project_2_label.title)
end
end
end
end
end
......@@ -15,6 +15,7 @@
"relative_position": { "type": "integer" },
"issue_sidebar_endpoint": { "type": "string" },
"toggle_subscription_endpoint": { "type": "string" },
"valid_labels_endpoint": { "type": "string" },
"reference_path": { "type": "string" },
"real_path": { "type": "string" },
"project": {
......
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