@gitlab/ui 68.2.1 → 68.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Fri, 10 Nov 2023 15:49:52 GMT
3
+ * Generated on Fri, 10 Nov 2023 17:20:59 GMT
4
4
  */
5
5
 
6
6
  :root {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Fri, 10 Nov 2023 15:49:52 GMT
3
+ * Generated on Fri, 10 Nov 2023 17:20:59 GMT
4
4
  */
5
5
 
6
6
  :root.gl-dark {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Fri, 10 Nov 2023 15:49:52 GMT
3
+ * Generated on Fri, 10 Nov 2023 17:20:59 GMT
4
4
  */
5
5
 
6
6
  export const BLACK = "#fff";
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Fri, 10 Nov 2023 15:49:52 GMT
3
+ * Generated on Fri, 10 Nov 2023 17:20:59 GMT
4
4
  */
5
5
 
6
6
  export const BLACK = "#000";
@@ -1,6 +1,6 @@
1
1
 
2
2
  // Do not edit directly
3
- // Generated on Fri, 10 Nov 2023 15:49:52 GMT
3
+ // Generated on Fri, 10 Nov 2023 17:20:59 GMT
4
4
 
5
5
  $red-950: #fff4f3;
6
6
  $red-900: #fcf1ef;
@@ -1,6 +1,6 @@
1
1
 
2
2
  // Do not edit directly
3
- // Generated on Fri, 10 Nov 2023 15:49:52 GMT
3
+ // Generated on Fri, 10 Nov 2023 17:20:59 GMT
4
4
 
5
5
  $gl-line-height-52: 3.25rem;
6
6
  $gl-line-height-44: 2.75rem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "68.2.1",
3
+ "version": "68.3.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -55,3 +55,22 @@
55
55
  @include gl-py-4;
56
56
  }
57
57
  }
58
+
59
+ .slash-commands {
60
+ @include gl-mt-n2;
61
+
62
+ .active-command{
63
+ @include gl-bg-gray-50;
64
+ @include gl-rounded-base;
65
+ }
66
+
67
+ .gl-dropdown-item button.dropdown-item {
68
+ @include gl-font-sm;
69
+ @include gl-px-3;
70
+ @include gl-bg-none;
71
+
72
+ &:hover {
73
+ @include gl-bg-none;
74
+ }
75
+ }
76
+ }
@@ -2,13 +2,23 @@ import { nextTick } from 'vue';
2
2
  import { shallowMount } from '@vue/test-utils';
3
3
  import GlEmptyState from '../../../regions/empty_state/empty_state.vue';
4
4
  import GlExperimentBadge from '../../experiment_badge/experiment_badge.vue';
5
+ import GlCard from '../../../base/card/card.vue';
6
+ import GlDropdownItem from '../../../base/dropdown/dropdown_item.vue';
5
7
  import DuoChatLoader from './components/duo_chat_loader/duo_chat_loader.vue';
6
8
  import DuoChatPredefinedPrompts from './components/duo_chat_predefined_prompts/duo_chat_predefined_prompts.vue';
7
9
  import DuoChatConversation from './components/duo_chat_conversation/duo_chat_conversation.vue';
8
- import GlDuoChat from './duo_chat.vue';
10
+ import GlDuoChat, { slashCommands } from './duo_chat.vue';
9
11
 
10
12
  import { MESSAGE_MODEL_ROLES, CHAT_RESET_MESSAGE } from './constants';
11
13
 
