Commit db755a1d authored by Kushal Pandya's avatar Kushal Pandya

Merge branch...

Merge branch '333213-allow-searching-for-epics-within-the-issue-sidebar-by-epic-reference' into 'master'

Search for epics by iid if search starts with &

See merge request gitlab-org/gitlab!65249
parents b3ebb541 5522a5ff
...@@ -22,6 +22,7 @@ import { ...@@ -22,6 +22,7 @@ import {
issuableAttributesQueries, issuableAttributesQueries,
noAttributeId, noAttributeId,
defaultEpicSort, defaultEpicSort,
epicIidPattern,
} from '~/sidebar/constants'; } from '~/sidebar/constants';
export default { export default {
...@@ -118,17 +119,37 @@ export default { ...@@ -118,17 +119,37 @@ export default {
return query; return query;
}, },
skip() { skip() {
if (this.isEpic && this.searchTerm.startsWith('&') && this.searchTerm.length < 2) {
return true;
}
return !this.editing; return !this.editing;
}, },
debounce: 250, debounce: 250,
variables() { variables() {
return { if (!this.isEpic) {
return {
fullPath: this.attrWorkspacePath,
title: this.searchTerm,
state: this.$options.IssuableAttributeState[this.issuableAttribute],
};
}
const variables = {
fullPath: this.attrWorkspacePath, fullPath: this.attrWorkspacePath,
title: this.searchTerm,
in: this.searchTerm && this.issuableAttribute === IssuableType.Epic ? 'TITLE' : undefined,
state: this.$options.IssuableAttributeState[this.issuableAttribute], state: this.$options.IssuableAttributeState[this.issuableAttribute],
sort: this.issuableAttribute === IssuableType.Epic ? defaultEpicSort : null, sort: defaultEpicSort,
}; };
if (epicIidPattern.test(this.searchTerm)) {
const matches = this.searchTerm.match(epicIidPattern);
variables.iidStartsWith = matches.groups.iid;
} else if (this.searchTerm !== '') {
variables.in = 'TITLE';
variables.title = this.searchTerm;
}
return variables;
}, },
update(data) { update(data) {
if (data?.workspace) { if (data?.workspace) {
...@@ -214,6 +235,9 @@ export default { ...@@ -214,6 +235,9 @@ export default {
), ),
}; };
}, },
isEpic() {
return this.issuableAttribute === IssuableType.Epic;
},
}, },
methods: { methods: {
updateAttribute(attributeId) { updateAttribute(attributeId) {
......
...@@ -48,6 +48,8 @@ export const ASSIGNEES_DEBOUNCE_DELAY = DEFAULT_DEBOUNCE_AND_THROTTLE_MS; ...@@ -48,6 +48,8 @@ export const ASSIGNEES_DEBOUNCE_DELAY = DEFAULT_DEBOUNCE_AND_THROTTLE_MS;
export const defaultEpicSort = 'TITLE_ASC'; export const defaultEpicSort = 'TITLE_ASC';
export const epicIidPattern = /^&(?<iid>\d+)$/;
export const assigneesQueries = { export const assigneesQueries = {
[IssuableType.Issue]: { [IssuableType.Issue]: {
query: getIssueAssignees, query: getIssueAssignees,
......
...@@ -5,6 +5,7 @@ query issueEpics( ...@@ -5,6 +5,7 @@ query issueEpics(
$title: String $title: String
$state: EpicState $state: EpicState
$in: [IssuableSearchableField!] $in: [IssuableSearchableField!]
$iidStartsWith: String
) { ) {
workspace: group(fullPath: $fullPath) { workspace: group(fullPath: $fullPath) {
attributes: epics( attributes: epics(
...@@ -13,6 +14,7 @@ query issueEpics( ...@@ -13,6 +14,7 @@ query issueEpics(
state: $state state: $state
includeAncestorGroups: true includeAncestorGroups: true
includeDescendantGroups: false includeDescendantGroups: false
iidStartsWith: $iidStartsWith
) { ) {
nodes { nodes {
...EpicFragment ...EpicFragment
......
...@@ -452,7 +452,6 @@ describe('SidebarDropdownWidget', () => { ...@@ -452,7 +452,6 @@ describe('SidebarDropdownWidget', () => {
fullPath: mockIssue.groupPath, fullPath: mockIssue.groupPath,
sort: 'TITLE_ASC', sort: 'TITLE_ASC',
state: 'opened', state: 'opened',
title: '',
}); });
}); });
...@@ -501,8 +500,21 @@ describe('SidebarDropdownWidget', () => { ...@@ -501,8 +500,21 @@ describe('SidebarDropdownWidget', () => {
fullPath: mockIssue.groupPath, fullPath: mockIssue.groupPath,
sort: 'TITLE_ASC', sort: 'TITLE_ASC',
state: 'opened', state: 'opened',
title: '', });
in: undefined, });
it('sends a groupEpics query for an IID with the entered search term "&1"', async () => {
findSearchBox().vm.$emit('input', '&1');
await wrapper.vm.$nextTick();
// Account for debouncing
jest.runAllTimers();
expect(groupEpicsSpy).toHaveBeenNthCalledWith(2, {
fullPath: mockIssue.groupPath,
iidStartsWith: '1',
sort: 'TITLE_ASC',
state: 'opened',
}); });
}); });
}); });
......
...@@ -451,7 +451,6 @@ describe('SidebarDropdownWidget', () => { ...@@ -451,7 +451,6 @@ describe('SidebarDropdownWidget', () => {
expect(projectMilestonesSpy).toHaveBeenNthCalledWith(1, { expect(projectMilestonesSpy).toHaveBeenNthCalledWith(1, {
fullPath: mockIssue.projectPath, fullPath: mockIssue.projectPath,
sort: null,
state: 'active', state: 'active',
title: '', title: '',
}); });
...@@ -478,7 +477,6 @@ describe('SidebarDropdownWidget', () => { ...@@ -478,7 +477,6 @@ describe('SidebarDropdownWidget', () => {
expect(projectMilestonesSpy).toHaveBeenNthCalledWith(2, { expect(projectMilestonesSpy).toHaveBeenNthCalledWith(2, {
fullPath: mockIssue.projectPath, fullPath: mockIssue.projectPath,
sort: null,
state: 'active', state: 'active',
title: mockSearchTerm, title: mockSearchTerm,
}); });
......
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