mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 03:57:52 +00:00
# Pull Request Template
## Description
This PR fixes an issue where typing variables, like `{{contact.name}}`,
caused the variable list to miss showing `contact.name`. The search key
in this case became `contact.name}},` which didn't match any available
options. The logic in `VariableList.vue` only checked the part after the
last comma and didn’t fully sanitize the input.
**Solution**
Updated `searchKey` to remove all {} and commas for accurate matching.
Fixes
[CW-4574](https://linear.app/chatwoot/issue/CW-4574/i-dont-see-an-option-for-contactname-it-shows-initially-but-it-doesnt)
## Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
## How Has This Been Tested?
### Loom video
https://www.loom.com/share/fc86e53853ad49e6acf6de57ebbd8fcb?sid=6702f896-d1a3-4c5a-9eb7-b96b5ed91531
## Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [x] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
99 lines
2.3 KiB
JavaScript
99 lines
2.3 KiB
JavaScript
/* eslint no-param-reassign: 0 */
|
|
|
|
import getUuid from 'widget/helpers/uuid';
|
|
import { MESSAGE_STATUS, MESSAGE_TYPE } from 'shared/constants/messages';
|
|
|
|
export default () => {
|
|
if (!Array.prototype.last) {
|
|
Object.assign(Array.prototype, {
|
|
last() {
|
|
return this[this.length - 1];
|
|
},
|
|
});
|
|
}
|
|
};
|
|
|
|
export const isEmptyObject = obj =>
|
|
Object.keys(obj).length === 0 && obj.constructor === Object;
|
|
|
|
export const isJSONValid = value => {
|
|
try {
|
|
JSON.parse(value);
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
export const getTypingUsersText = (users = []) => {
|
|
const count = users.length;
|
|
const [firstUser, secondUser] = users;
|
|
|
|
if (count === 1) {
|
|
return ['TYPING.ONE', { user: firstUser.name }];
|
|
}
|
|
|
|
if (count === 2) {
|
|
return [
|
|
'TYPING.TWO',
|
|
{ user: firstUser.name, secondUser: secondUser.name },
|
|
];
|
|
}
|
|
|
|
return ['TYPING.MULTIPLE', { user: firstUser.name, count: count - 1 }];
|
|
};
|
|
|
|
export const createPendingMessage = data => {
|
|
const timestamp = Math.floor(new Date().getTime() / 1000);
|
|
const tempMessageId = getUuid();
|
|
const { message, file } = data;
|
|
const tempAttachments = [{ id: tempMessageId }];
|
|
const pendingMessage = {
|
|
...data,
|
|
content: message || null,
|
|
id: tempMessageId,
|
|
echo_id: tempMessageId,
|
|
status: MESSAGE_STATUS.PROGRESS,
|
|
created_at: timestamp,
|
|
message_type: MESSAGE_TYPE.OUTGOING,
|
|
conversation_id: data.conversationId,
|
|
attachments: file ? tempAttachments : null,
|
|
};
|
|
|
|
return pendingMessage;
|
|
};
|
|
|
|
export const convertToAttributeSlug = text => {
|
|
return text
|
|
.toLowerCase()
|
|
.replace(/[^\w ]+/g, '')
|
|
.replace(/ +/g, '_');
|
|
};
|
|
|
|
export const convertToCategorySlug = text => {
|
|
return text
|
|
.toLowerCase()
|
|
.replace(/[^\w ]+/g, '')
|
|
.replace(/ +/g, '-');
|
|
};
|
|
|
|
export const convertToPortalSlug = text => {
|
|
return text
|
|
.toLowerCase()
|
|
.replace(/[^\w ]+/g, '')
|
|
.replace(/ +/g, '-');
|
|
};
|
|
|
|
/**
|
|
* Strip curly braces, commas and leading/trailing whitespace from a search key.
|
|
* Eg. "{{contact.name}}," => "contact.name"
|
|
* @param {string} searchKey
|
|
* @returns {string}
|
|
*/
|
|
export const sanitizeVariableSearchKey = (searchKey = '') => {
|
|
return searchKey
|
|
.replace(/[{}]/g, '') // remove all curly braces
|
|
.replace(/,/g, '') // remove commas
|
|
.trim();
|
|
};
|