Commit c66d7b5d authored by Phil Hughes's avatar Phil Hughes

Merge branch 'cngo-limit-tribute-autocomplete-to-100' into 'master'

Limit tribute autocomplete menu items to 100

See merge request gitlab-org/gitlab!51694
parents 434987d1 a168e670
...@@ -9,6 +9,8 @@ const memberLimit = 10; ...@@ -9,6 +9,8 @@ const memberLimit = 10;
const nonWordOrInteger = /\W|^\d+$/; const nonWordOrInteger = /\W|^\d+$/;
export const menuItemLimit = 100;
export const GfmAutocompleteType = { export const GfmAutocompleteType = {
Emojis: 'emojis', Emojis: 'emojis',
Issues: 'issues', Issues: 'issues',
...@@ -31,6 +33,7 @@ export const tributeConfig = { ...@@ -31,6 +33,7 @@ export const tributeConfig = {
config: { config: {
trigger: ':', trigger: ':',
lookup: (value) => value, lookup: (value) => value,
menuItemLimit,
menuItemTemplate: ({ original }) => `${original} ${Emoji.glEmojiTag(original)}`, menuItemTemplate: ({ original }) => `${original} ${Emoji.glEmojiTag(original)}`,
selectTemplate: ({ original }) => `:${original}:`, selectTemplate: ({ original }) => `:${original}:`,
}, },
...@@ -40,6 +43,7 @@ export const tributeConfig = { ...@@ -40,6 +43,7 @@ export const tributeConfig = {
config: { config: {
trigger: '#', trigger: '#',
lookup: (value) => `${value.iid}${value.title}`, lookup: (value) => `${value.iid}${value.title}`,
menuItemLimit,
menuItemTemplate: ({ original }) => menuItemTemplate: ({ original }) =>
`<small>${original.reference || original.iid}</small> ${escape(original.title)}`, `<small>${original.reference || original.iid}</small> ${escape(original.title)}`,
selectTemplate: ({ original }) => original.reference || `#${original.iid}`, selectTemplate: ({ original }) => original.reference || `#${original.iid}`,
...@@ -50,6 +54,7 @@ export const tributeConfig = { ...@@ -50,6 +54,7 @@ export const tributeConfig = {
config: { config: {
trigger: '~', trigger: '~',
lookup: 'title', lookup: 'title',
menuItemLimit,
menuItemTemplate: ({ original }) => ` menuItemTemplate: ({ original }) => `
<span class="dropdown-label-box" style="background: ${escape(original.color)};"></span> <span class="dropdown-label-box" style="background: ${escape(original.color)};"></span>
${escape(original.title)}`, ${escape(original.title)}`,
...@@ -132,6 +137,7 @@ export const tributeConfig = { ...@@ -132,6 +137,7 @@ export const tributeConfig = {
config: { config: {
trigger: '!', trigger: '!',
lookup: (value) => `${value.iid}${value.title}`, lookup: (value) => `${value.iid}${value.title}`,
menuItemLimit,
menuItemTemplate: ({ original }) => menuItemTemplate: ({ original }) =>
`<small>${original.reference || original.iid}</small> ${escape(original.title)}`, `<small>${original.reference || original.iid}</small> ${escape(original.title)}`,
selectTemplate: ({ original }) => original.reference || `!${original.iid}`, selectTemplate: ({ original }) => original.reference || `!${original.iid}`,
...@@ -142,6 +148,7 @@ export const tributeConfig = { ...@@ -142,6 +148,7 @@ export const tributeConfig = {
config: { config: {
trigger: '%', trigger: '%',
lookup: 'title', lookup: 'title',
menuItemLimit,
menuItemTemplate: ({ original }) => escape(original.title), menuItemTemplate: ({ original }) => escape(original.title),
selectTemplate: ({ original }) => `%"${escape(original.title)}"`, selectTemplate: ({ original }) => `%"${escape(original.title)}"`,
}, },
...@@ -152,6 +159,7 @@ export const tributeConfig = { ...@@ -152,6 +159,7 @@ export const tributeConfig = {
trigger: '/', trigger: '/',
fillAttr: 'name', fillAttr: 'name',
lookup: (value) => `${value.name}${value.aliases.join()}`, lookup: (value) => `${value.name}${value.aliases.join()}`,
menuItemLimit,
menuItemTemplate: ({ original }) => { menuItemTemplate: ({ original }) => {
const aliases = original.aliases.length const aliases = original.aliases.length
? `<small>(or /${original.aliases.join(', /')})</small>` ? `<small>(or /${original.aliases.join(', /')})</small>`
...@@ -180,6 +188,7 @@ export const tributeConfig = { ...@@ -180,6 +188,7 @@ export const tributeConfig = {
trigger: '$', trigger: '$',
fillAttr: 'id', fillAttr: 'id',
lookup: (value) => `${value.id}${value.title}`, lookup: (value) => `${value.id}${value.title}`,
menuItemLimit,
menuItemTemplate: ({ original }) => `<small>${original.id}</small> ${escape(original.title)}`, menuItemTemplate: ({ original }) => `<small>${original.id}</small> ${escape(original.title)}`,
}, },
}, },
......
import { escape } from 'lodash'; import { escape } from 'lodash';
import { import {
GfmAutocompleteType as GfmAutocompleteTypeFoss, GfmAutocompleteType as GfmAutocompleteTypeFoss,
menuItemLimit,
tributeConfig as tributeConfigFoss, tributeConfig as tributeConfigFoss,
} from '~/vue_shared/components/gfm_autocomplete/utils'; } from '~/vue_shared/components/gfm_autocomplete/utils';
...@@ -17,6 +18,7 @@ export const tributeConfig = { ...@@ -17,6 +18,7 @@ export const tributeConfig = {
trigger: '&', trigger: '&',
fillAttr: 'iid', fillAttr: 'iid',
lookup: (value) => `${value.iid}${value.title}`, lookup: (value) => `${value.iid}${value.title}`,
menuItemLimit,
menuItemTemplate: ({ original }) => menuItemTemplate: ({ original }) =>
`<small>${original.iid}</small> ${escape(original.title)}`, `<small>${original.iid}</small> ${escape(original.title)}`,
}, },
......
...@@ -24,6 +24,10 @@ describe('ee gfm_autocomplete/utils', () => { ...@@ -24,6 +24,10 @@ describe('ee gfm_autocomplete/utils', () => {
expect(epicsConfig.lookup(epic)).toBe(`${epic.iid}${epic.title}`); expect(epicsConfig.lookup(epic)).toBe(`${epic.iid}${epic.title}`);
}); });
it('limits the number of rendered items to 100', () => {
expect(epicsConfig.menuItemLimit).toBe(100);
});
it('shows the iid and title in the menu item', () => { it('shows the iid and title in the menu item', () => {
expect(epicsConfig.menuItemTemplate({ original: epic })).toMatchSnapshot(); expect(epicsConfig.menuItemTemplate({ original: epic })).toMatchSnapshot();
}); });
......
...@@ -14,6 +14,10 @@ describe('gfm_autocomplete/utils', () => { ...@@ -14,6 +14,10 @@ describe('gfm_autocomplete/utils', () => {
expect(emojisConfig.lookup(emoji)).toBe(emoji); expect(emojisConfig.lookup(emoji)).toBe(emoji);
}); });
it('limits the number of rendered items to 100', () => {
expect(emojisConfig.menuItemLimit).toBe(100);
});
it('shows the emoji name and icon in the menu item', () => { it('shows the emoji name and icon in the menu item', () => {
expect(emojisConfig.menuItemTemplate({ original: emoji })).toMatchSnapshot(); expect(emojisConfig.menuItemTemplate({ original: emoji })).toMatchSnapshot();
}); });
...@@ -47,6 +51,10 @@ describe('gfm_autocomplete/utils', () => { ...@@ -47,6 +51,10 @@ describe('gfm_autocomplete/utils', () => {
); );
}); });
it('limits the number of rendered items to 100', () => {
expect(issuesConfig.menuItemLimit).toBe(100);
});
it('shows the reference and title in the menu item within a group context', () => { it('shows the reference and title in the menu item within a group context', () => {
expect(issuesConfig.menuItemTemplate({ original: groupContextIssue })).toMatchSnapshot(); expect(issuesConfig.menuItemTemplate({ original: groupContextIssue })).toMatchSnapshot();
}); });
...@@ -98,6 +106,10 @@ describe('gfm_autocomplete/utils', () => { ...@@ -98,6 +106,10 @@ describe('gfm_autocomplete/utils', () => {
expect(labelsConfig.lookup).toBe('title'); expect(labelsConfig.lookup).toBe('title');
}); });
it('limits the number of rendered items to 100', () => {
expect(labelsConfig.menuItemLimit).toBe(100);
});
it('shows the title in the menu item', () => { it('shows the title in the menu item', () => {
expect(labelsConfig.menuItemTemplate({ original: label })).toMatchSnapshot(); expect(labelsConfig.menuItemTemplate({ original: label })).toMatchSnapshot();
}); });
...@@ -291,6 +303,10 @@ describe('gfm_autocomplete/utils', () => { ...@@ -291,6 +303,10 @@ describe('gfm_autocomplete/utils', () => {
); );
}); });
it('limits the number of rendered items to 100', () => {
expect(mergeRequestsConfig.menuItemLimit).toBe(100);
});
it('shows the reference and title in the menu item within a group context', () => { it('shows the reference and title in the menu item within a group context', () => {
expect( expect(
mergeRequestsConfig.menuItemTemplate({ original: groupContextMergeRequest }), mergeRequestsConfig.menuItemTemplate({ original: groupContextMergeRequest }),
...@@ -332,6 +348,10 @@ describe('gfm_autocomplete/utils', () => { ...@@ -332,6 +348,10 @@ describe('gfm_autocomplete/utils', () => {
expect(milestonesConfig.lookup).toBe('title'); expect(milestonesConfig.lookup).toBe('title');
}); });
it('limits the number of rendered items to 100', () => {
expect(milestonesConfig.menuItemLimit).toBe(100);
});
it('shows the title in the menu item', () => { it('shows the title in the menu item', () => {
expect(milestonesConfig.menuItemTemplate({ original: milestone })).toMatchSnapshot(); expect(milestonesConfig.menuItemTemplate({ original: milestone })).toMatchSnapshot();
}); });
...@@ -368,6 +388,10 @@ describe('gfm_autocomplete/utils', () => { ...@@ -368,6 +388,10 @@ describe('gfm_autocomplete/utils', () => {
); );
}); });
it('limits the number of rendered items to 100', () => {
expect(quickActionsConfig.menuItemLimit).toBe(100);
});
it('shows the name, aliases, params and description in the menu item', () => { it('shows the name, aliases, params and description in the menu item', () => {
expect(quickActionsConfig.menuItemTemplate({ original: quickAction })).toMatchSnapshot(); expect(quickActionsConfig.menuItemTemplate({ original: quickAction })).toMatchSnapshot();
}); });
...@@ -392,6 +416,10 @@ describe('gfm_autocomplete/utils', () => { ...@@ -392,6 +416,10 @@ describe('gfm_autocomplete/utils', () => {
expect(snippetsConfig.lookup(snippet)).toBe(`${snippet.id}${snippet.title}`); expect(snippetsConfig.lookup(snippet)).toBe(`${snippet.id}${snippet.title}`);
}); });
it('limits the number of rendered items to 100', () => {
expect(snippetsConfig.menuItemLimit).toBe(100);
});
it('shows the id and title in the menu item', () => { it('shows the id and title in the menu item', () => {
expect(snippetsConfig.menuItemTemplate({ original: snippet })).toMatchSnapshot(); expect(snippetsConfig.menuItemTemplate({ original: snippet })).toMatchSnapshot();
}); });
......
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