@gitlab/duo-ui 0.4.0 → 2.0.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/components/chat/components/duo_chat_context/constants.js +2 -1
  3. package/dist/components/chat/components/duo_chat_context/duo_chat_context_item_details_modal/duo_chat_context_item_details_modal.js +39 -9
  4. package/dist/components/chat/components/duo_chat_context/duo_chat_context_item_menu/duo_chat_context_item_menu.js +1 -1
  5. package/dist/components/chat/components/duo_chat_context/duo_chat_context_item_menu/duo_chat_context_item_menu_search_item.js +8 -16
  6. package/dist/components/chat/components/duo_chat_context/duo_chat_context_item_menu/duo_chat_context_item_menu_search_items_loading.js +1 -1
  7. package/dist/components/chat/components/duo_chat_context/duo_chat_context_item_popover/duo_chat_context_item_popover.js +12 -8
  8. package/dist/components/chat/components/duo_chat_context/duo_chat_context_item_selections/duo_chat_context_item_selections.js +2 -2
  9. package/dist/components/chat/components/duo_chat_context/mock_context_data.js +118 -9
  10. package/dist/components/chat/components/duo_chat_context/utils.js +28 -2
  11. package/dist/components/chat/components/duo_chat_conversation/duo_chat_conversation.js +1 -1
  12. package/dist/components/chat/components/duo_chat_loader/duo_chat_loader.js +1 -1
  13. package/dist/components/chat/duo_chat.js +4 -4
  14. package/dist/components/workflow/components/duo_workflow_panel/duo_workflow_panel.js +1 -1
  15. package/dist/components/workflow/components/duo_workflow_prompt/duo_workflow_prompt.js +1 -1
  16. package/dist/components.css +1 -1
  17. package/dist/components.css.map +1 -1
  18. package/dist/tailwind.css +1 -1
  19. package/dist/tailwind.css.map +1 -1
  20. package/dist/utils/i18n.js +63 -0
  21. package/package.json +2 -2
  22. package/src/components/chat/components/duo_chat_context/constants.js +1 -0
  23. package/src/components/chat/components/duo_chat_context/duo_chat_context_item_details_modal/duo_chat_context_item_details_modal.vue +64 -6
  24. package/src/components/chat/components/duo_chat_context/duo_chat_context_item_menu/duo_chat_context_item_menu.md +35 -0
  25. package/src/components/chat/components/duo_chat_context/duo_chat_context_item_menu/duo_chat_context_item_menu.vue +1 -1
  26. package/src/components/chat/components/duo_chat_context/duo_chat_context_item_menu/duo_chat_context_item_menu_search_item.vue +17 -25
  27. package/src/components/chat/components/duo_chat_context/duo_chat_context_item_menu/duo_chat_context_item_menu_search_items_loading.vue +1 -1
  28. package/src/components/chat/components/duo_chat_context/duo_chat_context_item_popover/duo_chat_context_item_popover.vue +20 -15
  29. package/src/components/chat/components/duo_chat_context/duo_chat_context_item_selections/duo_chat_context_item_selections.vue +10 -4
  30. package/src/components/chat/components/duo_chat_context/mock_context_data.js +148 -9
  31. package/src/components/chat/components/duo_chat_context/utils.js +32 -1
  32. package/src/components/chat/components/duo_chat_conversation/duo_chat_conversation.vue +1 -1
  33. package/src/components/chat/components/duo_chat_loader/duo_chat_loader.vue +1 -1
  34. package/src/components/chat/duo_chat.scss +19 -8
  35. package/src/components/chat/duo_chat.vue +15 -11
  36. package/src/components/workflow/components/duo_workflow_panel/duo_workflow_panel.vue +1 -1
  37. package/src/components/workflow/components/duo_workflow_prompt/duo_workflow_prompt.vue +1 -1
  38. package/src/utils/i18n.js +62 -0
  39. package/translations.js +2 -1
@@ -15,7 +15,7 @@ import {
15
15
  GlSafeHtmlDirective as SafeHtml,
16
16
  } from '@gitlab/ui';
17
17
 
