@gitlab/ui 78.1.0 → 78.1.2

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [78.1.2](https://gitlab.com/gitlab-org/gitlab-ui/compare/v78.1.1...v78.1.2) (2024-03-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Repair right alignment for table header ([3051537](https://gitlab.com/gitlab-org/gitlab-ui/commit/30515372b8b6212cab60b0cf50671a7cd36a392a))
7
+
8
+ ## [78.1.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v78.1.0...v78.1.1) (2024-03-05)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **GlDuoChat:** allow typing prompt while streaming ([bc107bf](https://gitlab.com/gitlab-org/gitlab-ui/commit/bc107bf7b4e84ec787142ed5b43f299ec6c7ea0b))
14
+
1
15
  # [78.1.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v78.0.0...v78.1.0) (2024-03-05)
2
16
 
3
17
 
@@ -1,5 +1,4 @@
1
1
  import { BTable } from 'bootstrap-vue/esm/index.js';
2
- import GlIcon from '../icon/icon';
3
2
  import { isDev, logWarning } from '../../../utils/utils';
4
3
  import { tableFullProps, tableFullSlots, glTableLiteWarning } from './constants';
5
4
  import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
@@ -18,8 +17,7 @@ const {
18
17
  var script = {
19
18
  name: 'GlTable',
20
19
  components: {
21
- BTable,
22
- GlIcon
20
+ BTable
23
21
  },
24
22
  inheritAttrs: false,
25
23
  props: {
@@ -92,7 +90,7 @@ var script = {
92
90
  const __vue_script__ = script;
93
91
 
94
92
  /* template */
95
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('b-table',_vm._g(_vm._b({attrs:{"table-class":_vm.localTableClass,"fields":_vm.fields,"sort-by":_vm.localSortBy,"sort-desc":_vm.localSortDesc},on:{"update:sortBy":function($event){_vm.localSortBy=$event;},"update:sort-by":function($event){_vm.localSortBy=$event;},"update:sortDesc":function($event){_vm.localSortDesc=$event;},"update:sort-desc":function($event){_vm.localSortDesc=$event;}},scopedSlots:_vm._u([_vm._l((Object.keys(_vm.$scopedSlots)),function(slotName){return {key:slotName,fn:function(scope){return [_vm._t(slotName,null,null,scope)]}}}),_vm._l((_vm.headSlots),function(headSlotName){return {key:headSlotName,fn:function(scope){return [_c('div',{key:headSlotName,staticClass:"gl-display-flex gl-align-items-center"},[_vm._t(headSlotName,function(){return [_vm._v(_vm._s(scope.label))]},null,scope),(_vm.isSortable(scope))?[(_vm.getSortingIcon(scope))?_c('gl-icon',{staticClass:"gl-ml-3 gl-min-w-5 gl-text-gray-900",attrs:{"name":_vm.getSortingIcon(scope)}}):_c('div',{staticClass:"gl-display-inline-block gl-w-5 gl-h-5 gl-ml-3"})]:_vm._e()],2)]}}})],null,true)},'b-table',_vm.$attrs,false),_vm.$listeners))};
93
+ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('b-table',_vm._g(_vm._b({attrs:{"table-class":_vm.localTableClass,"fields":_vm.fields,"sort-by":_vm.localSortBy,"sort-desc":_vm.localSortDesc},on:{"update:sortBy":function($event){_vm.localSortBy=$event;},"update:sort-by":function($event){_vm.localSortBy=$event;},"update:sortDesc":function($event){_vm.localSortDesc=$event;},"update:sort-desc":function($event){_vm.localSortDesc=$event;}},scopedSlots:_vm._u([_vm._l((Object.keys(_vm.$scopedSlots)),function(slotName){return {key:slotName,fn:function(scope){return [_vm._t(slotName,null,null,scope)]}}}),_vm._l((_vm.headSlots),function(headSlotName){return {key:headSlotName,fn:function(scope){return [_c('span',{key:headSlotName},[_vm._t(headSlotName,function(){return [_c('span',[_vm._v(_vm._s(scope.label))])]},null,scope),(_vm.isSortable(scope))?[(_vm.getSortingIcon(scope) && _vm.getSortingIcon(scope) === 'arrow-up')?_c('span',{staticClass:"gl-ml-3 gl-min-w-5 gl-text-gray-900 gl-text-center",attrs:{"name":"sort-icon"}},[_vm._v("\n ↑\n ")]):(_vm.getSortingIcon(scope) && _vm.getSortingIcon(scope) === 'arrow-down')?_c('span',{staticClass:"gl-ml-3 gl-min-w-5 gl-text-gray-900 gl-text-center",attrs:{"name":"sort-icon"}},[_vm._v("\n ↓\n ")]):_c('span',{staticClass:"gl-display-inline-block gl-w-5 gl-h-3 gl-ml-3"})]:_vm._e()],2)]}}})],null,true)},'b-table',_vm.$attrs,false),_vm.$listeners))};
96
94
  var __vue_staticRenderFns__ = [];
97
95
 
98
96
  /* style */
@@ -201,12 +201,22 @@ var script = {
201
201
  return acc;
202
202
  }, [[]]);
203
203
  },
204
+ lastMessage() {
205
+ return this.messages[this.messages.length - 1];
206
+ },
204
207
  resetDisabled() {
208
+ var _this$lastMessage;
205
209
  if (this.isLoading || !this.hasMessages) {
206
210
  return true;
207
211
  }
208
- const lastMessage = this.messages[this.messages.length - 1];
209
- return lastMessage.content === CHAT_RESET_MESSAGE;
212
+ return ((_this$lastMessage = this.lastMessage) === null || _this$lastMessage === void 0 ? void 0 : _this$lastMessage.content) === CHAT_RESET_MESSAGE;
213
+ },
214
+ submitDisabled() {
215
+ return this.isLoading || this.isStreaming;
216
+ },
217
+ isStreaming() {
218
+ var _this$lastMessage2, _this$lastMessage2$ch, _this$lastMessage3;
219
+ return Boolean(((_this$lastMessage2 = this.lastMessage) === null || _this$lastMessage2 === void 0 ? void 0 : (_this$lastMessage2$ch = _this$lastMessage2.chunks) === null || _this$lastMessage2$ch === void 0 ? void 0 : _this$lastMessage2$ch.length) > 0 && !((_this$lastMessage3 = this.lastMessage) !== null && _this$lastMessage3 !== void 0 && _this$lastMessage3.content));
210
220
  },
211
221
  filteredSlashCommands() {
212
222
  const caseInsensitivePrompt = this.prompt.toLowerCase();
@@ -227,12 +237,13 @@ var script = {
227
237
  }
228
238
  },
229
239
  watch: {
230
- isLoading() {
240
+ isLoading(newVal) {
231
241
  this.isHidden = false;
232
242
  this.scrollToBottom();
233
- },
234
- messages() {
235
- this.prompt = '';
243
+ if (newVal) {
244
+ // We reset the prompt when we start getting the response and focus in the prompt field
245
+ this.setPromptAndFocus();
246
+ }
236
247
  }
237
248
  },
238
249
  created() {
@@ -250,6 +261,9 @@ var script = {
250
261
  this.$emit('chat-hidden');
251
262
  },
252
263
  sendChatPrompt() {
264
+ if (this.submitDisabled) {
265
+ return;
266
+ }
253
267
  if (this.prompt) {
254
268
  if (this.prompt === CHAT_RESET_MESSAGE && this.resetDisabled) {
255
269
  return;
@@ -324,14 +338,19 @@ var script = {
324
338
  this.activeCommandIndex = 0;
325
339
  }
326
340
  },
341
+ async setPromptAndFocus() {
342
+ let prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
343
+ this.prompt = prompt;
344
+ await this.$nextTick();
345
+ this.$refs.prompt.$el.focus();
346
+ },
327
347
  selectSlashCommand(index) {
328
348
  const command = this.filteredSlashCommands[index];
329
349
  if (command.shouldSubmit) {
330
350
  this.prompt = command.name;
331
351
  this.sendChatPrompt();
332
352
  } else {
333
- this.prompt = `${command.name} `;
334
- this.$refs.prompt.$el.focus();
353
+ this.setPromptAndFocus(`${command.name} `);
335
354
  }
336
355
  }
337
356
  },
@@ -347,7 +366,7 @@ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=
347
366
  {
348
367
  'gl-h-full': !_vm.hasMessages,
349
368
  'force-scroll-bar': _vm.hasMessages,
350
- } ],attrs:{"tag":"section","name":"message"}},[_vm._l((_vm.conversations),function(conversation,index){return _c('gl-duo-chat-conversation',{key:("conversation-" + index),attrs:{"messages":conversation,"show-delimiter":index > 0},on:{"track-feedback":_vm.onTrackFeedback}})}),_vm._v(" "),(!_vm.hasMessages && !_vm.isLoading)?[_c('gl-empty-state',{key:"empty-state",staticClass:"gl-flex-grow gl-justify-content-center",attrs:{"svg-path":_vm.$options.emptySvg,"svg-height":145,"title":_vm.emptyStateTitle,"description":_vm.emptyStateDescription}}),_vm._v(" "),_c('gl-duo-chat-predefined-prompts',{key:"predefined-prompts",attrs:{"prompts":_vm.predefinedPrompts},on:{"click":_vm.sendPredefinedPrompt}})]:_vm._e(),_vm._v(" "),(_vm.isLoading)?_c('gl-duo-chat-loader',{key:"loader",attrs:{"tool-name":_vm.toolName}}):_vm._e(),_vm._v(" "),_c('div',{key:"anchor",ref:"anchor",staticClass:"scroll-anchor"})],2)],1),_vm._v(" "),(_vm.isChatAvailable)?_c('footer',{staticClass:"gl-drawer-footer gl-drawer-footer-sticky gl-p-5 gl-border-t gl-bg-gray-10",class:{ 'gl-drawer-body-scrim-on-footer': !_vm.scrolledToBottom },attrs:{"data-testid":"chat-footer"}},[_c('gl-form',{attrs:{"data-testid":"chat-prompt-form"},on:{"submit":function($event){$event.stopPropagation();$event.preventDefault();return _vm.sendChatPrompt.apply(null, arguments)}}},[_c('gl-form-input-group',{scopedSlots:_vm._u([{key:"append",fn:function(){return [_c('gl-button',{staticClass:"!gl-absolute gl-bottom-2 gl-right-2 gl-rounded-base!",attrs:{"icon":"paper-airplane","category":"primary","variant":"confirm","type":"submit","aria-label":_vm.$options.i18n.CHAT_SUBMIT_LABEL,"disabled":_vm.isLoading}})]},proxy:true}],null,false,3929529036)},[_c('div',{staticClass:"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",attrs:{"data-value":_vm.prompt}},[(_vm.shouldShowSlashCommands)?_c('gl-card',{ref:"commands",staticClass:"slash-commands !gl-absolute gl-translate-y-n100 gl-list-style-none gl-pl-0 gl-w-full gl-shadow-md",attrs:{"body-class":"gl-p-2!"}},_vm._l((_vm.filteredSlashCommands),function(command,index){return _c('gl-dropdown-item',{key:command.name,class:{ 'active-command': index === _vm.activeCommandIndex },on:{"click":function($event){return _vm.selectSlashCommand(index)}},nativeOn:{"mouseenter":function($event){_vm.activeCommandIndex = index;}}},[_c('span',{staticClass:"gl-display-flex gl-justify-content-space-between"},[_c('span',{staticClass:"gl-display-block"},[_vm._v(_vm._s(command.name))]),_vm._v(" "),_c('small',{staticClass:"gl-text-gray-500 gl-font-style-italic gl-text-right gl-pl-3"},[_vm._v(_vm._s(command.description))])])])}),1):_vm._e(),_vm._v(" "),_c('gl-form-textarea',{ref:"prompt",staticClass:"gl-absolute gl-h-full! gl-py-4! gl-bg-transparent! gl-rounded-top-right-none gl-rounded-bottom-right-none gl-shadow-none!",class:{ 'gl-text-truncate': !_vm.prompt },attrs:{"data-testid":"chat-prompt-input","placeholder":_vm.inputPlaceholder,"disabled":_vm.isLoading,"autofocus":""},nativeOn:{"keydown":function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){ return null; }if($event.ctrlKey||$event.shiftKey||$event.altKey||$event.metaKey){ return null; }$event.preventDefault();},"keyup":function($event){return _vm.onInputKeyup.apply(null, arguments)}},model:{value:(_vm.prompt),callback:function ($$v) {_vm.prompt=$$v;},expression:"prompt"}})],1)]),_vm._v(" "),_c('gl-form-text',{staticClass:"gl-text-gray-400 gl-line-height-20 gl-mt-3",attrs:{"data-testid":"chat-legal-disclaimer"}},[_vm._v(_vm._s(_vm.$options.i18n.CHAT_LEGAL_DISCLAIMER))])],1)],1):_vm._e()]):_vm._e()};
369
+ } ],attrs:{"tag":"section","name":"message"}},[_vm._l((_vm.conversations),function(conversation,index){return _c('gl-duo-chat-conversation',{key:("conversation-" + index),attrs:{"messages":conversation,"show-delimiter":index > 0},on:{"track-feedback":_vm.onTrackFeedback}})}),_vm._v(" "),(!_vm.hasMessages && !_vm.isLoading)?[_c('gl-empty-state',{key:"empty-state",staticClass:"gl-flex-grow gl-justify-content-center",attrs:{"svg-path":_vm.$options.emptySvg,"svg-height":145,"title":_vm.emptyStateTitle,"description":_vm.emptyStateDescription}}),_vm._v(" "),_c('gl-duo-chat-predefined-prompts',{key:"predefined-prompts",attrs:{"prompts":_vm.predefinedPrompts},on:{"click":_vm.sendPredefinedPrompt}})]:_vm._e(),_vm._v(" "),(_vm.isLoading)?_c('gl-duo-chat-loader',{key:"loader",attrs:{"tool-name":_vm.toolName}}):_vm._e(),_vm._v(" "),_c('div',{key:"anchor",ref:"anchor",staticClass:"scroll-anchor"})],2)],1),_vm._v(" "),(_vm.isChatAvailable)?_c('footer',{staticClass:"gl-drawer-footer gl-drawer-footer-sticky gl-p-5 gl-border-t gl-bg-gray-10",class:{ 'gl-drawer-body-scrim-on-footer': !_vm.scrolledToBottom },attrs:{"data-testid":"chat-footer"}},[_c('gl-form',{attrs:{"data-testid":"chat-prompt-form"},on:{"submit":function($event){$event.stopPropagation();$event.preventDefault();return _vm.sendChatPrompt.apply(null, arguments)}}},[_c('gl-form-input-group',{scopedSlots:_vm._u([{key:"append",fn:function(){return [_c('gl-button',{staticClass:"!gl-absolute gl-bottom-2 gl-right-2 gl-rounded-base!",attrs:{"icon":"paper-airplane","category":"primary","variant":"confirm","type":"submit","data-testid":"chat-prompt-submit-button","aria-label":_vm.$options.i18n.CHAT_SUBMIT_LABEL,"disabled":_vm.submitDisabled}})]},proxy:true}],null,false,3132459889)},[_c('div',{staticClass:"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",attrs:{"data-value":_vm.prompt}},[(_vm.shouldShowSlashCommands)?_c('gl-card',{ref:"commands",staticClass:"slash-commands !gl-absolute gl-translate-y-n100 gl-list-style-none gl-pl-0 gl-w-full gl-shadow-md",attrs:{"body-class":"gl-p-2!"}},_vm._l((_vm.filteredSlashCommands),function(command,index){return _c('gl-dropdown-item',{key:command.name,class:{ 'active-command': index === _vm.activeCommandIndex },on:{"click":function($event){return _vm.selectSlashCommand(index)}},nativeOn:{"mouseenter":function($event){_vm.activeCommandIndex = index;}}},[_c('span',{staticClass:"gl-display-flex gl-justify-content-space-between"},[_c('span',{staticClass:"gl-display-block"},[_vm._v(_vm._s(command.name))]),_vm._v(" "),_c('small',{staticClass:"gl-text-gray-500 gl-font-style-italic gl-text-right gl-pl-3"},[_vm._v(_vm._s(command.description))])])])}),1):_vm._e(),_vm._v(" "),_c('gl-form-textarea',{ref:"prompt",staticClass:"gl-absolute gl-h-full! gl-py-4! gl-bg-transparent! gl-rounded-top-right-none gl-rounded-bottom-right-none gl-shadow-none!",class:{ 'gl-text-truncate': !_vm.prompt },attrs:{"data-testid":"chat-prompt-input","placeholder":_vm.inputPlaceholder,"autofocus":""},nativeOn:{"keydown":function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){ return null; }if($event.ctrlKey||$event.shiftKey||$event.altKey||$event.metaKey){ return null; }$event.preventDefault();},"keyup":function($event){return _vm.onInputKeyup.apply(null, arguments)}},model:{value:(_vm.prompt),callback:function ($$v) {_vm.prompt=$$v;},expression:"prompt"}})],1)]),_vm._v(" "),_c('gl-form-text',{staticClass:"gl-text-gray-400 gl-line-height-20 gl-mt-3",attrs:{"data-testid":"chat-legal-disclaimer"}},[_vm._v(_vm._s(_vm.$options.i18n.CHAT_LEGAL_DISCLAIMER))])],1)],1):_vm._e()]):_vm._e()};
351
370
  var __vue_staticRenderFns__ = [];
