@kiva/kv-components 3.56.1 → 3.58.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 +32 -0
- package/package.json +2 -2
- package/tests/fixtures/mockFeedActivityData.js +4 -1
- package/tests/unit/specs/components/KvCommentsListItem.spec.js +3 -1
- package/tests/unit/specs/utils/imageUtils.spec.js +29 -0
- package/utils/imageUtils.js +43 -0
- package/vue/KvCommentsList.vue +1 -1
- package/vue/KvCommentsListItem.vue +16 -5
- package/vue/KvUserAvatar.vue +132 -0
- package/vue/stories/KvUserAvatar.stories.js +47 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
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.58.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.57.0...@kiva/kv-components@3.58.0) (2024-03-01)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* fallback to kiva logo if no image or name ([74cdc90](https://github.com/kiva/kv-ui-elements/commit/74cdc900a8c1f9783771a7428f2722f59f5edf09))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* port avatar component from cps to cover different avatar situations ([036506f](https://github.com/kiva/kv-ui-elements/commit/036506f7680646c8e432af1842fb55851a5c6b2c))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [3.57.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.56.1...@kiva/kv-components@3.57.0) (2024-03-01)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* test failed because of whitespaces in value ([4591e93](https://github.com/kiva/kv-ui-elements/commit/4591e932a9c785f97019f47a8d7899142b2c1204))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* show number of likes ([c088fae](https://github.com/kiva/kv-ui-elements/commit/c088fae443da391871ef1783e64712d306b84007))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
## [3.56.1](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.56.0...@kiva/kv-components@3.56.1) (2024-03-01)
|
|
7
39
|
|
|
8
40
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiva/kv-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.58.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": "
|
|
78
|
+
"gitHead": "b2375c3684b25f0b94ed8cda48e2871564467ce4"
|
|
79
79
|
}
|
|
@@ -26,11 +26,13 @@ describe('KvCommentsListItem', () => {
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
it('should handle like button click', async () => {
|
|
29
|
-
const { getAllByRole, emitted } = renderComment({ comment });
|
|
29
|
+
const { getAllByRole, emitted, getByTestId } = renderComment({ comment });
|
|
30
30
|
const likeButton = getAllByRole('button', { name: 'Like' })[0];
|
|
31
|
+
const likeCount = getByTestId('like-count');
|
|
31
32
|
|
|
32
33
|
await userEvent.click(likeButton);
|
|
33
34
|
|
|
35
|
+
expect(likeCount).toHaveTextContent(1);
|
|
34
36
|
expect(emitted()[ADD_REACTION_EVENT]).toEqual([[{
|
|
35
37
|
id: comment.id,
|
|
36
38
|
isChild: true,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isLegacyPlaceholderAvatar, randomizedUserAvatarClass } from '../../../../utils/imageUtils';
|
|
2
|
+
|
|
3
|
+
describe('imageUtils.ts', () => {
|
|
4
|
+
describe('isLegacyPlaceholderAvatar', () => {
|
|
5
|
+
it('should return true when filename is default kiva user avatar.', () => {
|
|
6
|
+
expect(isLegacyPlaceholderAvatar('726677.jpg')).toBe(true);
|
|
7
|
+
expect(isLegacyPlaceholderAvatar('315726.jpg')).toBe(true);
|
|
8
|
+
expect(isLegacyPlaceholderAvatar('4d844ac2c0b77a8a522741b908ea5c32.jpg')).toBe(true);
|
|
9
|
+
expect(isLegacyPlaceholderAvatar('726677.png')).toBe(true);
|
|
10
|
+
expect(isLegacyPlaceholderAvatar('315726.gif')).toBe(true);
|
|
11
|
+
expect(isLegacyPlaceholderAvatar('4d844ac2c0b77a8a522741b908ea5c32.png')).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should return false when filename is not default kiva user avatar.', () => {
|
|
15
|
+
expect(isLegacyPlaceholderAvatar('')).toBe(false);
|
|
16
|
+
expect(isLegacyPlaceholderAvatar('test')).toBe(false);
|
|
17
|
+
expect(isLegacyPlaceholderAvatar('123abc.jpg')).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('randomizedUserAvatarClass', () => {
|
|
22
|
+
it('should return random classes', () => {
|
|
23
|
+
const class1 = randomizedUserAvatarClass();
|
|
24
|
+
|
|
25
|
+
expect(class1).toContain('tw-text-');
|
|
26
|
+
expect(class1).toContain('tw-bg-');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the users avatar is the default legacy placeholder image from the monolith.
|
|
3
|
+
* The legacy avatars are found exclusively at the following urls:
|
|
4
|
+
* <domain>/img/<size param>/726677.jpg
|
|
5
|
+
* <domain>/img/<size param>/315726.jpg
|
|
6
|
+
* for images from Fastly, urls, like: <domain>/img/s100/4d844ac2c0b77a8a522741b908ea5c32.jpg
|
|
7
|
+
* are the default placeholder image.
|
|
8
|
+
*
|
|
9
|
+
* @param filename The filename of the avatar
|
|
10
|
+
* @returns Whether the file is a legacy placeholder image
|
|
11
|
+
*/
|
|
12
|
+
export function isLegacyPlaceholderAvatar(filename) {
|
|
13
|
+
// if filename is empty or undefined, return false
|
|
14
|
+
if (!filename) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
// convert filename to string if it is a number
|
|
18
|
+
let filenameCleaned = filename.toString();
|
|
19
|
+
// remove file extension from filename if it exists
|
|
20
|
+
if (filenameCleaned.includes('.')) {
|
|
21
|
+
[filenameCleaned] = filenameCleaned.split('.');
|
|
22
|
+
}
|
|
23
|
+
const defaultProfileIds = ['726677', '315726', '4d844ac2c0b77a8a522741b908ea5c32'];
|
|
24
|
+
return defaultProfileIds.includes(filenameCleaned);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns a class string to style a user avatar
|
|
29
|
+
* @returns Random user avatar class string
|
|
30
|
+
*/
|
|
31
|
+
export function randomizedUserAvatarClass() {
|
|
32
|
+
const userCardStyleOptions = [
|
|
33
|
+
{ color: 'tw-text-action', bg: 'tw-bg-brand-100' },
|
|
34
|
+
{ color: 'tw-text-black', bg: 'tw-bg-brand-100' },
|
|
35
|
+
{ color: 'tw-text-white', bg: 'tw-bg-action' },
|
|
36
|
+
{ color: 'tw-text-brand-100', bg: 'tw-bg-action' },
|
|
37
|
+
{ color: 'tw-text-primary-inverse', bg: 'tw-bg-action' },
|
|
38
|
+
{ color: 'tw-text-white', bg: 'tw-bg-black' },
|
|
39
|
+
{ color: 'tw-text-action', bg: 'tw-bg-black' },
|
|
40
|
+
];
|
|
41
|
+
const randomStyle = userCardStyleOptions[Math.floor(Math.random() * userCardStyleOptions.length)];
|
|
42
|
+
return `${randomStyle.color} ${randomStyle.bg}`;
|
|
43
|
+
}
|
package/vue/KvCommentsList.vue
CHANGED
|
@@ -31,11 +31,19 @@
|
|
|
31
31
|
v-if="nestLevel < 3"
|
|
32
32
|
class="tw-flex tw-items-center tw-gap-x-2"
|
|
33
33
|
>
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
<div class="tw-flex tw-items-center tw-gap-0.5">
|
|
35
|
+
<kv-comments-heart-button
|
|
36
|
+
:is-small="true"
|
|
37
|
+
:is-liked="isLiked"
|
|
38
|
+
@click="addReaction(LIKE_COMMENT_EVENT, $event)"
|
|
39
|
+
/>
|
|
40
|
+
<p
|
|
41
|
+
v-if="numberOfLikes"
|
|
42
|
+
data-testid="like-count"
|
|
43
|
+
>
|
|
44
|
+
{{ numberOfLikes }}
|
|
45
|
+
</p>
|
|
46
|
+
</div>
|
|
39
47
|
<kv-comments-reply-button
|
|
40
48
|
@click="replyClick"
|
|
41
49
|
/>
|
|
@@ -178,6 +186,8 @@ export default {
|
|
|
178
186
|
|
|
179
187
|
const hideInput = () => { showInput.value = false; };
|
|
180
188
|
|
|
189
|
+
const numberOfLikes = computed(() => comment?.value?.children_counts?.like ?? 0);
|
|
190
|
+
|
|
181
191
|
return {
|
|
182
192
|
hideInput,
|
|
183
193
|
showInput,
|
|
@@ -192,6 +202,7 @@ export default {
|
|
|
192
202
|
authorName,
|
|
193
203
|
childComments,
|
|
194
204
|
isLiked,
|
|
205
|
+
numberOfLikes,
|
|
195
206
|
};
|
|
196
207
|
},
|
|
197
208
|
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="data-hj-suppress"
|
|
4
|
+
:class="{ 'tw-w-3': isSmall, 'tw-w-6': !isSmall }"
|
|
5
|
+
>
|
|
6
|
+
<!-- User is anonymous or data is missing -->
|
|
7
|
+
<div
|
|
8
|
+
v-if="isAnonymousUser"
|
|
9
|
+
class="
|
|
10
|
+
tw-rounded-full
|
|
11
|
+
tw-bg-brand
|
|
12
|
+
tw-inline-flex tw-align-center tw-justify-center
|
|
13
|
+
"
|
|
14
|
+
:class="{ 'tw-w-3 tw-h-3': isSmall, 'tw-w-6 tw-h-6': !isSmall }"
|
|
15
|
+
>
|
|
16
|
+
<!-- Kiva K logo -->
|
|
17
|
+
<!-- eslint-disable max-len -->
|
|
18
|
+
<svg
|
|
19
|
+
class="tw-h-full tw-text-brand"
|
|
20
|
+
:class="{ 'tw-w-3 tw-h-3': isSmall }"
|
|
21
|
+
width="25"
|
|
22
|
+
height="37"
|
|
23
|
+
viewBox="0 0 25 37"
|
|
24
|
+
fill="none"
|
|
25
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
26
|
+
>
|
|
27
|
+
<path
|
|
28
|
+
d="M8.22861 0.875H0.857178V36.3125H8.22861V0.875Z"
|
|
29
|
+
fill="white"
|
|
30
|
+
/>
|
|
31
|
+
<path
|
|
32
|
+
d="M10.1143 23.2751C21.9428 23.2751 24.6857 13.2126 24.6857 11.4626H23.6571C11.8286 11.4626 9.08569 21.5251 9.08569 23.2751H10.1143Z"
|
|
33
|
+
fill="white"
|
|
34
|
+
/>
|
|
35
|
+
<path
|
|
36
|
+
d="M9.08569 24.2376C9.08569 26.0751 11.1428 36.3126 23.8285 36.3126H24.8571C24.8571 34.4751 22.8 24.2376 10.1143 24.2376H9.08569Z"
|
|
37
|
+
fill="white"
|
|
38
|
+
/>
|
|
39
|
+
</svg>
|
|
40
|
+
<!-- eslint-enable max-len -->
|
|
41
|
+
</div>
|
|
42
|
+
<!-- User is not anonymous and has an image -->
|
|
43
|
+
<div
|
|
44
|
+
v-else-if="!isLegacyPlaceholderAvatar(imageFilename) && imageFilename"
|
|
45
|
+
>
|
|
46
|
+
<img
|
|
47
|
+
:src="lenderImageUrl"
|
|
48
|
+
alt="Image of lender"
|
|
49
|
+
class="tw-rounded-full tw-inline-block"
|
|
50
|
+
:class="{ 'tw-w-3 tw-h-3': isSmall, 'tw-w-6 tw-h-6': !isSmall }"
|
|
51
|
+
>
|
|
52
|
+
</div>
|
|
53
|
+
<!-- User is not anonymous and does not have an image -->
|
|
54
|
+
<div
|
|
55
|
+
v-else-if="isLegacyPlaceholderAvatar(imageFilename) || !imageFilename"
|
|
56
|
+
class="
|
|
57
|
+
tw-rounded-full
|
|
58
|
+
tw-inline-flex tw-align-center tw-justify-center
|
|
59
|
+
"
|
|
60
|
+
:class="avatarClass()"
|
|
61
|
+
>
|
|
62
|
+
<!-- First Letter of lender name -->
|
|
63
|
+
<span class="tw-self-center">
|
|
64
|
+
{{ lenderNameFirstLetter }}
|
|
65
|
+
</span>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</template>
|
|
69
|
+
|
|
70
|
+
<script>
|
|
71
|
+
import { computed, toRefs } from 'vue-demi';
|
|
72
|
+
import { isLegacyPlaceholderAvatar, randomizedUserAvatarClass } from '../utils/imageUtils';
|
|
73
|
+
|
|
74
|
+
export default {
|
|
75
|
+
name: 'KvUserAvatar',
|
|
76
|
+
props: {
|
|
77
|
+
/**
|
|
78
|
+
* The name of the lender
|
|
79
|
+
*/
|
|
80
|
+
lenderName: {
|
|
81
|
+
type: String,
|
|
82
|
+
default: '',
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* The image of the lender
|
|
86
|
+
*/
|
|
87
|
+
lenderImageUrl: {
|
|
88
|
+
type: String,
|
|
89
|
+
default: '',
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* The image of the lender
|
|
93
|
+
*/
|
|
94
|
+
isSmall: {
|
|
95
|
+
type: Boolean,
|
|
96
|
+
default: false,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
setup(props) {
|
|
100
|
+
const {
|
|
101
|
+
lenderName,
|
|
102
|
+
lenderImageUrl,
|
|
103
|
+
isSmall,
|
|
104
|
+
} = toRefs(props);
|
|
105
|
+
|
|
106
|
+
const isAnonymousUser = computed(() => {
|
|
107
|
+
return (lenderName.value === '' && lenderImageUrl.value === '') || lenderName.value === 'Anonymous';
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const avatarClass = () => {
|
|
111
|
+
const smallClass = isSmall?.value ? 'tw-w-3 tw-h-3 tw-text-h4' : 'tw-w-6 tw-h-6 tw-text-h2';
|
|
112
|
+
return `${randomizedUserAvatarClass()} ${smallClass}`;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const imageFilename = computed(() => {
|
|
116
|
+
return lenderImageUrl?.value?.split('/').pop() ?? '';
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const lenderNameFirstLetter = computed(() => {
|
|
120
|
+
return lenderName?.value?.substring(0, 1).toUpperCase();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
isAnonymousUser,
|
|
125
|
+
avatarClass,
|
|
126
|
+
imageFilename,
|
|
127
|
+
lenderNameFirstLetter,
|
|
128
|
+
isLegacyPlaceholderAvatar,
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
</script>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import KvUserAvatar from '../KvUserAvatar.vue';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: 'KvUserAvatar',
|
|
5
|
+
component: KvUserAvatar,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const story = (args) => {
|
|
9
|
+
const template = (templateArgs, { argTypes }) => ({
|
|
10
|
+
props: Object.keys(argTypes),
|
|
11
|
+
components: { KvUserAvatar },
|
|
12
|
+
setup() { return { args: templateArgs }; },
|
|
13
|
+
template: `
|
|
14
|
+
<KvUserAvatar v-bind="args" />
|
|
15
|
+
`,
|
|
16
|
+
});
|
|
17
|
+
template.args = args;
|
|
18
|
+
return template;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const Default = story({
|
|
22
|
+
lenderImageUrl: 'https://www.development.kiva.org/img/s100/26e15431f51b540f31cd9f011cc54f31.jpg',
|
|
23
|
+
lenderName: 'Roger',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const NoImage = story({
|
|
27
|
+
lenderImageUrl: '',
|
|
28
|
+
lenderName: 'Roger',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const Anonymous = story({
|
|
32
|
+
lenderImageUrl: 'https://www.development.kiva.org/img/s100/26e15431f51b540f31cd9f011cc54f31.jpg',
|
|
33
|
+
lenderName: 'Anonymous',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const DefaultProfile = story({
|
|
37
|
+
lenderImageUrl: 'https://www.development.kiva.org/img/s100/4d844ac2c0b77a8a522741b908ea5c32.jpg',
|
|
38
|
+
lenderName: 'Default Profile',
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const IsSmall = story({
|
|
42
|
+
lenderImageUrl: 'https://www.development.kiva.org/img/s100/26e15431f51b540f31cd9f011cc54f31.jpg',
|
|
43
|
+
lenderName: 'Roger',
|
|
44
|
+
isSmall: true,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const Fallback = story();
|