18
- import { translate } from '@gitlab/ui/dist/utils/i18n';
18
+ import { translate } from '../../utils/i18n';
19
19
  import {
20
20
  badgeTypes,
21
21
  badgeTypeValidator,
@@ -46,7 +46,7 @@ export const i18n = {
46
46
  ),
47
47
  CHAT_PROMPT_PLACEHOLDER_WITH_COMMANDS: translate(
48
48
  'GlDuoChat.chatPromptPlaceholderWithCommands',
49
- 'Type "/" for slash commands'
49
+ 'Type /help to learn more'
50
50
  ),
51
51
  CHAT_SUBMIT_LABEL: translate('GlDuoChat.chatSubmitLabel', 'Send chat message.'),
52
52
  CHAT_CANCEL_LABEL: translate('GlDuoChat.chatCancelLabel', 'Cancel'),
@@ -542,14 +542,14 @@ export default {
542
542
  <aside
543
543
  v-if="!isHidden"
544
544
  id="chat-component"
545
- class="markdown-code-block duo-chat-drawer duo-chat gl-border-t gl-border-l gl-bottom-0 gl-max-h-full gl-shadow-none"
545
+ class="markdown-code-block duo-chat-drawer duo-chat gl-bottom-0 gl-max-h-full"
546
546
  role="complementary"
547
547
  data-testid="chat-component"
548
548
  >
549
549
  <header
550
550
  v-if="showHeader"
551
551
  data-testid="chat-header"
552
- class="duo-chat-drawer-header duo-chat-drawer-header-sticky gl-z-200 gl-bg-gray-10 !gl-p-0"
552
+ class="duo-chat-drawer-header duo-chat-drawer-header-sticky gl-z-200 gl-border-0 gl-bg-default !gl-p-0"
553
553
  >
554
554
  <div class="drawer-title gl-flex gl-items-center gl-justify-start gl-p-5">
555
555
  <h3 class="gl-my-0 gl-text-size-h2">{{ title }}</h3>
@@ -590,11 +590,15 @@ export default {
590
590
  </gl-alert>
591
591
  </header>
592
592
 
593
- <div class="duo-chat-drawer-body" data-testid="chat-history" @scroll="handleScrollingTrottled">
593
+ <div
594
+ class="duo-chat-drawer-body gl-bg-default"
595
+ data-testid="chat-history"
596
+ @scroll="handleScrollingTrottled"
597
+ >
594
598
  <transition-group
595
599
  tag="section"
596
600
  name="message"
597
- class="duo-chat-history gl-flex gl-flex-col gl-justify-end gl-bg-gray-10"
601
+ class="duo-chat-history gl-flex gl-flex-col gl-justify-end"
598
602
  :class="[
599
603
  {
600
604
  'gl-h-full': !hasMessages,
@@ -646,7 +650,7 @@ export default {
646
650
  <footer
647
651
  v-if="isChatAvailable"
648
652
  data-testid="chat-footer"
649
- class="duo-chat-drawer-footer duo-chat-drawer-footer-sticky gl-border-t gl-bg-gray-10 gl-p-5"
653
+ class="duo-chat-drawer-footer duo-chat-drawer-footer-sticky gl-border-0 gl-bg-default gl-p-5"
650
654
  :class="{ 'duo-chat-drawer-body-scrim-on-footer': !scrolledToBottom }"
651
655
  >
652
656
  <gl-form data-testid="chat-prompt-form" @submit.stop.prevent="sendChatPrompt">
@@ -665,7 +669,7 @@ export default {
665
669
 
666
670
  <gl-form-input-group>
667
671
  <div
668
- class="duo-chat-input gl-min-h-8 gl-max-w-full gl-grow gl-rounded-base gl-bg-white gl-align-top gl-shadow-inner-1-gray-400"
672
+ class="duo-chat-input gl-min-h-8 gl-max-w-full gl-grow gl-align-top"
669
673
  :data-value="prompt"
670
674
  >
671
675
  <gl-card
@@ -683,7 +687,7 @@ export default {
683
687
  >
684
688
  <span class="gl-flex gl-justify-between">
685
689
  <span class="gl-block">{{ command.name }}</span>
686
- <small class="gl-pl-3 gl-text-right gl-italic gl-text-gray-500">{{
690
+ <small class="gl-pl-3 gl-text-right gl-italic gl-text-subtle">{{
687
691
  command.description
688
692
  }}</small>
689
693
  </span>
@@ -709,7 +713,7 @@ export default {
709
713
  icon="paper-airplane"
710
714
  category="primary"
711
715
  variant="confirm"
712
- class="!gl-absolute gl-bottom-2 gl-right-2 !gl-rounded-base"
716
+ class="!gl-absolute gl-bottom-2 gl-right-2 !gl-rounded-full"
713
717
  type="submit"
714
718
  data-testid="chat-prompt-submit-button"
715
719
  :aria-label="$options.i18n.CHAT_SUBMIT_LABEL"
@@ -719,7 +723,7 @@ export default {
719
723
  icon="stop"
720
724
  category="primary"
721
725
  variant="default"
722
- class="!gl-absolute gl-bottom-2 gl-right-2 !gl-rounded-base"
726
+ class="!gl-absolute gl-bottom-2 gl-right-2 !gl-rounded-full"
723
727
  data-testid="chat-prompt-cancel-button"
724
728
  :aria-label="$options.i18n.CHAT_CANCEL_LABEL"
725
729
  @click="cancelPrompt"
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { GlIcon, GlCollapse, GlButton, GlTooltipDirective as GlTooltip } from '@gitlab/ui';
3
- import { translate } from '@gitlab/ui/dist/utils/i18n';
3
+ import { translate } from '../../../../utils/i18n';
4
4
 
5
5
  export default {
6
6
  name: 'GlDuoWorkflowPanel',
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { GlButton, GlFormGroup, GlFormTextarea, GlFormInput } from '@gitlab/ui';
3
- import { translate } from '@gitlab/ui/dist/utils/i18n';
3
+ import { translate } from '../../../../utils/i18n';
4
4
  import GlDuoWorkflowPanel from '../duo_workflow_panel/duo_workflow_panel.vue';
5
5
 
6
6
  export default {
@@ -0,0 +1,62 @@
1
+ import escape from 'lodash/escape';
2
+ import { i18n } from '../config';
3
+
4
+ const defaultPluralHandler = (n, singleValue, pluralValue) => {
5
+ const value = n === 1 ? singleValue : pluralValue;
6
+
7
+ return value.replace(/%d/g, n);
8
+ };
9
+
10
+ /**
11
+ * Mark a label as translatable.
12
+ *
13
+ * @param {string} key Translation key to be leveraged by the consumer to provide a generic translation at configuration time.
14
+ * @param {string} defaultValue A fallback value to be relied on if the consumer doesn't have translation capabilities.
15
+ * @returns {string} The translated label.
16
+ */
17
+ export const translate = (key, defaultValue) => i18n[key] ?? defaultValue;
18
+
19
+ /**
20
+ * Marks a label as translatable and pluralized.
21
+ *
22
+ * @param {*} key Translation key to be leveraged by the consumer to provide a generic translation at configuration time.
23
+ * @param {*} singularValue The singular value to be relied on if the consumer doesn't have translation capabilities.
24
+ * @param {*} pluralValue The plural value to be relied on if the consumer doesn't have translation capabilities.
25
+ * @returns {function} A function that takes a number and returns the pluralized translated label.
26
+ */
27
+ export const translatePlural = (key, singularValue, pluralValue) => {
28
+ if (i18n[key]) {
29
+ return i18n[key];
30
+ }
31
+ return (x) => defaultPluralHandler(x, singularValue, pluralValue);
32
+ };
33
+
34
+ /**
35
+ * Very limited implementation of sprintf supporting only named parameters.
36
+ * Copied from the GitLab repo: https://gitlab.com/gitlab-org/gitlab/-/blob/0dff8b02accb3dccbf6cd31236834c37013aad59/app/assets/javascripts/locale/sprintf.js.
37
+ * @param {string} input - (translated) text with parameters (e.g. '%{num_users} users use us')
38
+ * @param {Object.<string, string|number>} [parameters] - object mapping parameter names to values (e.g. { num_users: 5 })
39
+ * @param {boolean} [escapeParameters=true] - whether parameter values should be escaped (see https://lodash.com/docs/4.17.15#escape)
40
+ * @returns {string} the text with parameters replaces (e.g. '5 users use us')
41
+ * @see https://ruby-doc.org/core-2.3.3/Kernel.html#method-i-sprintf
42
+ * @see https://gitlab.com/gitlab-org/gitlab-foss/issues/37992
43
+ */
44
+ export function sprintf(input, parameters, escapeParameters = true) {
45
+ let output = input;
46
+
47
+ output = output.replace(/%+/g, '%');
48
+
49
+ if (parameters) {
50
+ const mappedParameters = new Map(Object.entries(parameters));
51
+
52
+ mappedParameters.forEach((key, parameterName) => {
53
+ const parameterValue = mappedParameters.get(parameterName);
54
+ const escapedParameterValue = escapeParameters ? escape(parameterValue) : parameterValue;
55
+ // Pass the param value as a function to ignore special replacement patterns like $` and $'.
56
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#syntax
57
+ output = output.replace(new RegExp(`%{${parameterName}}`, 'g'), () => escapedParameterValue);
58
+ });
59
+ }
60
+
61
+ return output;
62
+ }
package/translations.js CHANGED
@@ -18,8 +18,9 @@ export default {
18
18
  'GlDuoChat.chatEmptyStateSecondaryDesc': 'Responses may be inaccurate. Verify before use.',
19
19
  'GlDuoChat.chatEmptyStateTitle': 'Ask a question',
20
20
  'GlDuoChat.chatPromptPlaceholderDefault': 'GitLab Duo Chat',
21
- 'GlDuoChat.chatPromptPlaceholderWithCommands': 'Type "/" for slash commands',
21
+ 'GlDuoChat.chatPromptPlaceholderWithCommands': 'Type /help to learn more',
22
22
  'GlDuoChat.chatSubmitLabel': 'Send chat message.',
23
+ 'GlDuoChatContextItemDetailsModal.contentErrorMessage': 'Item content could not be displayed.',
23
24
  'GlDuoChatContextItemDetailsModal.title': 'Preview',
24
25
  'GlDuoChatContextItemMenu.emptyStateMessage': 'No results found',
25
26
  'GlDuoChatContextItemMenu.loadingMessage': 'Loading...',