352
371
 
353
372
  /* style */
@@ -1,3 +1,4 @@
1
+ import { setStoryTimeout } from '../../../../utils/test_utils';
1
2
  import { DOCUMENTATION_SOURCE_TYPES, MESSAGE_MODEL_ROLES } from './constants';
2
3
 
3
4
  const MOCK_SOURCES = [{
@@ -57,21 +58,47 @@ const MOCK_RESPONSE_MESSAGE_FOR_STREAMING = {
57
58
  errors: [],
58
59
  timestamp: '2021-04-21T12:00:00.000Z'
59
60
  };
60
- const generateMockResponseChunks = requestId => {
61
- const chunks = [];
62
- const chunkSize = 5;
63
- const chunkCount = Math.ceil(MOCK_RESPONSE_MESSAGE_FOR_STREAMING.content.length / chunkSize);
64
- for (let i = 0; i < chunkCount; i += 1) {
65
- const chunk = {
66
- ...MOCK_RESPONSE_MESSAGE_FOR_STREAMING,
67
- requestId,
68
- content: MOCK_RESPONSE_MESSAGE_FOR_STREAMING.content.substring(i * chunkSize, (i + 1) * chunkSize),
69
- chunkId: i
70
- };
71
- chunks.push(chunk);
61
+
62
+ // Utility function for delay
63
+ async function delayRandom() {
64
+ let min = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 16;
65
+ let max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 267;
66
+ const delay = Math.floor(Math.random() * (max - min + 1)) + min;
67
+ // eslint-disable-next-line no-promise-executor-return
68
+ return new Promise(resolve => setStoryTimeout(resolve, delay));
69
+ }
70
+ function generateMockResponseChunks() {
71
+ try {
72
+ let requestId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
73
+ return async function* () {
74
+ const chunkSize = 5;
75
+ const contentLength = MOCK_RESPONSE_MESSAGE_FOR_STREAMING.content.length;
76
+ const chunkCount = Math.ceil(contentLength / chunkSize);
77
+ for (let chunkId = 0; chunkId < chunkCount; chunkId += 1) {
78
+ const start = chunkId * chunkSize;
79
+ const end = Math.min((chunkId + 1) * chunkSize, contentLength);
80
+ const chunk = {
81
+ ...MOCK_RESPONSE_MESSAGE_FOR_STREAMING,
82
+ requestId,
83
+ content: MOCK_RESPONSE_MESSAGE_FOR_STREAMING.content.substring(start, end),
84
+ chunkId
85
+ };
86
+
87
+ // eslint-disable-next-line no-await-in-loop
88
+ await delayRandom();
89
+ yield chunk;
90
+ }
91
+ yield {
92
+ ...MOCK_RESPONSE_MESSAGE_FOR_STREAMING,
93
+ requestId,
94
+ content: MOCK_RESPONSE_MESSAGE_FOR_STREAMING.content,
95
+ chunkId: null
96
+ };
97
+ }();
98
+ } catch (e) {
99
+ return Promise.reject(e);
72
100
  }
73
- return chunks;
74
- };
101
+ }
75
102
  const MOCK_USER_PROMPT_MESSAGE = {
76
103
  id: '456',
77
104
  content: 'How to create a new template?',