@kiva/kv-components 3.54.0 → 3.55.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
@@ -3,6 +3,24 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.55.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.54.0...@kiva/kv-components@3.55.0) (2024-02-29)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * input width ([2489339](https://github.com/kiva/kv-ui-elements/commit/2489339c622ac45739bcc1eefc0a69837f90b841))
12
+ * when to send hide event and test not recognizing vue3 ([c3941a7](https://github.com/kiva/kv-ui-elements/commit/c3941a7a73a439846e6abf16b6dd0b29fa0e36f7))
13
+
14
+
15
+ ### Features
16
+
17
+ * adding input for comment reply ([b18edf0](https://github.com/kiva/kv-ui-elements/commit/b18edf0ecd300f622379d160237fd750cf117fa1))
18
+ * update tests and remove handleClick for emits ([fc3c586](https://github.com/kiva/kv-ui-elements/commit/fc3c58667248fb4e44bb0a7558f6c88f97f299b1))
19
+
20
+
21
+
22
+
23
+
6
24
  # [3.54.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.53.0...@kiva/kv-components@3.54.0) (2024-02-28)
7
25
 
8
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiva/kv-components",
3
- "version": "3.54.0",
3
+ "version": "3.55.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -75,5 +75,5 @@
75
75
  "optional": true
76
76
  }
77
77
  },
78
- "gitHead": "b29d4c7e40f229ac09c7f68c377741af7d068158"
78
+ "gitHead": "ecd01faa5db8db12e79b243f311a264616a23e7d"
79
79
  }
@@ -1,6 +1,6 @@
1
1
  import { render } from '@testing-library/vue';
2
2
  import userEvent from '@testing-library/user-event';
3
- import CommentsAdd, { ADD_COMMENT_EVENT } from '../../../../vue/KvCommentsAdd.vue';
3
+ import CommentsAdd, { ADD_COMMENT_EVENT, HIDE_INPUT_EVENT } from '../../../../vue/KvCommentsAdd.vue';
4
4
 
5
5
  const renderCommentsAdd = (props = {}) => {
6
6
  return render(CommentsAdd, { props });
@@ -71,4 +71,26 @@ describe('KvCommentsAdd', () => {
71
71
 
72
72
  expect(emitted()[ADD_COMMENT_EVENT]).toBe(undefined);
73
73
  });
74
+
75
+ it('should emit close event when it replies a comment', async () => {
76
+ const { getByRole, emitted, getByPlaceholderText } = renderCommentsAdd({ isReply: true });
77
+ const textInput = getByPlaceholderText('Add a comment to this loan...');
78
+ const commentButton = getByRole('button', { name: 'Comment' });
79
+ const TEST_INPUT = 'test test';
80
+
81
+ await userEvent.type(textInput, TEST_INPUT);
82
+
83
+ await userEvent.click(commentButton);
84
+
85
+ expect(emitted()[HIDE_INPUT_EVENT]).toEqual([[]]);
86
+ });
87
+
88
+ it('should emit close event when it clicks cancel on reply', async () => {
89
+ const { getByRole, emitted } = renderCommentsAdd({ isReply: true });
90
+ const cancelButton = getByRole('button', { name: 'Cancel' });
91
+
92
+ await userEvent.click(cancelButton);
93
+
94
+ expect(emitted()[HIDE_INPUT_EVENT]).toEqual([[]]);
95
+ });
74
96
  });
@@ -19,7 +19,7 @@ describe('KvCommentsList', () => {
19
19
  });
20
20
 
21
21
  it('should emit comment events', async () => {
22
- const { getAllByRole, emitted } = renderList({ comments });
22
+ const { getAllByRole, getByRole, emitted } = renderList({ comments });
23
23
  const replyButton = getAllByRole('button', { name: 'Reply' })[0];
24
24
  const likeButton = getAllByRole('button', { name: 'Like' })[0];
25
25
  const firstComment = comments.comment[0];
@@ -32,6 +32,7 @@ describe('KvCommentsList', () => {
32
32
 
33
33
  await userEvent.click(replyButton);
34
34
  expect(emitted()[REPLY_COMMENT_EVENT]).toEqual([[{ ...TEST_OBJ, reaction: REPLY_COMMENT_EVENT }]]);
35
+ getByRole('button', { name: 'Comment' });
35
36
 
36
37
  await userEvent.click(likeButton);
37
38
  expect(emitted()[LIKE_COMMENT_EVENT]).toEqual([[{ ...TEST_OBJ, reaction: LIKE_COMMENT_EVENT, value: true }]]);
@@ -1,12 +1,10 @@
1
1
  import { render } from '@testing-library/vue';
2
2
  import userEvent from '@testing-library/user-event';
3
- import KvCommentsListItem from '../../../../vue/KvCommentsListItem.vue';
3
+ import KvCommentsListItem, { LIKE_COMMENT_EVENT } from '../../../../vue/KvCommentsListItem.vue';
4
4
  import activityFeed from '../../../fixtures/mockFeedActivityData';
5
5
 
6
6
  const comment = activityFeed.results[0].latest_reactions.comment[0];
7
7
 
8
- const handleClick = jest.fn();
9
-
10
8
  const renderComment = (props = {}) => {
11
9
  return render(KvCommentsListItem, { props });
12
10
  };
@@ -24,20 +22,25 @@ describe('KvCommentsListItem', () => {
24
22
  });
25
23
 
26
24
  it('should handle like button click', async () => {
27
- const { getByRole } = renderComment({ comment, handleClick });
25
+ const { getByRole, emitted } = renderComment({ comment });
28
26
  const likeButton = getByRole('button', { name: 'Like' });
29
27
 
30
28
  await userEvent.click(likeButton);
31
29
 
32
- expect(handleClick).toHaveBeenCalledTimes(1);
30
+ expect(emitted()[LIKE_COMMENT_EVENT]).toEqual([[{
31
+ id: comment.id,
32
+ isChild: true,
33
+ reaction: LIKE_COMMENT_EVENT,
34
+ userId: comment.user_id,
35
+ value: true,
36
+ }]]);
33
37
  });
34
38
 
35
39
  it('should handle reply button click', async () => {
36
- const { getByRole } = renderComment({ comment, handleClick });
40
+ const { getByRole } = renderComment({ comment });
37
41
  const replyButton = getByRole('button', { name: 'Reply' });
38
42
 
39
43
  await userEvent.click(replyButton);
40
-
41
- expect(handleClick).toHaveBeenCalledTimes(1);
44
+ getByRole('button', { name: 'Comment' });
42
45
  });
43
46
  });
@@ -0,0 +1,23 @@
1
+ import { render } from '@testing-library/vue';
2
+ import userEvent from '@testing-library/user-event';
3
+ import KvCommentsReplyButton from '../../../../vue/KvCommentsReplyButton.vue';
4
+
5
+ const CLICK_EVENT = 'click';
6
+
7
+ describe('KvCommentsReplyButton', () => {
8
+ it('should render defaults', () => {
9
+ const { getByRole } = render(KvCommentsReplyButton);
10
+ const replyButton = getByRole('button', { name: 'Reply' });
11
+
12
+ expect(replyButton).toBeDefined();
13
+ });
14
+
15
+ it('should emit true value when clicked as not liked', async () => {
16
+ const { getByRole, emitted } = render(KvCommentsReplyButton);
17
+ const likeButton = getByRole('button', { name: 'Reply' });
18
+
19
+ await userEvent.click(likeButton);
20
+
21
+ expect(emitted()[CLICK_EVENT]).toEqual([[]]);
22
+ });
23
+ });
@@ -22,6 +22,7 @@
22
22
  </div>
23
23
  <kv-text-input
24
24
  :id="ADD_COMMENT_ID"
25
+ ref="input"
25
26
  v-model="addCommentValue"
26
27
  placeholder="Add a comment to this loan..."
27
28
  class="data-hj-suppress tw-grow"
@@ -53,6 +54,7 @@ import KvTextInput from './KvTextInput.vue';
53
54
 
54
55
  export const ADD_COMMENT_ID = 'add-comment-value';
55
56
  export const ADD_COMMENT_EVENT = 'add-comment';
57
+ export const HIDE_INPUT_EVENT = 'hide-input';
56
58
 
57
59
  export default {
58
60
  components: {
@@ -74,27 +76,45 @@ export default {
74
76
  type: String,
75
77
  default: '',
76
78
  },
79
+ /**
80
+ * Whether or not the comment is a reply
81
+ */
82
+ isReply: {
83
+ type: Boolean,
84
+ default: false,
85
+ },
77
86
  },
78
- emits: [ADD_COMMENT_EVENT],
79
- setup(_props, { emit }) {
87
+ emits: [ADD_COMMENT_EVENT, HIDE_INPUT_EVENT],
88
+ setup(props, { emit }) {
80
89
  const addCommentValue = ref('');
90
+ const input = ref(null);
81
91
 
82
92
  const commentButtonState = computed(() => (addCommentValue.value ? '' : 'disabled'));
83
93
 
84
94
  const cancel = () => {
85
95
  addCommentValue.value = '';
96
+ if (props.isReply) {
97
+ emit(HIDE_INPUT_EVENT);
98
+ }
86
99
  };
87
100
 
88
101
  const comment = () => {
89
102
  emit(ADD_COMMENT_EVENT, addCommentValue.value);
103
+ addCommentValue.value = '';
104
+ if (props.isReply) {
105
+ emit(HIDE_INPUT_EVENT);
106
+ }
90
107
  };
91
108
 
109
+ const focus = () => input.value.focus();
110
+
92
111
  return {
93
112
  ADD_COMMENT_ID,
94
113
  addCommentValue,
95
114
  commentButtonState,
96
115
  cancel,
97
116
  comment,
117
+ focus,
98
118
  };
99
119
  },
100
120
  };
@@ -7,7 +7,8 @@
7
7
  :nest-level="1"
8
8
  :comment="comment"
9
9
  :is-liked="comment.is_liked"
10
- :handle-click="handleClick"
10
+ @[REPLY_COMMENT_EVENT]="handleClick"
11
+ @[LIKE_COMMENT_EVENT]="handleClick"
11
12
  />
12
13
  </div>
13
14
  </template>
@@ -27,12 +28,16 @@ export default {
27
28
  default: () => {},
28
29
  },
29
30
  },
30
- methods: {
31
- handleClick(payload) {
32
- if ([REPLY_COMMENT_EVENT, LIKE_COMMENT_EVENT].includes(payload.reaction)) {
33
- this.$emit(payload.reaction, { ...payload });
34
- }
35
- },
31
+ setup(_props, { emit }) {
32
+ const handleClick = (payload) => {
33
+ emit(payload.reaction, { ...payload });
34
+ };
35
+
36
+ return {
37
+ handleClick,
38
+ REPLY_COMMENT_EVENT,
39
+ LIKE_COMMENT_EVENT,
40
+ };
36
41
  },
37
42
  };
38
43
  </script>
@@ -21,19 +21,29 @@
21
21
  {{ text }}
22
22
  </p>
23
23
  </div>
24
- <div class="tw-flex tw-items-center tw-gap-x-0.5">
24
+ <div
25
+ v-if="nestLevel < 3"
26
+ class="tw-flex tw-items-center tw-gap-x-2"
27
+ >
25
28
  <kv-comments-heart-button
26
29
  :is-small="true"
27
30
  :is-liked="isLiked"
28
31
  @click="onClick(LIKE_COMMENT_EVENT, $event)"
29
32
  />
30
- <kv-button
31
- variant="ghost"
32
- class="tw-font-medium"
33
- @click="onClick(REPLY_COMMENT_EVENT)"
34
- >
35
- Reply
36
- </kv-button>
33
+ <kv-comments-reply-button
34
+ @click="onClick(REPLY_COMMENT_EVENT, $event)"
35
+ />
36
+ </div>
37
+ <div
38
+ v-if="showInput"
39
+ class="tw-w-full"
40
+ >
41
+ <kv-comments-add
42
+ ref="commentsAddRef"
43
+ user-mention
44
+ @add-comment="onClick(REPLY_COMMENT_EVENT, $event)"
45
+ @hide-input="hideInput"
46
+ />
37
47
  </div>
38
48
  <div
39
49
  v-if="latestChildren"
@@ -56,8 +66,10 @@
56
66
  </template>
57
67
 
58
68
  <script>
59
- import KvButton from './KvButton.vue';
69
+ import { ref, nextTick } from 'vue-demi';
70
+ import KvCommentsReplyButton from './KvCommentsReplyButton.vue';
60
71
  import KvCommentsHeartButton from './KvCommentsHeartButton.vue';
72
+ import KvCommentsAdd from './KvCommentsAdd.vue';
61
73
 
62
74
  export const REPLY_COMMENT_EVENT = 'reply-comment';
63
75
  export const LIKE_COMMENT_EVENT = 'like-comment';
@@ -65,8 +77,9 @@ export const LIKE_COMMENT_EVENT = 'like-comment';
65
77
  export default {
66
78
  name: 'KvCommentsListItem',
67
79
  components: {
68
- KvButton,
80
+ KvCommentsReplyButton,
69
81
  KvCommentsHeartButton,
82
+ KvCommentsAdd,
70
83
  },
71
84
  props: {
72
85
  /**
@@ -90,17 +103,24 @@ export default {
90
103
  type: Boolean,
91
104
  default: false,
92
105
  },
93
- /**
94
- * The function to call when a reaction is clicked
95
- */
96
- handleClick: {
97
- type: Function,
98
- default: () => ({}),
99
- },
100
106
  },
101
- setup(props) {
107
+ emits: [
108
+ REPLY_COMMENT_EVENT,
109
+ LIKE_COMMENT_EVENT,
110
+ ],
111
+ setup(props, { emit }) {
112
+ const showInput = ref(false);
113
+ const commentsAddRef = ref(null);
114
+
102
115
  const onClick = (reaction, value) => {
103
- props.handleClick({
116
+ if (reaction === REPLY_COMMENT_EVENT) {
117
+ showInput.value = true;
118
+ nextTick(() => {
119
+ commentsAddRef.value.$refs.input.focus();
120
+ });
121
+ }
122
+
123
+ emit(reaction, {
104
124
  reaction,
105
125
  id: props.comment?.id ?? null,
106
126
  userId: props.comment?.user_id ?? null,
@@ -109,7 +129,12 @@ export default {
109
129
  });
110
130
  };
111
131
 
132
+ const hideInput = () => { showInput.value = false; };
133
+
112
134
  return {
135
+ hideInput,
136
+ showInput,
137
+ commentsAddRef,
113
138
  onClick,
114
139
  REPLY_COMMENT_EVENT,
115
140
  LIKE_COMMENT_EVENT,
@@ -0,0 +1,49 @@
1
+ <!-- eslint-disable max-len -->
2
+ <template>
3
+ <button
4
+ ref="replyButton"
5
+ aria-label="Reply"
6
+ class="tw-font-medium tw-flex tw-items-center tw-gap-x-0.5"
7
+ @click="handleClick"
8
+ >
9
+ <svg
10
+ width="14"
11
+ height="11"
12
+ viewBox="0 0 14 11"
13
+ fill="none"
14
+ xmlns="http://www.w3.org/2000/svg"
15
+ >
16
+ <path
17
+ d="M2.87502 5.12499L4.91669 7.16666C5.06946 7.31943 5.14585 7.49652 5.14585 7.69791C5.14585 7.8993 5.06946 8.0797 4.91669 8.23911C4.76391 8.38525 4.58683 8.45832 4.38544 8.45832C4.18405 8.45832 4.00696 8.38193 3.85419 8.22916L0.520854 4.89582C0.368076 4.7481 0.291687 4.57575 0.291687 4.37878C0.291687 4.18181 0.368076 4.00693 0.520854 3.85416L3.85419 0.520823C4.00696 0.368045 4.18521 0.291656 4.38892 0.291656C4.59261 0.291656 4.76853 0.368045 4.91669 0.520823C5.06946 0.668976 5.14585 0.8449 5.14585 1.04859C5.14585 1.2523 5.06946 1.43055 4.91669 1.58332L2.87502 3.62499H10C11.1067 3.62499 12.05 4.01499 12.83 4.79499C13.61 5.57499 14 6.51832 14 7.62499V9.87499C14 10.0875 13.9286 10.2656 13.7857 10.4094C13.6427 10.5531 13.4657 10.625 13.2544 10.625C13.0432 10.625 12.8646 10.5531 12.7188 10.4094C12.5729 10.2656 12.5 10.0875 12.5 9.87499V7.62499C12.5 6.93055 12.257 6.34027 11.7709 5.85416C11.2847 5.36805 10.6945 5.12499 10 5.12499H2.87502Z"
18
+ fill="#1C1B1F"
19
+ />
20
+ </svg>
21
+
22
+ <span>
23
+ Reply
24
+ </span>
25
+ </button>
26
+ </template>
27
+
28
+ <script>
29
+ import { ref } from 'vue-demi';
30
+
31
+ export default {
32
+ name: 'KvCommentsReplyButton',
33
+ emits: [
34
+ 'click',
35
+ ],
36
+ setup(_props, { emit }) {
37
+ const replyButton = ref(null);
38
+
39
+ const handleClick = () => {
40
+ emit('click');
41
+ };
42
+
43
+ return {
44
+ replyButton,
45
+ handleClick,
46
+ };
47
+ },
48
+ };
49
+ </script>