Skip to content

Commit

Permalink
fix: chat name computations [WTEL-5553](https://webitel.atlassian.net…
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Nov 19, 2024
1 parent 98054d2 commit 289d10a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
12 changes: 11 additions & 1 deletion src/ui/mixins/displayInfoMixin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
export default {
computed: {
displayChatName() {
return this.task && this.task?.members?.map((member) => member.name).join(', ');
const chat = this.chat || this.task;

if (this.contact?.name) {
return this.contact.name;
}

if (chat?.members?.length) {
return chat?.members?.map((member) => member.name).join(', ');
}

return chat.title;

Check failure on line 14 in src/ui/mixins/displayInfoMixin.js

View workflow job for this annotation

GitHub Actions / test

src/ui/modules/work-section/modules/chat/chat-header/__tests__/chat-header.spec.js > Chat Header > renders a component

TypeError: Cannot read properties of undefined (reading 'title') ❯ Proxy.displayChatName src/ui/mixins/displayInfoMixin.js:14:19 ❯ ReactiveEffect.fn node_modules/@vue/reactivity/dist/reactivity.cjs.js:996:13 ❯ ReactiveEffect.run node_modules/@vue/reactivity/dist/reactivity.cjs.js:180:19 ❯ ComputedRefImpl.get value [as value] node_modules/@vue/reactivity/dist/reactivity.cjs.js:1007:68 ❯ Object.get [as displayChatName] node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3514:22 ❯ Object.get node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3074:19 ❯ Proxy._sfc_render src/ui/modules/work-section/modules/chat/chat-header/chat-header.vue:4:16 ❯ renderComponentRoot node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:874:16 ❯ ReactiveEffect.componentUpdateFn [as fn] node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5941:46 ❯ ReactiveEffect.run node_modules/@vue/reactivity/dist/reactivity.cjs.js:180:19

Check failure on line 14 in src/ui/mixins/displayInfoMixin.js

View workflow job for this annotation

GitHub Actions / test

src/ui/modules/work-section/modules/chat/chat-header/__tests__/chat-header.spec.js > Chat Header > $emits openTab event at transfer button click

TypeError: Cannot read properties of undefined (reading 'title') ❯ Proxy.displayChatName src/ui/mixins/displayInfoMixin.js:14:19 ❯ ReactiveEffect.fn node_modules/@vue/reactivity/dist/reactivity.cjs.js:996:13 ❯ ReactiveEffect.run node_modules/@vue/reactivity/dist/reactivity.cjs.js:180:19 ❯ ComputedRefImpl.get value [as value] node_modules/@vue/reactivity/dist/reactivity.cjs.js:1007:68 ❯ Object.get [as displayChatName] node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3514:22 ❯ Object.get node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3074:19 ❯ Proxy._sfc_render src/ui/modules/work-section/modules/chat/chat-header/chat-header.vue:4:16 ❯ renderComponentRoot node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:874:16 ❯ ReactiveEffect.componentUpdateFn [as fn] node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5941:46 ❯ ReactiveEffect.run node_modules/@vue/reactivity/dist/reactivity.cjs.js:180:19

Check failure on line 14 in src/ui/mixins/displayInfoMixin.js

View workflow job for this annotation

GitHub Actions / test

src/ui/modules/work-section/modules/chat/chat-header/__tests__/chat-header.spec.js > Chat Header > calls close() method at close chat button click

TypeError: Cannot read properties of undefined (reading 'title') ❯ Proxy.displayChatName src/ui/mixins/displayInfoMixin.js:14:19 ❯ ReactiveEffect.fn node_modules/@vue/reactivity/dist/reactivity.cjs.js:996:13 ❯ ReactiveEffect.run node_modules/@vue/reactivity/dist/reactivity.cjs.js:180:19 ❯ ComputedRefImpl.get value [as value] node_modules/@vue/reactivity/dist/reactivity.cjs.js:1007:68 ❯ Object.get [as displayChatName] node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3514:22 ❯ Object.get node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3074:19 ❯ Proxy._sfc_render src/ui/modules/work-section/modules/chat/chat-header/chat-header.vue:4:16 ❯ renderComponentRoot node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:874:16 ❯ ReactiveEffect.componentUpdateFn [as fn] node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:5941:46 ❯ ReactiveEffect.run node_modules/@vue/reactivity/dist/reactivity.cjs.js:180:19
},
displayName() {
return (this.task || this.call)?.displayName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<task-header :size="size" :username="contact?.name">
<task-header
:size="size"
:username="displayChatName"
>
<template v-slot:after-avatar>
<wt-rounded-action
v-show="isTransferAction"
Expand All @@ -21,24 +24,25 @@
v-if="contact?.id"
:href="contactLink(contact?.id)"
class="chat-header-title"
target="_blank">
{{ contact?.name }}
target="_blank"
>
{{ displayChatName }}
</a>
<span v-else>
{{ title }}
{{ displayChatName }}
</span>
</template>
</task-header>
</template>

<script>
import { mapActions, mapGetters, mapState } from 'vuex';
import displayInfoMixin from '../../../../../mixins/displayInfoMixin.js';
import sizeMixin from '../../../../../../app/mixins/sizeMixin.js';
import TaskHeader from '../../_shared/components/task-header/task-header.vue';
import ChatHeaderCloseAction from './chat-header-close-action.vue';
import HotkeyAction from '../../../../../hotkeys/HotkeysActiom.enum.js';
import { useHotkeys } from '../../../../../hotkeys/useHotkeys.js';
import displayInfoMixin from '../../../../../mixins/displayInfoMixin.js';
import TaskHeader from '../../_shared/components/task-header/task-header.vue';
import ChatHeaderCloseAction from './chat-header-close-action.vue';
export default {
name: 'chat-header',
Expand All @@ -48,7 +52,7 @@ export default {
ChatHeaderCloseAction,
},
data: () => ({
hotkeyUnsubscribers : [],
hotkeyUnsubscribers: [],
}),
computed: {
...mapState('ui/infoSec/client/contact', {
Expand All @@ -62,18 +66,13 @@ export default {
...mapGetters('ui/infoSec/client/contact', {
contactLink: 'CONTACT_LINK',
}),
title() {
return this.chat?.members
? this.chat?.members[this.chat?.members?.length - 1]?.name
: this.chat?.title;
},
},
methods: {
...mapActions('features/chat', {
close: 'CLOSE',
}),
openTab() {
this.$emit('openTab', 'transfer')
this.$emit('openTab', 'transfer');
},
setupHotkeys() {
const subscripers = [
Expand All @@ -85,17 +84,17 @@ export default {
event: HotkeyAction.TRANSFER,
callback: () => {
if (this.isTransferAction) this.openTab();
}
}
},
},
];
this.hotkeyUnsubscribers = useHotkeys(subscripers);
this.hotkeyUnsubscribers = useHotkeys(subscripers);
},
},
mounted() {
this.setupHotkeys();
},
unmounted() {
this.hotkeyUnsubscribers .forEach((unsubscribe) => unsubscribe());
this.hotkeyUnsubscribers.forEach((unsubscribe) => unsubscribe());
},
};
</script>
Expand All @@ -104,6 +103,7 @@ export default {
.chat-header-title {
color: var(--text-main-color);
}
a:hover {
text-decoration: underline;
}
Expand Down

0 comments on commit 289d10a

Please sign in to comment.