14
+ const generatePartialSlashCommands = () => {
15
+ const res = [];
16
+ slashCommands.forEach((command) => {
17
+ res.push(command.name.slice(0, command.name.length - 1));
18
+ });
19
+ return res;
20
+ };
21
+
12
22
  describe('GlDuoChat', () => {
13
23
  let wrapper;
14
24
 
@@ -43,6 +53,9 @@ describe('GlDuoChat', () => {
43
53
  const findChatInput = () => wrapper.find('[data-testid="chat-prompt-input"]');
44
54
  const findCloseChatButton = () => wrapper.find('[data-testid="chat-close-button"]');
45
55
  const findLegalDisclaimer = () => wrapper.find('[data-testid="chat-legal-disclaimer"]');
56
+ const findSlashCommandsCard = () => wrapper.findComponent(GlCard);
57
+ const findSlashCommands = () => wrapper.findAllComponents(GlDropdownItem);
58
+ const findSelectedSlashCommand = () => wrapper.find('.active-command');
46
59
 
47
60
  beforeEach(() => {
48
61
  createComponent();
@@ -207,13 +220,13 @@ describe('GlDuoChat', () => {
207
220
  const ENTER = 'Enter';
208
221
 
209
222
  it.each`
210
- trigger | event | action | expectEmitted
211
- ${() => clickSubmit()} | ${'Submit button click'} | ${'submit'} | ${[[promptStr]]}
212
- ${() => findChatInput().trigger('keydown.enter', { code: ENTER })} | ${`Clicking ${ENTER}`} | ${'submit'} | ${[[promptStr]]}
213
- ${() => findChatInput().trigger('keydown.enter', { code: ENTER, metaKey: true })} | ${`Clicking ${ENTER} + ⌘`} | ${'not submit'} | ${undefined}
214
- ${() => findChatInput().trigger('keydown.enter', { code: ENTER, altKey: true })} | ${`Clicking ${ENTER} + ⎇`} | ${'not submit'} | ${undefined}
215
- ${() => findChatInput().trigger('keydown.enter', { code: ENTER, shiftKey: true })} | ${`Clicking ${ENTER} + ⬆︎`} | ${'not submit'} | ${undefined}
216
- ${() => findChatInput().trigger('keydown.enter', { code: ENTER, ctrlKey: true })} | ${`Clicking ${ENTER} + CTRL`} | ${'not submit'} | ${undefined}
223
+ trigger | event | action | expectEmitted
224
+ ${() => clickSubmit()} | ${'Submit button click'} | ${'submit'} | ${[[promptStr]]}
225
+ ${() => findChatInput().trigger('keyup', { key: ENTER })} | ${`Clicking ${ENTER}`} | ${'submit'} | ${[[promptStr]]}
226
+ ${() => findChatInput().trigger('keyup', { key: ENTER, metaKey: true })} | ${`Clicking ${ENTER} + ⌘`} | ${'not submit'} | ${undefined}
227
+ ${() => findChatInput().trigger('keyup', { key: ENTER, altKey: true })} | ${`Clicking ${ENTER} + ⎇`} | ${'not submit'} | ${undefined}
228
+ ${() => findChatInput().trigger('keyup', { key: ENTER, shiftKey: true })} | ${`Clicking ${ENTER} + ⬆︎`} | ${'not submit'} | ${undefined}
229
+ ${() => findChatInput().trigger('keyup', { key: ENTER, ctrlKey: true })} | ${`Clicking ${ENTER} + CTRL`} | ${'not submit'} | ${undefined}
217
230
  `('$event should $action the prompt form', ({ trigger, expectEmitted } = {}) => {
218
231
  createComponent({
219
232
  propsData: { messages: [], isChatAvailable: true },
@@ -401,4 +414,288 @@ describe('GlDuoChat', () => {
401
414
  });
402
415
  });
403
416
  });
417
+
418
+ describe('slash commands', () => {
419
+ const slashCommandsNames = slashCommands.map((command) => command.name);
420
+ const slashCommandsOnly = (commands = []) =>
421
+ slashCommandsNames.filter((name) => commands.includes(name));
422
+
423
+ describe('rendering', () => {
424
+ describe('without the `withSlashCommands` enabled', () => {
425
+ it('does not render slash commands by default', () => {
426
+ createComponent({
427
+ propsData: {
428
+ withSlashCommands: false,
429
+ },
430
+ });
431
+ expect(findSlashCommandsCard().exists()).toBe(false);
432
+ });
433
+
434
+ it('does not render slash commands when prompt is "/"', async () => {
435
+ createComponent({
436
+ propsData: {
437
+ withSlashCommands: false,
438
+ },
439
+ data: {
440
+ prompt: '/',
441
+ },
442
+ });
443
+
444
+ await nextTick();
445
+ expect(findSlashCommandsCard().exists()).toBe(false);
446
+ });
447
+ });
448
+
449
+ describe('with the `withSlashCommands` enabled', () => {
450
+ it('does not render slash commands by default', async () => {
451
+ createComponent({
452
+ propsData: {
453
+ withSlashCommands: true,
454
+ },
455
+ });
456
+
457
+ await nextTick();
458
+ expect(findSlashCommandsCard().exists()).toBe(false);
459
+ });
460
+
461
+ it('renders all slash commands when prompt is "/"', async () => {
462
+ createComponent({
463
+ propsData: {
464
+ withSlashCommands: true,
465
+ },
466
+ data: {
467
+ prompt: '/',
468
+ },
469
+ });
470
+
471
+ await nextTick();
472
+ expect(findSlashCommandsCard().exists()).toBe(true);
473
+ expect(findSlashCommands()).toHaveLength(slashCommands.length);
474
+
475
+ slashCommands.forEach((command, index) => {
476
+ expect(findSlashCommands().at(index).text()).toContain(command.name);
477
+ expect(findSlashCommands().at(index).text()).toContain(command.description);
478
+ });
479
+ });
480
+
481
+ describe('when the prompt includes the "/" character or no characters', () => {
482
+ it.each(['', '//', '\\', 'foo', '/foo'])(
483
+ 'does not render the slash commands if prompt is "$prompt"',
484
+ async (prompt) => {
485
+ createComponent({
486
+ propsData: {
487
+ withSlashCommands: true,
488
+ },
489
+ data: {
490
+ prompt,
491
+ },
492
+ });
493
+
494
+ await nextTick();
495
+ expect(findSlashCommandsCard().exists()).toBe(false);
496
+ }
497
+ );
498
+ });
499
+
500
+ describe('when prompt presents a partial match to an existing slash command', () => {
501
+ it.each(generatePartialSlashCommands())(
502
+ 'renders the slash commands when prompt is "%s" and is a partial match',
503
+ async (prompt) => {
504
+ createComponent({
505
+ propsData: {
506
+ withSlashCommands: true,
507
+ },
508
+ data: {
509
+ prompt,
510
+ },
511
+ });
512
+
513
+ await nextTick();
514
+ expect(findSlashCommandsCard().exists()).toBe(true);
515
+ }
516
+ );
517
+ });
518
+
519
+ describe('when the prompt matches a complete slash command', () => {
520
+ it.each(slashCommands.map((command) => command.name))(
521
+ 'does not render the slash commands when prompt is "%s"',
522
+ async (prompt) => {
523
+ createComponent({
524
+ propsData: {
525
+ withSlashCommands: true,
526
+ },
527
+ data: {
528
+ prompt,
529
+ },
530
+ });
531
+
532
+ await nextTick();
533
+ expect(findSlashCommandsCard().exists()).toBe(false);
534
+ }
535
+ );
536
+ });
537
+ });
538
+ });
539
+
540
+ describe('interaction', () => {
541
+ describe('filtering when user types in partial slash command', () => {
542
+ it.each`
543
+ prompt | expectedCommands
544
+ ${'/'} | ${slashCommandsNames}
545
+ ${'/t'} | ${slashCommandsOnly(['/test'])}
546
+ ${'/tes'} | ${slashCommandsOnly(['/test'])}
547
+ ${'/e'} | ${slashCommandsOnly(['/explain'])}
548
+ ${'/explai'} | ${slashCommandsOnly(['/explain'])}
549
+ ${'/r'} | ${slashCommandsOnly(['/reset', '/refactor'])}
550
+ ${'/re'} | ${slashCommandsOnly(['/reset', '/refactor'])}
551
+ ${'/res'} | ${slashCommandsOnly(['/reset'])}
552
+ ${'/ref'} | ${slashCommandsOnly(['/refactor'])}
553
+ ${'/foo'} | ${[]}
554
+ `(
555
+ 'shows $expectedCommands when prompt is $prompt',
556
+ async ({ prompt, expectedCommands } = {}) => {
557
+ createComponent({
558
+ propsData: {
559
+ withSlashCommands: true,
560
+ },
561
+ data: {
562
+ prompt,
563
+ },
564
+ });
565
+
566
+ await nextTick();
567
+ expect(findSlashCommands()).toHaveLength(expectedCommands.length);
568
+ expectedCommands.forEach((command) => {
569
+ expect(findSlashCommandsCard().text()).toContain(command);
570
+ });
571
+ }
572
+ );
573
+ });
574
+
575
+ describe('keyboard navigation', () => {
576
+ beforeEach(() => {
577
+ createComponent({
578
+ propsData: {
579
+ withSlashCommands: true,
580
+ messages,
581
+ },
582
+ data: {
583
+ prompt: '/',
584
+ },
585
+ });
586
+ });
587
+
588
+ it('toggles through commands on ArrowDown', async () => {
589
+ for (const command of slashCommandsNames) {
590
+ expect(findSelectedSlashCommand().text()).toContain(command);
591
+ findChatInput().trigger('keyup', { key: 'ArrowDown' });
592
+ // eslint-disable-next-line no-await-in-loop
593
+ await nextTick();
594
+ }
595
+ });
596
+
597
+ it('toggles through commands on ArrowUp', async () => {
598
+ const arr = [...slashCommandsNames].reverse();
599
+ arr.unshift(slashCommandsNames[0]); // it still has the top most command selected on the first run
600
+ for (const command of arr) {
601
+ expect(findSelectedSlashCommand().text()).toContain(command);
602
+ findChatInput().trigger('keyup', { key: 'ArrowUp' });
603
+ // eslint-disable-next-line no-await-in-loop
604
+ await nextTick();
605
+ }
606
+ });
607
+
608
+ describe('on Enter', () => {
609
+ const navigateToCommand = async (index) => {
610
+ const command = slashCommandsNames[index];
611
+ if (index) {
612
+ for (let i = 0; i < index; i += 1) {
613
+ findChatInput().trigger('keyup', { key: 'ArrowDown' });
614
+ }
615
+ }
616
+ await nextTick();
617
+ return command;
618
+ };
619
+
620
+ it('selects correct command and updates input if command should not submit right away', async () => {
621
+ const commandIndex = slashCommands.findIndex((cmd) => !cmd.shouldSubmit);
622
+ const command = await navigateToCommand(commandIndex);
623
+
624
+ expect(findSelectedSlashCommand().text()).toContain(command);
625
+ findChatInput().trigger('keyup', { key: 'Enter' });
626
+ await nextTick();
627
+ expect(findChatInput().props('value')).toBe(`${command} `);
628
+ expect(wrapper.emitted('send-chat-prompt')).toBe(undefined);
629
+ });
630
+
631
+ it('selects correct command and submits the prompt if command should submit right away', async () => {
632
+ const commandIndex = slashCommands.findIndex((cmd) => cmd.shouldSubmit);
633
+ const command = await navigateToCommand(commandIndex);
634
+
635
+ expect(findSelectedSlashCommand().text()).toContain(command);
636
+ findChatInput().trigger('keyup', { key: 'Enter' });
637
+ await nextTick();
638
+ expect(findChatInput().props('value')).toBe(`${command}`);
639
+ expect(wrapper.emitted('send-chat-prompt')).toEqual([[command]]);
640
+ });
641
+ });
642
+ });
643
+
644
+ describe('mouse navigation', () => {
645
+ beforeEach(() => {
646
+ createComponent({
647
+ propsData: {
648
+ withSlashCommands: true,
649
+ messages,
650
+ },
651
+ data: {
652
+ prompt: '/',
653
+ },
654
+ });
655
+ });
656
+
657
+ it('updates the selected command when hovering over it', async () => {
658
+ expect(findSelectedSlashCommand().text()).toContain(slashCommandsNames[0]);
659
+ findSlashCommands().at(2).trigger('mouseenter');
660
+ await nextTick();
661
+ expect(findSelectedSlashCommand().text()).toContain(slashCommandsNames[2]);
662
+ expect(findSelectedSlashCommand().text()).not.toContain(slashCommandsNames[0]);
663
+ });
664
+
665
+ describe('click', () => {
666
+ it('selects correct command and updates input if command should not submit right away', async () => {
667
+ const commandIndex = slashCommands.findIndex((cmd) => !cmd.shouldSubmit);
668
+
669
+ findSlashCommands().at(commandIndex).trigger('mouseenter');
670
+ await nextTick();
671
+
672
+ expect(findSelectedSlashCommand().text()).toContain(slashCommandsNames[commandIndex]);
673
+
674
+ findSelectedSlashCommand().vm.$emit('click');
675
+ await nextTick();
676
+
677
+ expect(findChatInput().props('value')).toBe(`${slashCommandsNames[commandIndex]} `);
678
+ expect(wrapper.emitted('send-chat-prompt')).toBe(undefined);
679
+ });
680
+
681
+ it('selects correct command and submits the prompt if command should submit right away', async () => {
682
+ const commandIndex = slashCommands.findIndex((cmd) => cmd.shouldSubmit);
683
+
684
+ findSlashCommands().at(commandIndex).trigger('mouseenter');
685
+ await nextTick();
686
+
687
+ expect(findSelectedSlashCommand().text()).toContain(slashCommandsNames[commandIndex]);
688
+
689
+ findSelectedSlashCommand().vm.$emit('click');
690
+ await nextTick();
691
+
692
+ expect(findChatInput().props('value')).toBe(slashCommandsNames[commandIndex]);
693
+ expect(wrapper.emitted('send-chat-prompt')).toEqual([
694
+ [slashCommandsNames[commandIndex]],
695
+ ]);
696
+ });
697
+ });
698
+ });
699
+ });
700
+ });
404
701
  });
@@ -27,6 +27,7 @@ const generateProps = ({
27
27
  badgeHelpPageUrl = defaultValue('badgeHelpPageUrl'),
28
28
  badgeType = defaultValue('badgeType'),
29
29
  toolName = defaultValue('toolName'),
30
+ withSlashCommands = defaultValue('withSlashCommands'),
30
31
  } = {}) => ({
31
32
  title,
32
33
  messages,
@@ -37,6 +38,7 @@ const generateProps = ({
37
38
  badgeHelpPageUrl,
38
39
  badgeType,
39
40
  toolName,
41
+ withSlashCommands,
40
42
  });
41
43
 
42
44
  export const Default = (args, { argTypes }) => ({
@@ -57,6 +59,7 @@ export const Default = (args, { argTypes }) => ({
57
59
  :badge-help-page-url="badgeHelpPageUrl"
58
60
  :badge-type="badgeType"
59
61
  :tool-name="toolName"
62
+ :with-slash-commands="withSlashCommands"
60
63
  />`,
61
64
  });
62
65
  Default.args = generateProps({
@@ -151,6 +154,7 @@ export const Interactive = (args, { argTypes }) => ({
151
154
  :badge-help-page-url="badgeHelpPageUrl"
152
155
  :badge-type="badgeType"
153
156
  :tool-name="toolName"
157
+ :with-slash-commands="withSlashCommands"
154
158
  @send-chat-prompt="onSendChatPrompt"
155
159
  @chat-hidden="onChatHidden"
156
160
  />
@@ -176,7 +180,8 @@ export const Slots = (args, { argTypes }) => ({
176
180
  :predefined-prompts="predefinedPrompts"
177
181
  :badge-help-page-url="badgeHelpPageUrl"
178
182
  :badge-type="badgeType"
179
- :tool-name="toolName">
183
+ :tool-name="toolName"
184
+ :with-slash-commands="withSlashCommands">
180
185
 
181
186
  <template #hero>
182
187
  <pre class="code-block rounded code highlight gl-border-b gl-rounded-0! gl-mb-0 gl-overflow-y-auto solarized-light" style="max-height: 20rem; overflow-y: auto;">
@@ -1,6 +1,8 @@
1
1
  <script>
2
2
  import throttle from 'lodash/throttle';
3
3
  import emptySvg from '@gitlab/svgs/dist/illustrations/empty-state/empty-activity-md.svg';
4
+ import GlDropdownItem from '../../../base/dropdown/dropdown_item.vue';
5
+ import GlCard from '../../../base/card/card.vue';
4
6
  import GlEmptyState from '../../../regions/empty_state/empty_state.vue';
5
7
  import GlButton from '../../../base/button/button.vue';
6
8
  import GlAlert from '../../../base/alert/alert.vue';
@@ -34,6 +36,29 @@ export const i18n = {
34
36
  ],
35
37
  };
36
38
 
39
+ export const slashCommands = [
40
+ {
41
+ name: '/reset',
42
+ shouldSubmit: true,
43
+ description: 'Reset conversation, ignore the previous messages.',
44
+ },
45
+ {
46
+ name: '/test',
47
+ shouldSubmit: false,
48
+ description: 'Write tests for the code snippet.',
49
+ },
50
+ {
51
+ name: '/refactor',
52
+ shouldSubmit: false,
53
+ description: 'Refactor the code snippet.',
54
+ },
55
+ {
56
+ name: '/explain',
57
+ shouldSubmit: false,
58
+ description: 'Explain the code snippet.',
59
+ },
60
+ ];
61
+
37
62
  const isMessage = (item) => Boolean(item) && item?.role;
38
63
 
39
64
  const itemsValidator = (items) => items.every(isMessage);
@@ -52,6 +77,8 @@ export default {
52
77
  GlDuoChatLoader,
53
78
  GlDuoChatPredefinedPrompts,
54
79
  GlDuoChatConversation,
80
+ GlCard,
81
+ GlDropdownItem,
55
82
  },
56
83
  directives: {
57
84
  SafeHtml,
@@ -131,12 +158,21 @@ export default {
131
158
  required: false,
132
159
  default: i18n.CHAT_DEFAULT_TITLE,
133
160
  },
161
+ /**
162
+ * Whether the slash commands should be available to user when typing the prompt.
163
+ */
164
+ withSlashCommands: {
165
+ type: Boolean,
166
+ required: false,
167
+ default: false,
168
+ },
134
169
  },
135
170
  data() {
136
171
  return {
137
172
  isHidden: false,
138
173
  prompt: '',
139
174
  scrolledToBottom: true,
175
+ activeCommandIndex: 0,
140
176
  };
141
177
  },
142
178
  computed: {
@@ -166,6 +202,19 @@ export default {
166
202
  const lastMessage = this.messages[this.messages.length - 1];
167
203
  return lastMessage.content === CHAT_RESET_MESSAGE;
168
204
  },
205
+ filteredSlashCommands() {
206
+ const caseInsensitivePrompt = this.prompt.toLowerCase();
207
+ return slashCommands.filter((c) => c.name.toLowerCase().startsWith(caseInsensitivePrompt));
208
+ },
209
+ shouldShowSlashCommands() {
210
+ if (!this.withSlashCommands) return false;
211
+ const caseInsensitivePrompt = this.prompt.toLowerCase();
212
+ const startsWithSlash = caseInsensitivePrompt.startsWith('/');
213
+ const startsWithSlashCommand = slashCommands.some((c) =>
214
+ caseInsensitivePrompt.startsWith(c.name)
215
+ );
216
+ return startsWithSlash && this.filteredSlashCommands.length && !startsWithSlashCommand;
217
+ },
169
218
  },
170
219
  watch: {
171
220
  isLoading() {
@@ -225,6 +274,51 @@ export default {
225
274
  */
226
275
  this.$emit('track-feedback', event);
227
276
  },
277
+ onInputKeyup(e) {
278
+ const { metaKey, ctrlKey, altKey, shiftKey } = e;
279
+
280
+ if (this.shouldShowSlashCommands) {
281
+ e.preventDefault();
282
+
283
+ if (e.key === 'Enter') {
284
+ this.selectSlashCommand(this.activeCommandIndex);
285
+ } else if (e.key === 'ArrowUp') {
286
+ this.prevCommand();
287
+ } else if (e.key === 'ArrowDown') {
288
+ this.nextCommand();
289
+ } else {
290
+ this.activeCommandIndex = 0;
291
+ }
292
+ } else if (e.key === 'Enter' && !(metaKey || ctrlKey || altKey || shiftKey)) {
293
+ e.preventDefault();
294
+ this.sendChatPrompt();
295
+ }
296
+ },
297
+ prevCommand() {
298
+ this.activeCommandIndex -= 1;
299
+ this.wrapCommandIndex();
300
+ },
301
+ nextCommand() {
302
+ this.activeCommandIndex += 1;
303
+ this.wrapCommandIndex();
304
+ },
305
+ wrapCommandIndex() {
306
+ if (this.activeCommandIndex < 0) {
307
+ this.activeCommandIndex = this.filteredSlashCommands.length - 1;
308
+ } else if (this.activeCommandIndex >= this.filteredSlashCommands.length) {
309
+ this.activeCommandIndex = 0;
310
+ }
311
+ },
312
+ selectSlashCommand(index) {
313
+ const command = this.filteredSlashCommands[index];
314
+ if (command.shouldSubmit) {
315
+ this.prompt = command.name;
316
+ this.sendChatPrompt();
317
+ } else {
318
+ this.prompt = `${command.name} `;
319
+ this.$refs.prompt.$el.focus();
320
+ }
321
+ },
228
322
  },
229
323
  i18n,
230
324
  emptySvg,
@@ -349,7 +443,30 @@ export default {
349
443
  class="duo-chat-input gl-flex-grow-1 gl-vertical-align-top gl-max-w-full gl-min-h-8 gl-inset-border-1-gray-400 gl-rounded-base gl-bg-white"
350
444
  :data-value="prompt"
351
445
  >
446
+ <gl-card
447
+ v-if="shouldShowSlashCommands"
448
+ ref="commands"
449
+ class="slash-commands gl-absolute! gl-translate-y-n100 gl-list-style-none gl-pl-0 gl-w-full gl-shadow-md"
450
+ body-class="gl-p-2!"
451
+ >
452
+ <gl-dropdown-item
453
+ v-for="(command, index) in filteredSlashCommands"
454
+ :key="command.name"
455
+ :class="{ 'active-command': index === activeCommandIndex }"
456
+ @mouseenter.native="activeCommandIndex = index"
457
+ @click="selectSlashCommand(index)"
458
+ >
459
+ <span class="gl-display-flex gl-justify-content-space-between">
460
+ <span class="gl-display-block">{{ command.name }}</span>
461
+ <small class="gl-text-gray-500 gl-font-style-italic">{{
462
+ command.description
463
+ }}</small>
464
+ </span>
465
+ </gl-dropdown-item>
466
+ </gl-card>
467
+
352
468
  <gl-form-textarea
469
+ ref="prompt"
353
470
  v-model="prompt"
354
471
  data-testid="chat-prompt-input"
355
472
  class="gl-absolute gl-h-full! gl-py-4! gl-bg-transparent! gl-rounded-top-right-none gl-rounded-bottom-right-none gl-shadow-none!"
@@ -357,7 +474,8 @@ export default {
357
474
  :placeholder="$options.i18n.CHAT_PROMPT_PLACEHOLDER"
358
475
  :disabled="isLoading"
359
476
  autofocus
360
- @keydown.enter.exact.native.prevent="sendChatPrompt"
477
+ @keydown.enter.exact.native.prevent
478
+ @keyup.native="onInputKeyup"
361
479
  />
362
480
  </div>
363
481
  <template #append>