Commit a8d6f96c authored by Rajat Jain's avatar Rajat Jain Committed by Kushal Pandya

Epic tree bug fixes

parent a0412c79
---
title: Epic tree bug fixes
merge_request: 20209
author:
type: fixed
...@@ -15,7 +15,13 @@ export default { ...@@ -15,7 +15,13 @@ export default {
computed: { computed: {
removeButtonLabel() { removeButtonLabel() {
const { displayReference } = this; const { displayReference } = this;
return sprintf(__('Remove %{displayReference}'), { displayReference }); /*
* Giving false as third argument to prevent unescaping of ampersand in
* epic reference. Eg. &42 will remain &42 instead of &42
*
* https://docs.gitlab.com/ee/development/i18n/externalization.html#interpolation
*/
return sprintf(__('Remove %{displayReference}'), { displayReference }, false);
}, },
stateTitle() { stateTitle() {
if (this.isCondensed) return ''; if (this.isCondensed) return '';
......
...@@ -56,6 +56,7 @@ export default { ...@@ -56,6 +56,7 @@ export default {
return { return {
isInputFocused: false, isInputFocused: false,
isAutoCompleteOpen: false, isAutoCompleteOpen: false,
areEventsAssigned: false,
}; };
}, },
computed: { computed: {
...@@ -74,6 +75,9 @@ export default { ...@@ -74,6 +75,9 @@ export default {
this.$refs.input.focus(); this.$refs.input.focus();
} }
}, },
beforeUpdate() {
this.setupAutoComplete();
},
beforeDestroy() { beforeDestroy() {
const $input = $(this.$refs.input); const $input = $(this.$refs.input);
$input.off('shown-issues.atwho'); $input.off('shown-issues.atwho');
...@@ -116,7 +120,13 @@ export default { ...@@ -116,7 +120,13 @@ export default {
caretPos, caretPos,
}); });
}, },
onBlur() { onBlur(event) {
// Early exit if this Blur event is caused by card header
const container = this.$root.$el.querySelector('.js-button-container');
if (container && container.contains(event.relatedTarget)) {
return;
}
this.isInputFocused = false; this.isInputFocused = false;
// Avoid tokenizing partial input when clicking an autocomplete item // Avoid tokenizing partial input when clicking an autocomplete item
...@@ -139,8 +149,11 @@ export default { ...@@ -139,8 +149,11 @@ export default {
this.gfmAutoComplete.setup($input, this.autoCompleteOptions); this.gfmAutoComplete.setup($input, this.autoCompleteOptions);
} }
if (!this.areEventsAssigned) {
$input.on('shown-issues.atwho', this.onAutoCompleteToggled.bind(this, true)); $input.on('shown-issues.atwho', this.onAutoCompleteToggled.bind(this, true));
$input.on('hidden-issues.atwho', this.onAutoCompleteToggled.bind(this, true)); $input.on('hidden-issues.atwho', this.onAutoCompleteToggled.bind(this, true));
}
this.areEventsAssigned = true;
}, },
onIssuableFormWrapperClick() { onIssuableFormWrapperClick() {
this.$refs.input.focus(); this.$refs.input.focus();
......
...@@ -30,7 +30,7 @@ export default { ...@@ -30,7 +30,7 @@ export default {
}, },
}, },
methods: { methods: {
...mapActions(['toggleAddItemForm', 'toggleCreateEpicForm']), ...mapActions(['toggleAddItemForm', 'toggleCreateEpicForm', 'setItemInputValue']),
showAddEpicForm() { showAddEpicForm() {
this.toggleAddItemForm({ this.toggleAddItemForm({
issuableType: issuableTypesMap.EPIC, issuableType: issuableTypesMap.EPIC,
...@@ -38,6 +38,7 @@ export default { ...@@ -38,6 +38,7 @@ export default {
}); });
}, },
showAddIssueForm() { showAddIssueForm() {
this.setItemInputValue('');
this.toggleAddItemForm({ this.toggleAddItemForm({
issuableType: issuableTypesMap.ISSUE, issuableType: issuableTypesMap.ISSUE,
toggleState: true, toggleState: true,
...@@ -69,7 +70,7 @@ export default { ...@@ -69,7 +70,7 @@ export default {
</span> </span>
</div> </div>
</div> </div>
<div class="d-inline-flex"> <div class="d-inline-flex js-button-container">
<template v-if="parentItem.userPermissions.adminEpic"> <template v-if="parentItem.userPermissions.adminEpic">
<epic-actions-split-button <epic-actions-split-button
:class="headerItems[0].qaClass" :class="headerItems[0].qaClass"
......
...@@ -140,7 +140,8 @@ export default { ...@@ -140,7 +140,8 @@ export default {
}, },
[types.ADD_PENDING_REFERENCES](state, references) { [types.ADD_PENDING_REFERENCES](state, references) {
state.pendingReferences.push(...references); const nonDuplicateReferences = references.filter(ref => !state.pendingReferences.includes(ref));
state.pendingReferences.push(...nonDuplicateReferences);
}, },
[types.REMOVE_PENDING_REFERENCE](state, indexToRemove) { [types.REMOVE_PENDING_REFERENCE](state, indexToRemove) {
......
...@@ -123,19 +123,26 @@ describe('RelatedItemsTree', () => { ...@@ -123,19 +123,26 @@ describe('RelatedItemsTree', () => {
describe('click event', () => { describe('click event', () => {
let toggleAddItemForm; let toggleAddItemForm;
let setItemInputValue;
beforeEach(() => { beforeEach(() => {
setItemInputValue = jasmine.createSpy();
toggleAddItemForm = jasmine.createSpy(); toggleAddItemForm = jasmine.createSpy();
wrapper.vm.$store.hotUpdate({ wrapper.vm.$store.hotUpdate({
actions: { actions: {
setItemInputValue,
toggleAddItemForm, toggleAddItemForm,
}, },
}); });
}); });
it('dispatches toggleAddItemForm action', () => { it('dispatches setItemInputValue and toggleAddItemForm action', () => {
findAddIssuesButton().vm.$emit('click'); findAddIssuesButton().vm.$emit('click');
expect(setItemInputValue).toHaveBeenCalled();
expect(setItemInputValue.calls.mostRecent().args[1]).toEqual('');
expect(toggleAddItemForm).toHaveBeenCalled(); expect(toggleAddItemForm).toHaveBeenCalled();
const payload = toggleAddItemForm.calls.mostRecent().args[1]; const payload = toggleAddItemForm.calls.mostRecent().args[1];
......
...@@ -410,6 +410,16 @@ describe('RelatedItemsTree', () => { ...@@ -410,6 +410,16 @@ describe('RelatedItemsTree', () => {
expect.arrayContaining(['foo'].concat(reference)), expect.arrayContaining(['foo'].concat(reference)),
); );
}); });
it('should not add duplicated `references` param to `pendingReferences` within state', () => {
const references = ['foo', 'bar'];
state.pendingReferences = ['foo'];
mutations[types.ADD_PENDING_REFERENCES](state, references);
expect(state.pendingReferences).toEqual(['foo', 'bar']);
});
}); });
describe(types.REMOVE_PENDING_REFERENCE, () => { describe(types.REMOVE_PENDING_REFERENCE, () => {
......
...@@ -218,4 +218,24 @@ describe('IssueToken', () => { ...@@ -218,4 +218,24 @@ describe('IssueToken', () => {
expect(vm.$emit).toHaveBeenCalledWith('pendingIssuableRemoveRequest', vm.idKey); expect(vm.$emit).toHaveBeenCalledWith('pendingIssuableRemoveRequest', vm.idKey);
}); });
}); });
describe('tooltip', () => {
beforeEach(() => {
vm = new IssueToken({
propsData: {
idKey,
eventNamespace,
displayReference,
pathIdSeparator,
canRemove: true,
},
}).$mount();
});
it('should not be escaped', () => {
const { originalTitle } = vm.$refs.removeButton.dataset;
expect(originalTitle).toEqual(`Remove ${displayReference}`);
});
});
}); });
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