feat: Enable custom attributes in the suggestion for variables. (#8520)
This commit is contained in:
@@ -271,6 +271,11 @@ export default {
|
|||||||
accountId: 'getCurrentAccountId',
|
accountId: 'getCurrentAccountId',
|
||||||
isFeatureEnabledonAccount: 'accounts/isFeatureEnabledonAccount',
|
isFeatureEnabledonAccount: 'accounts/isFeatureEnabledonAccount',
|
||||||
}),
|
}),
|
||||||
|
currentContact() {
|
||||||
|
return this.$store.getters['contacts/getContact'](
|
||||||
|
this.currentChat.meta.sender.id
|
||||||
|
);
|
||||||
|
},
|
||||||
shouldShowReplyToMessage() {
|
shouldShowReplyToMessage() {
|
||||||
return (
|
return (
|
||||||
this.inReplyTo?.id &&
|
this.inReplyTo?.id &&
|
||||||
@@ -509,6 +514,7 @@ export default {
|
|||||||
messageVariables() {
|
messageVariables() {
|
||||||
const variables = getMessageVariables({
|
const variables = getMessageVariables({
|
||||||
conversation: this.currentChat,
|
conversation: this.currentChat,
|
||||||
|
contact: this.currentContact,
|
||||||
});
|
});
|
||||||
return variables;
|
return variables;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<mention-box :items="items" @mention-select="handleVariableClick">
|
<mention-box
|
||||||
|
type="variable"
|
||||||
|
:items="items"
|
||||||
|
@mention-select="handleVariableClick"
|
||||||
|
>
|
||||||
<template slot-scope="{ item }">
|
<template slot-scope="{ item }">
|
||||||
<span class="text-capitalize variable--list-label">
|
<span class="text-capitalize variable--list-label">
|
||||||
{{ item.description }}
|
{{ item.description }}
|
||||||
@@ -10,6 +14,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapGetters } from 'vuex';
|
||||||
import { MESSAGE_VARIABLES } from 'shared/constants/messages';
|
import { MESSAGE_VARIABLES } from 'shared/constants/messages';
|
||||||
import MentionBox from '../mentions/MentionBox.vue';
|
import MentionBox from '../mentions/MentionBox.vue';
|
||||||
|
|
||||||
@@ -22,7 +27,16 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
...mapGetters({
|
||||||
|
customAttributes: 'attributes/getAttributes',
|
||||||
|
}),
|
||||||
items() {
|
items() {
|
||||||
|
return [
|
||||||
|
...this.standardAttributeVariables,
|
||||||
|
...this.customAttributeVariables,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
standardAttributeVariables() {
|
||||||
return MESSAGE_VARIABLES.filter(variable => {
|
return MESSAGE_VARIABLES.filter(variable => {
|
||||||
return (
|
return (
|
||||||
variable.label.includes(this.searchKey) ||
|
variable.label.includes(this.searchKey) ||
|
||||||
@@ -34,6 +48,20 @@ export default {
|
|||||||
description: variable.label,
|
description: variable.label,
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
customAttributeVariables() {
|
||||||
|
return this.customAttributes.map(attribute => {
|
||||||
|
const attributePrefix =
|
||||||
|
attribute.attribute_model === 'conversation_attribute'
|
||||||
|
? 'conversation'
|
||||||
|
: 'contact';
|
||||||
|
|
||||||
|
return {
|
||||||
|
label: `${attributePrefix}.custom_attribute.${attribute.attribute_key}`,
|
||||||
|
key: `${attributePrefix}.custom_attribute.${attribute.attribute_key}`,
|
||||||
|
description: attribute.attribute_description,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleVariableClick(item = {}) {
|
handleVariableClick(item = {}) {
|
||||||
|
|||||||
@@ -1,20 +1,41 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="items.length" ref="mentionsListContainer" class="mention--box">
|
<div
|
||||||
|
v-if="items.length"
|
||||||
|
ref="mentionsListContainer"
|
||||||
|
class="bg-white dark:bg-slate-800 rounded-md overflow-auto absolute w-full z-20 pb-0 shadow-md left-0 bottom-full max-h-[9.75rem] border border-solid border-slate-100 dark:border-slate-700 mention--box"
|
||||||
|
>
|
||||||
<ul class="vertical dropdown menu">
|
<ul class="vertical dropdown menu">
|
||||||
<woot-dropdown-item
|
<woot-dropdown-item
|
||||||
v-for="(item, index) in items"
|
v-for="(item, index) in items"
|
||||||
:id="`mention-item-${index}`"
|
:id="`mention-item-${index}`"
|
||||||
:key="item.key"
|
:key="item.key"
|
||||||
|
class="!mb-0"
|
||||||
@mouseover="onHover(index)"
|
@mouseover="onHover(index)"
|
||||||
>
|
>
|
||||||
<woot-button
|
<button
|
||||||
class="canned-item__button"
|
class="flex group flex-col gap-0.5 overflow-hidden cursor-pointer items-start py-2.5 px-2.5 justify-center w-full h-full text-left hover:bg-woot-50 dark:hover:bg-woot-800 border-b border-solid border-slate-100 dark:border-slate-700"
|
||||||
:variant="index === selectedIndex ? '' : 'clear'"
|
:class="{
|
||||||
:class="{ active: index === selectedIndex }"
|
' bg-woot-25 dark:bg-woot-800': index === selectedIndex,
|
||||||
|
}"
|
||||||
@click="onListItemSelection(index)"
|
@click="onListItemSelection(index)"
|
||||||
>
|
>
|
||||||
<strong>{{ item.label }}</strong> - {{ item.description }}
|
<p
|
||||||
</woot-button>
|
class="text-slate-900 dark:text-slate-100 group-hover:text-woot-500 dark:group-hover:text-woot-500 font-medium mb-0 text-sm overflow-hidden text-ellipsis whitespace-nowrap min-w-0 max-w-full"
|
||||||
|
:class="{
|
||||||
|
'text-woot-500 dark:text-woot-500': index === selectedIndex,
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ item.description }}
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
class="text-slate-500 dark:text-slate-300 group-hover:text-woot-500 dark:group-hover:text-woot-500 mb-0 text-xs overflow-hidden text-ellipsis whitespace-nowrap min-w-0 max-w-full"
|
||||||
|
:class="{
|
||||||
|
'text-woot-500 dark:text-woot-500': index === selectedIndex,
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ variableKey(item) }}
|
||||||
|
</p>
|
||||||
|
</button>
|
||||||
</woot-dropdown-item>
|
</woot-dropdown-item>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -29,6 +50,10 @@ export default {
|
|||||||
type: Array,
|
type: Array,
|
||||||
default: () => {},
|
default: () => {},
|
||||||
},
|
},
|
||||||
|
type: {
|
||||||
|
type: String,
|
||||||
|
default: 'canned',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -73,28 +98,17 @@ export default {
|
|||||||
onSelect() {
|
onSelect() {
|
||||||
this.$emit('mention-select', this.items[this.selectedIndex]);
|
this.$emit('mention-select', this.items[this.selectedIndex]);
|
||||||
},
|
},
|
||||||
|
variableKey(item = {}) {
|
||||||
|
return this.type === 'variable' ? `{{${item.label}}}` : `/${item.label}`;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.mention--box {
|
.mention--box {
|
||||||
@apply bg-white dark:bg-slate-700 rounded-md overflow-auto absolute w-full z-20 pt-2 px-2 pb-0 shadow-md left-0 bottom-full max-h-[9.75rem] border-t border-solid border-slate-75 dark:border-slate-800;
|
.dropdown-menu__item:last-child > button {
|
||||||
|
@apply border-0;
|
||||||
.dropdown-menu__item:last-child {
|
|
||||||
@apply pb-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.active {
|
|
||||||
@apply text-white dark:text-white;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
@apply bg-woot-700 dark:bg-woot-700;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.button {
|
|
||||||
@apply transition-none h-8 leading-[1.4];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@braid/vue-formulate": "^2.5.2",
|
"@braid/vue-formulate": "^2.5.2",
|
||||||
"@chatwoot/prosemirror-schema": "1.0.3",
|
"@chatwoot/prosemirror-schema": "1.0.3",
|
||||||
"@chatwoot/utils": "^0.0.16",
|
"@chatwoot/utils": "^0.0.20",
|
||||||
"@hcaptcha/vue-hcaptcha": "^0.3.2",
|
"@hcaptcha/vue-hcaptcha": "^0.3.2",
|
||||||
"@june-so/analytics-next": "^1.36.5",
|
"@june-so/analytics-next": "^1.36.5",
|
||||||
"@radix-ui/colors": "^1.0.1",
|
"@radix-ui/colors": "^1.0.1",
|
||||||
@@ -169,4 +169,4 @@
|
|||||||
"scss-lint"
|
"scss-lint"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3177,10 +3177,10 @@
|
|||||||
prosemirror-utils "^0.9.6"
|
prosemirror-utils "^0.9.6"
|
||||||
prosemirror-view "^1.17.2"
|
prosemirror-view "^1.17.2"
|
||||||
|
|
||||||
"@chatwoot/utils@^0.0.16":
|
"@chatwoot/utils@^0.0.20":
|
||||||
version "0.0.16"
|
version "0.0.20"
|
||||||
resolved "https://registry.yarnpkg.com/@chatwoot/utils/-/utils-0.0.16.tgz#84a0ade7f0377a3c7a95b2e5fa3c3b3d7d045339"
|
resolved "https://registry.yarnpkg.com/@chatwoot/utils/-/utils-0.0.20.tgz#d7cb407da434efcce4262178dbef55441f218489"
|
||||||
integrity sha512-PcWEJ+LeJlDkjOOCHyi7wLaaBsPpedDh1jBblkqOYnt8PvKHSttq/Fusi6u6EcxPhIw1umgq5A/k8sWozmZ4iQ==
|
integrity sha512-rChMLxxbtzDpS2wePhnsdu+NDfRWbV+9Jw9eZ34jQRxkQ4LYVUoj6z5gC7a5+3izZQZ1XEwDSPHIiIvIUX4tzg==
|
||||||
dependencies:
|
dependencies:
|
||||||
date-fns "^2.29.1"
|
date-fns "^2.29.1"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user