feat: add automation condition to filter private notes (#12102)
## Summary Adds a new automation condition to filter private notes. This allows automation rules to explicitly include or exclude private notes instead of relying on implicit behavior. Fixes: #11208 ## Preview https://github.com/user-attachments/assets/c40f6910-7bbf-4e59-aae5-ad408602927a
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
agents,
|
||||
teams,
|
||||
labels,
|
||||
booleanFilterOptions,
|
||||
statusFilterOptions,
|
||||
messageTypeOptions,
|
||||
priorityOptions,
|
||||
@@ -73,6 +74,8 @@ describe('useAutomation', () => {
|
||||
return countries;
|
||||
case 'message_type':
|
||||
return messageTypeOptions;
|
||||
case 'private_note':
|
||||
return booleanFilterOptions;
|
||||
case 'priority':
|
||||
return priorityOptions;
|
||||
default:
|
||||
@@ -226,6 +229,9 @@ describe('useAutomation', () => {
|
||||
expect(getConditionDropdownValues('message_type')).toEqual(
|
||||
messageTypeOptions
|
||||
);
|
||||
expect(getConditionDropdownValues('private_note')).toEqual(
|
||||
booleanFilterOptions
|
||||
);
|
||||
expect(getConditionDropdownValues('priority')).toEqual(priorityOptions);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { useEditableAutomation } from '../useEditableAutomation';
|
||||
import useAutomationValues from '../useAutomationValues';
|
||||
|
||||
vi.mock('../useAutomationValues');
|
||||
|
||||
describe('useEditableAutomation', () => {
|
||||
beforeEach(() => {
|
||||
useAutomationValues.mockReturnValue({
|
||||
getConditionDropdownValues: vi.fn(attributeKey => {
|
||||
if (attributeKey === 'private_note') {
|
||||
return [
|
||||
{ id: true, name: 'True' },
|
||||
{ id: false, name: 'False' },
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}),
|
||||
getActionDropdownValues: vi.fn(),
|
||||
});
|
||||
});
|
||||
|
||||
it('rehydrates boolean conditions as a single selected option', () => {
|
||||
const automation = {
|
||||
event_name: 'message_created',
|
||||
conditions: [
|
||||
{
|
||||
attribute_key: 'private_note',
|
||||
filter_operator: 'equal_to',
|
||||
values: [false],
|
||||
query_operator: null,
|
||||
},
|
||||
],
|
||||
actions: [],
|
||||
};
|
||||
const automationTypes = {
|
||||
message_created: {
|
||||
conditions: [{ key: 'private_note', inputType: 'search_select' }],
|
||||
},
|
||||
};
|
||||
|
||||
const { formatAutomation } = useEditableAutomation();
|
||||
const result = formatAutomation(automation, [], automationTypes, []);
|
||||
|
||||
expect(result.conditions).toEqual([
|
||||
{
|
||||
attribute_key: 'private_note',
|
||||
filter_operator: 'equal_to',
|
||||
values: { id: false, name: 'False' },
|
||||
query_operator: 'and',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -46,11 +46,26 @@ export function useEditableAutomation() {
|
||||
if (inputType === 'comma_separated_plain_text') {
|
||||
return { ...condition, values: condition.values.join(',') };
|
||||
}
|
||||
const dropdownValues = getConditionDropdownValues(
|
||||
condition.attribute_key
|
||||
);
|
||||
const hasBooleanOptions =
|
||||
inputType === 'search_select' &&
|
||||
dropdownValues.length &&
|
||||
dropdownValues.every(item => typeof item.id === 'boolean');
|
||||
|
||||
if (hasBooleanOptions) {
|
||||
return {
|
||||
...condition,
|
||||
query_operator: condition.query_operator || 'and',
|
||||
values: dropdownValues.find(item => item.id === condition.values[0]),
|
||||
};
|
||||
}
|
||||
return {
|
||||
...condition,
|
||||
query_operator: condition.query_operator || 'and',
|
||||
values: [...getConditionDropdownValues(condition.attribute_key)].filter(
|
||||
item => [...condition.values].includes(item.id)
|
||||
values: [...dropdownValues].filter(item =>
|
||||
[...condition.values].includes(item.id)
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -150,6 +150,7 @@ export const getConditionOptions = ({
|
||||
conversation_language: languages,
|
||||
country_code: countries,
|
||||
message_type: messageTypeOptions,
|
||||
private_note: booleanFilterOptions,
|
||||
priority: priorityOptions,
|
||||
labels: generateConditionOptions(labels, 'title'),
|
||||
};
|
||||
|
||||
@@ -178,6 +178,21 @@ describe('getConditionOptions', () => {
|
||||
})
|
||||
).toEqual(testOptions);
|
||||
});
|
||||
|
||||
it('returns boolean options for private_note', () => {
|
||||
const booleanOptions = [
|
||||
{ id: true, name: 'True' },
|
||||
{ id: false, name: 'False' },
|
||||
];
|
||||
|
||||
expect(
|
||||
helpers.getConditionOptions({
|
||||
booleanFilterOptions: booleanOptions,
|
||||
customAttributes,
|
||||
type: 'private_note',
|
||||
})
|
||||
).toEqual(booleanOptions);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFileName', () => {
|
||||
|
||||
@@ -169,6 +169,7 @@
|
||||
},
|
||||
"ATTRIBUTES": {
|
||||
"MESSAGE_TYPE": "Message Type",
|
||||
"PRIVATE_NOTE": "Private Note",
|
||||
"MESSAGE_CONTAINS": "Message Contains",
|
||||
"EMAIL": "Email",
|
||||
"INBOX": "Inbox",
|
||||
|
||||
@@ -14,6 +14,12 @@ export const AUTOMATIONS = {
|
||||
inputType: 'search_select',
|
||||
filterOperators: OPERATOR_TYPES_1,
|
||||
},
|
||||
{
|
||||
key: 'private_note',
|
||||
name: 'PRIVATE_NOTE',
|
||||
inputType: 'search_select',
|
||||
filterOperators: OPERATOR_TYPES_1,
|
||||
},
|
||||
{
|
||||
key: 'content',
|
||||
name: 'MESSAGE_CONTAINS',
|
||||
|
||||
Reference in New Issue
Block a user