Commit 4293e42d authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch...

Merge branch '322455-fix-sidebar-issue-labels-not-linking-properly-on-jira-issue-details-page' into 'master'

Fix sidebar issue labels not linking properly on Jira issue details page

See merge request gitlab-org/gitlab!54829
parents 0cd79ee8 e49d15e7
...@@ -21,11 +21,14 @@ export default { ...@@ -21,11 +21,14 @@ export default {
'allowLabelRemove', 'allowLabelRemove',
'allowScopedLabels', 'allowScopedLabels',
'labelsFilterBasePath', 'labelsFilterBasePath',
'labelsFilterParam',
]), ]),
}, },
methods: { methods: {
labelFilterUrl(label) { labelFilterUrl(label) {
return `${this.labelsFilterBasePath}?label_name[]=${encodeURIComponent(label.title)}`; return `${this.labelsFilterBasePath}?${this.labelsFilterParam}[]=${encodeURIComponent(
label.title,
)}`;
}, },
scopedLabel(label) { scopedLabel(label) {
return this.allowScopedLabels && isScopedLabel(label); return this.allowScopedLabels && isScopedLabel(label);
......
...@@ -81,6 +81,11 @@ export default { ...@@ -81,6 +81,11 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
labelsFilterParam: {
type: String,
required: false,
default: 'label_name',
},
dropdownButtonText: { dropdownButtonText: {
type: String, type: String,
required: false, required: false,
...@@ -156,6 +161,7 @@ export default { ...@@ -156,6 +161,7 @@ export default {
labelsFetchPath: this.labelsFetchPath, labelsFetchPath: this.labelsFetchPath,
labelsManagePath: this.labelsManagePath, labelsManagePath: this.labelsManagePath,
labelsFilterBasePath: this.labelsFilterBasePath, labelsFilterBasePath: this.labelsFilterBasePath,
labelsFilterParam: this.labelsFilterParam,
labelsListTitle: this.labelsListTitle, labelsListTitle: this.labelsListTitle,
labelsCreateTitle: this.labelsCreateTitle, labelsCreateTitle: this.labelsCreateTitle,
footerCreateLabelTitle: this.footerCreateLabelTitle, footerCreateLabelTitle: this.footerCreateLabelTitle,
......
<script> <script>
import { labelsFilterParam } from 'ee/integrations/jira/issues_show/constants';
import LabelsSelect from '~/vue_shared/components/sidebar/labels_select_vue/labels_select_root.vue'; import LabelsSelect from '~/vue_shared/components/sidebar/labels_select_vue/labels_select_root.vue';
import Assignee from './assignee.vue'; import Assignee from './assignee.vue';
import IssueReference from './issue_reference.vue'; import IssueReference from './issue_reference.vue';
...@@ -10,6 +12,11 @@ export default { ...@@ -10,6 +12,11 @@ export default {
IssueReference, IssueReference,
LabelsSelect, LabelsSelect,
}, },
inject: {
issuesListPath: {
default: null,
},
},
props: { props: {
sidebarExpanded: { sidebarExpanded: {
type: Boolean, type: Boolean,
...@@ -29,6 +36,7 @@ export default { ...@@ -29,6 +36,7 @@ export default {
return this.issue?.references?.relative; return this.issue?.references?.relative;
}, },
}, },
labelsFilterParam,
}; };
</script> </script>
...@@ -38,6 +46,8 @@ export default { ...@@ -38,6 +46,8 @@ export default {
<labels-select <labels-select
:selected-labels="issue.labels" :selected-labels="issue.labels"
:labels-filter-base-path="issuesListPath"
:labels-filter-param="$options.labelsFilterParam"
variant="sidebar" variant="sidebar"
class="block labels js-labels-block" class="block labels js-labels-block"
> >
......
...@@ -9,3 +9,5 @@ export const issueStateLabels = { ...@@ -9,3 +9,5 @@ export const issueStateLabels = {
[issueStates.OPENED]: __('Open'), [issueStates.OPENED]: __('Open'),
[issueStates.CLOSED]: __('Closed'), [issueStates.CLOSED]: __('Closed'),
}; };
export const labelsFilterParam = 'labels';
...@@ -9,12 +9,13 @@ export default function initJiraIssueShow({ mountPointSelector }) { ...@@ -9,12 +9,13 @@ export default function initJiraIssueShow({ mountPointSelector }) {
return null; return null;
} }
const { issuesShowPath } = mountPointEl.dataset; const { issuesShowPath, issuesListPath } = mountPointEl.dataset;
return new Vue({ return new Vue({
el: mountPointEl, el: mountPointEl,
provide: { provide: {
issuesShowPath, issuesShowPath,
issuesListPath,
}, },
render: (createElement) => createElement(JiraIssuesShowApp), render: (createElement) => createElement(JiraIssuesShowApp),
}); });
......
...@@ -53,7 +53,8 @@ module EE ...@@ -53,7 +53,8 @@ module EE
def jira_issues_show_data def jira_issues_show_data
{ {
issues_show_path: project_integrations_jira_issue_path(@project, params[:id], format: :json) issues_show_path: project_integrations_jira_issue_path(@project, params[:id], format: :json),
issues_list_path: project_integrations_jira_issues_path(@project)
} }
end end
end end
......
...@@ -11,32 +11,31 @@ import { mockConfig, mockRegularLabel, mockScopedLabel } from './mock_data'; ...@@ -11,32 +11,31 @@ import { mockConfig, mockRegularLabel, mockScopedLabel } from './mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
const createComponent = (initialState = mockConfig, slots = {}) => {
const store = new Vuex.Store(labelsSelectModule());
store.dispatch('setInitialState', initialState);
return shallowMount(DropdownValue, {
localVue,
store,
slots,
});
};
describe('DropdownValue', () => { describe('DropdownValue', () => {
let wrapper; let wrapper;
beforeEach(() => { const createComponent = (initialState = {}, slots = {}) => {
wrapper = createComponent(); const store = new Vuex.Store(labelsSelectModule());
});
store.dispatch('setInitialState', { ...mockConfig, ...initialState });
wrapper = shallowMount(DropdownValue, {
localVue,
store,
slots,
});
};
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
describe('methods', () => { describe('methods', () => {
describe('labelFilterUrl', () => { describe('labelFilterUrl', () => {
it('returns a label filter URL based on provided label param', () => { it('returns a label filter URL based on provided label param', () => {
createComponent();
expect(wrapper.vm.labelFilterUrl(mockRegularLabel)).toBe( expect(wrapper.vm.labelFilterUrl(mockRegularLabel)).toBe(
'/gitlab-org/my-project/issues?label_name[]=Foo%20Label', '/gitlab-org/my-project/issues?label_name[]=Foo%20Label',
); );
...@@ -44,6 +43,10 @@ describe('DropdownValue', () => { ...@@ -44,6 +43,10 @@ describe('DropdownValue', () => {
}); });
describe('scopedLabel', () => { describe('scopedLabel', () => {
beforeEach(() => {
createComponent();
});
it('returns `true` when provided label param is a scoped label', () => { it('returns `true` when provided label param is a scoped label', () => {
expect(wrapper.vm.scopedLabel(mockScopedLabel)).toBe(true); expect(wrapper.vm.scopedLabel(mockScopedLabel)).toBe(true);
}); });
...@@ -56,28 +59,29 @@ describe('DropdownValue', () => { ...@@ -56,28 +59,29 @@ describe('DropdownValue', () => {
describe('template', () => { describe('template', () => {
it('renders class `has-labels` on component container element when `selectedLabels` is not empty', () => { it('renders class `has-labels` on component container element when `selectedLabels` is not empty', () => {
createComponent();
expect(wrapper.attributes('class')).toContain('has-labels'); expect(wrapper.attributes('class')).toContain('has-labels');
}); });
it('renders element containing `None` when `selectedLabels` is empty', () => { it('renders element containing `None` when `selectedLabels` is empty', () => {
const wrapperNoLabels = createComponent( createComponent(
{ {
...mockConfig,
selectedLabels: [], selectedLabels: [],
}, },
{ {
default: 'None', default: 'None',
}, },
); );
const noneEl = wrapperNoLabels.find('span.text-secondary'); const noneEl = wrapper.find('span.text-secondary');
expect(noneEl.exists()).toBe(true); expect(noneEl.exists()).toBe(true);
expect(noneEl.text()).toBe('None'); expect(noneEl.text()).toBe('None');
wrapperNoLabels.destroy();
}); });
it('renders labels when `selectedLabels` is not empty', () => { it('renders labels when `selectedLabels` is not empty', () => {
createComponent();
expect(wrapper.findAll(GlLabel).length).toBe(2); expect(wrapper.findAll(GlLabel).length).toBe(2);
}); });
}); });
......
...@@ -47,6 +47,7 @@ export const mockConfig = { ...@@ -47,6 +47,7 @@ export const mockConfig = {
labelsFetchPath: '/gitlab-org/my-project/-/labels.json', labelsFetchPath: '/gitlab-org/my-project/-/labels.json',
labelsManagePath: '/gitlab-org/my-project/-/labels', labelsManagePath: '/gitlab-org/my-project/-/labels',
labelsFilterBasePath: '/gitlab-org/my-project/issues', labelsFilterBasePath: '/gitlab-org/my-project/issues',
labelsFilterParam: 'label_name',
}; };
export const mockSuggestedColors = { export const mockSuggestedColors = {
......
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