@gitlab/ui 66.21.0 → 66.22.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [66.22.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v66.21.0...v66.22.0) (2023-10-03)
2
+
3
+
4
+ ### Features
5
+
6
+ * **GlDuoChatMessageSources:** Implemented component ([8066320](https://gitlab.com/gitlab-org/gitlab-ui/commit/8066320214e88a8b75279eec1d82029bf8c3e9db))
7
+
1
8
  # [66.21.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v66.20.0...v66.21.0) (2023-10-02)
2
9
 
3
10
 
@@ -0,0 +1,103 @@
1
+ import { GlIcon, GlLink } from '../../../../../../index';
2
+ import { DOCUMENTATION_SOURCE_TYPES } from '../../constants';
3
+ import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
4
+
5
+ const i18n = {
6
+ MESSAGE_SOURCE: 'Source',
7
+ MESSAGE_SOURCES: 'Sources'
8
+ };
9
+ var script = {
10
+ name: 'GlDuoChatMessageSources',
11
+ components: {
12
+ GlIcon,
13
+ GlLink
14
+ },
15
+ props: {
16
+ /**
17
+ * The Array of the message sources.
18
+ */
19
+ sources: {
20
+ type: Array,
21
+ required: true
22
+ }
23
+ },
24
+ computed: {
25
+ sourceLabel() {
26
+ return this.sources.length > 1 ? i18n.MESSAGE_SOURCES : i18n.MESSAGE_SOURCES;
27
+ }
28
+ },
29
+ methods: {
30
+ getSourceIcon(sourceType) {
31
+ const currentSourceType = Object.values(DOCUMENTATION_SOURCE_TYPES).find(_ref => {
32
+ let {
33
+ value
34
+ } = _ref;
35
+ return value === sourceType;
36
+ });
37
+ return (currentSourceType === null || currentSourceType === void 0 ? void 0 : currentSourceType.icon) || 'document';
38
+ },
39
+ getSourceTitle(_ref2) {
40
+ let {
41
+ title,
42
+ source_type: sourceType,
43
+ stage,
44
+ group,
45
+ date,
46
+ author
47
+ } = _ref2;
48
+ if (title) {
49
+ return title;
50
+ }
51
+ if (sourceType === DOCUMENTATION_SOURCE_TYPES.DOC.value) {
52
+ if (stage && group) {
53
+ return `${stage} / ${group}`;
54
+ }
55
+ }
56
+ if (sourceType === DOCUMENTATION_SOURCE_TYPES.BLOG.value) {
57
+ if (date && author) {
58
+ return `${date} / ${author}`;
59
+ }
60
+ }
61
+ return i18n.MESSAGE_SOURCE;
62
+ }
63
+ }
64
+ };
65
+
66
+ /* script */
67
+ const __vue_script__ = script;
68
+
69
+ /* template */
70
+ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"gl-mt-4 gl-mr-3 gl-text-gray-600",attrs:{"data-testid":"duo-chat-message-sources"}},[(_vm.sources.length)?_c('span',[_vm._v(_vm._s(_vm.sourceLabel)+":")]):_vm._e(),_vm._v(" "),_c('ul',{staticClass:"gl-list-style-none gl-p-0 gl-m-0"},_vm._l((_vm.sources),function(source,index){return _c('li',{key:index,staticClass:"gl-display-flex gl-pt-3 gl-align-items-center",attrs:{"data-testid":"source-list-item"}},[(source.source_type)?_c('gl-icon',{staticClass:"gl-flex-shrink-0 gl-mr-2",attrs:{"name":_vm.getSourceIcon(source.source_type)}}):_vm._e(),_vm._v(" "),_c('gl-link',{attrs:{"href":source.source_url}},[_vm._v(_vm._s(_vm.getSourceTitle(source)))])],1)}),0)])};
71
+ var __vue_staticRenderFns__ = [];
72
+
73
+ /* style */
74
+ const __vue_inject_styles__ = undefined;
75
+ /* scoped */
76
+ const __vue_scope_id__ = undefined;
77
+ /* module identifier */
78
+ const __vue_module_identifier__ = undefined;
79
+ /* functional template */
80
+ const __vue_is_functional_template__ = false;
81
+ /* style inject */
82
+
83
+ /* style inject SSR */
84
+
85
+ /* style inject shadow dom */
86
+
87
+
88
+
89
+ const __vue_component__ = __vue_normalize__(
90
+ { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
91
+ __vue_inject_styles__,
92
+ __vue_script__,
93
+ __vue_scope_id__,
94
+ __vue_is_functional_template__,
95
+ __vue_module_identifier__,
96
+ false,
97
+ undefined,
98
+ undefined,
99
+ undefined
100
+ );
101
+
102
+ export default __vue_component__;
103
+ export { i18n };
@@ -0,0 +1,21 @@
1
+ const DOCUMENTATION_SOURCE_TYPES = {
2
+ HANDBOOK: {
3
+ value: 'handbook',
4
+ icon: 'book'
5
+ },
6
+ DOC: {
7
+ value: 'doc',
8
+ icon: 'documents'
9
+ },
10
+ BLOG: {
11
+ value: 'blog',
12
+ icon: 'list-bulleted'
13
+ }
14
+ };
15
+ const MESSAGE_MODEL_ROLES = {
16
+ user: 'user',
17
+ system: 'system',
18
+ assistant: 'assistant'
19
+ };
20
+
21
+ export { DOCUMENTATION_SOURCE_TYPES, MESSAGE_MODEL_ROLES };
@@ -0,0 +1,31 @@
1
+ import { DOCUMENTATION_SOURCE_TYPES, MESSAGE_MODEL_ROLES } from './constants';
2
+
3
+ const MOCK_SOURCES = [{
4
+ title: 'GitLab Handbook',
5
+ source_type: DOCUMENTATION_SOURCE_TYPES.HANDBOOK.value,
6
+ source_url: '/handbook/'
7
+ }, {
8
+ stage: 'Mock Stage',
9
+ group: 'Mock Group',
10
+ source_type: DOCUMENTATION_SOURCE_TYPES.DOC.value,
11
+ source_url: '/company/team/'
12
+ }, {
13
+ date: '2023-04-21',
14
+ author: 'Test User',
15
+ source_type: DOCUMENTATION_SOURCE_TYPES.BLOG.value,
16
+ source_url: '/blog/'
17
+ }];
18
+ const MOCK_RESPONSE_MESSAGE = {
19
+ id: '123',
20
+ content: '_Duo Chat message_ comming from AI',
21
+ contentHtml: '<p><em>Duo Chat message</em> comming from AI</p>',
22
+ role: MESSAGE_MODEL_ROLES.assistant,
23
+ extras: {
24
+ sources: MOCK_SOURCES
25
+ },
26
+ requestId: '987',
27
+ errors: [],
28
+ timestamp: '2021-04-21T12:00:00.000Z'
29
+ };
30
+
31
+ export { MOCK_RESPONSE_MESSAGE };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Mon, 02 Oct 2023 23:23:52 GMT
3
+ * Generated on Tue, 03 Oct 2023 10:22:26 GMT
4
4
  */
5
5
 
6
6
  :root {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Mon, 02 Oct 2023 23:23:52 GMT
3
+ * Generated on Tue, 03 Oct 2023 10:22:26 GMT
4
4
  */
5
5
 
6
6
  :root {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Mon, 02 Oct 2023 23:23:52 GMT
3
+ * Generated on Tue, 03 Oct 2023 10:22:26 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 Mon, 02 Oct 2023 23:23:52 GMT
3
+ * Generated on Tue, 03 Oct 2023 10:22:26 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 Mon, 02 Oct 2023 23:23:52 GMT
3
+ // Generated on Tue, 03 Oct 2023 10:22:26 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 Mon, 02 Oct 2023 23:23:52 GMT
3
+ // Generated on Tue, 03 Oct 2023 10:22:26 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": "66.21.0",
3
+ "version": "66.22.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -0,0 +1 @@
1
+ A simple component to list documentation sources for a documentation-related AI response messages.
@@ -0,0 +1,92 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import { GlIcon, GlLink } from '../../../../../../index';
3
+ import { DOCUMENTATION_SOURCE_TYPES } from '../../constants';
4
+ import GlDuoChatMessageSources from './duo_chat_message_sources.vue';
5
+
6
+ const dummySourceBase = {
7
+ title: 'Foo',
8
+ source_type: DOCUMENTATION_SOURCE_TYPES.HANDBOOK.value,
9
+ stage: 'foo-stage',
10
+ group: 'bar-group',
11
+ date: new Date('December 31, 2020 23:59:59'),
12
+ author: 'Gregor Samsa',
13
+ };
14
+
15
+ describe('Duo Chat Message Sources', () => {
16
+ let wrapper;
17
+
18
+ const findListItems = () => wrapper.findAll('[data-testid="source-list-item"]');
19
+ const findSourceIcons = () => wrapper.findAllComponents(GlIcon);
20
+ const findSourceTitles = () => wrapper.findAllComponents(GlLink);
21
+
22
+ const createComponent = ({ propsData = {} } = {}) => {
23
+ wrapper = shallowMount(GlDuoChatMessageSources, {
24
+ propsData,
25
+ });
26
+ };
27
+
28
+ it('does not render anything if sources is an empty Array', () => {
29
+ createComponent({
30
+ propsData: {
31
+ sources: [],
32
+ },
33
+ });
34
+ expect(wrapper.text()).toBe('');
35
+ });
36
+
37
+ it('renders sources passed down as a prop', () => {
38
+ createComponent({
39
+ propsData: {
40
+ sources: [
41
+ dummySourceBase,
42
+ {
43
+ ...dummySourceBase,
44
+ title: 'Bar',
45
+ },
46
+ ],
47
+ },
48
+ });
49
+ expect(findListItems().length).toBe(2);
50
+ });
51
+
52
+ it.each`
53
+ type | expectedIcon
54
+ ${DOCUMENTATION_SOURCE_TYPES.HANDBOOK.value} | ${DOCUMENTATION_SOURCE_TYPES.HANDBOOK.icon}
55
+ ${DOCUMENTATION_SOURCE_TYPES.DOC.value} | ${DOCUMENTATION_SOURCE_TYPES.DOC.icon}
56
+ ${DOCUMENTATION_SOURCE_TYPES.BLOG.value} | ${DOCUMENTATION_SOURCE_TYPES.BLOG.icon}
57
+ ${'foo'} | ${'document'}
58
+ `('renders the correct icon for $type type', ({ type, expectedIcon } = {}) => {
59
+ createComponent({
60
+ propsData: {
61
+ sources: [
62
+ {
63
+ ...dummySourceBase,
64
+ source_type: type,
65
+ },
66
+ ],
67
+ },
68
+ });
69
+ expect(findSourceIcons().at(0).props('name')).toBe(expectedIcon);
70
+ });
71
+
72
+ it.each`
73
+ sourceExtension | expectedTitle
74
+ ${{ title: 'Foo' }} | ${'Foo'}
75
+ ${{ source_type: DOCUMENTATION_SOURCE_TYPES.DOC.value }} | ${`${dummySourceBase.stage} / ${dummySourceBase.group}`}
76
+ ${{ source_type: DOCUMENTATION_SOURCE_TYPES.BLOG.value }} | ${`${dummySourceBase.date} / ${dummySourceBase.author}`}
77
+ ${{}} | ${'Source'}
78
+ `('renders the correct title for $sourceExtension', ({ sourceExtension, expectedTitle } = {}) => {
79
+ createComponent({
80
+ propsData: {
81
+ sources: [
82
+ {
83
+ ...dummySourceBase,
84
+ title: '',
85
+ ...sourceExtension,
86
+ },
87
+ ],
88
+ },
89
+ });
90
+ expect(findSourceTitles().at(0).text()).toBe(expectedTitle);
91
+ });
92
+ });
@@ -0,0 +1,32 @@
1
+ import { MOCK_RESPONSE_MESSAGE } from '../../mock_data';
2
+ import GlDuoChatMessageSources from './duo_chat_message_sources.vue';
3
+ import readme from './duo_chat_message_sources.md';
4
+
5
+ const generateProps = ({ sources = [] } = {}) => ({
6
+ sources,
7
+ });
8
+
9
+ const Template = (args, { argTypes }) => ({
10
+ components: { GlDuoChatMessageSources },
11
+ props: Object.keys(argTypes),
12
+ template: `
13
+ <gl-duo-chat-message-sources :sources="sources" />
14
+ `,
15
+ });
16
+
17
+ export const Default = Template.bind({});
18
+ Default.args = generateProps({
19
+ sources: MOCK_RESPONSE_MESSAGE.extras.sources,
20
+ });
21
+
22
+ export default {
23
+ title: 'experimental/duo/chat/duo_chat_message_sources',
24
+ component: GlDuoChatMessageSources,
25
+ parameters: {
26
+ docs: {
27
+ description: {
28
+ component: readme,
29
+ },
30
+ },
31
+ },
32
+ };
@@ -0,0 +1,80 @@
1
+ <script>
2
+ import { GlIcon, GlLink } from '../../../../../../index';
3
+ import { DOCUMENTATION_SOURCE_TYPES } from '../../constants';
4
+
5
+ export const i18n = {
6
+ MESSAGE_SOURCE: 'Source',
7
+ MESSAGE_SOURCES: 'Sources',
8
+ };
9
+
10
+ export default {
11
+ name: 'GlDuoChatMessageSources',
12
+ components: {
13
+ GlIcon,
14
+ GlLink,
15
+ },
16
+ props: {
17
+ /**
18
+ * The Array of the message sources.
19
+ */
20
+ sources: {
21
+ type: Array,
22
+ required: true,
23
+ },
24
+ },
25
+ computed: {
26
+ sourceLabel() {
27
+ return this.sources.length > 1 ? i18n.MESSAGE_SOURCES : i18n.MESSAGE_SOURCES;
28
+ },
29
+ },
30
+ methods: {
31
+ getSourceIcon(sourceType) {
32
+ const currentSourceType = Object.values(DOCUMENTATION_SOURCE_TYPES).find(
33
+ ({ value }) => value === sourceType
34
+ );
35
+
36
+ return currentSourceType?.icon || 'document';
37
+ },
38
+ getSourceTitle({ title, source_type: sourceType, stage, group, date, author }) {
39
+ if (title) {
40
+ return title;
41
+ }
42
+
43
+ if (sourceType === DOCUMENTATION_SOURCE_TYPES.DOC.value) {
44
+ if (stage && group) {
45
+ return `${stage} / ${group}`;
46
+ }
47
+ }
48
+
49
+ if (sourceType === DOCUMENTATION_SOURCE_TYPES.BLOG.value) {
50
+ if (date && author) {
51
+ return `${date} / ${author}`;
52
+ }
53
+ }
54
+
55
+ return i18n.MESSAGE_SOURCE;
56
+ },
57
+ },
58
+ };
59
+ </script>
60
+ <template>
61
+ <div class="gl-mt-4 gl-mr-3 gl-text-gray-600" data-testid="duo-chat-message-sources">
62
+ <span v-if="sources.length">{{ sourceLabel }}:</span>
63
+
64
+ <ul class="gl-list-style-none gl-p-0 gl-m-0">
65
+ <li
66
+ v-for="(source, index) in sources"
67
+ :key="index"
68
+ class="gl-display-flex gl-pt-3 gl-align-items-center"
69
+ data-testid="source-list-item"
70
+ >
71
+ <gl-icon
72
+ v-if="source.source_type"
73
+ :name="getSourceIcon(source.source_type)"
74
+ class="gl-flex-shrink-0 gl-mr-2"
75
+ />
76
+ <gl-link :href="source.source_url">{{ getSourceTitle(source) }}</gl-link>
77
+ </li>
78
+ </ul>
79
+ </div>
80
+ </template>
@@ -0,0 +1,20 @@
1
+ export const DOCUMENTATION_SOURCE_TYPES = {
2
+ HANDBOOK: {
3
+ value: 'handbook',
4
+ icon: 'book',
5
+ },
6
+ DOC: {
7
+ value: 'doc',
8
+ icon: 'documents',
9
+ },
10
+ BLOG: {
11
+ value: 'blog',
12
+ icon: 'list-bulleted',
13
+ },
14
+ };
15
+
16
+ export const MESSAGE_MODEL_ROLES = {
17
+ user: 'user',
18
+ system: 'system',
19
+ assistant: 'assistant',
20
+ };
@@ -0,0 +1,34 @@
1
+ import { DOCUMENTATION_SOURCE_TYPES, MESSAGE_MODEL_ROLES } from './constants';
2
+
3
+ const MOCK_SOURCES = [
4
+ {
5
+ title: 'GitLab Handbook',
6
+ source_type: DOCUMENTATION_SOURCE_TYPES.HANDBOOK.value,
7
+ source_url: '/handbook/',
8
+ },
9
+ {
10
+ stage: 'Mock Stage',
11
+ group: 'Mock Group',
12
+ source_type: DOCUMENTATION_SOURCE_TYPES.DOC.value,
13
+ source_url: '/company/team/',
14
+ },
15
+ {
16
+ date: '2023-04-21',
17
+ author: 'Test User',
18
+ source_type: DOCUMENTATION_SOURCE_TYPES.BLOG.value,
19
+ source_url: '/blog/',
20
+ },
21
+ ];
22
+
23
+ export const MOCK_RESPONSE_MESSAGE = {
24
+ id: '123',
25
+ content: '_Duo Chat message_ comming from AI',
26
+ contentHtml: '<p><em>Duo Chat message</em> comming from AI</p>',
27
+ role: MESSAGE_MODEL_ROLES.assistant,
28
+ extras: {
29
+ sources: MOCK_SOURCES,
30
+ },
31
+ requestId: '987',
32
+ errors: [],
33
+ timestamp: '2021-04-21T12:00:00.000Z',
34
+ };