fix: Translate "None" option in automation select (#11076)

# Pull Request Template

## Description

This PR includes a translation update for the "None" option in the
automation select for both agents and teams

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)



## 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
- [x] 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
This commit is contained in:
Sivin Varghese
2025-03-14 05:14:46 +05:30
committed by GitHub
parent 557df5c5c9
commit a8001ccabc
4 changed files with 60 additions and 13 deletions

View File

@@ -16,7 +16,6 @@ import {
export default function useAutomationValues() { export default function useAutomationValues() {
const getters = useStoreGetters(); const getters = useStoreGetters();
const { t } = useI18n(); const { t } = useI18n();
const agents = useMapGetter('agents/getAgents'); const agents = useMapGetter('agents/getAgents');
const campaigns = useMapGetter('campaigns/getAllCampaigns'); const campaigns = useMapGetter('campaigns/getAllCampaigns');
const contacts = useMapGetter('contacts/getContacts'); const contacts = useMapGetter('contacts/getContacts');
@@ -61,6 +60,19 @@ export default function useAutomationValues() {
]; ];
}); });
/**
* Adds a translated "None" option to the beginning of a list
* @param {Array} list - The list to add "None" to
* @returns {Array} A new array with "None" option at the beginning
*/
const addNoneToList = list => [
{
id: 'nil',
name: t('AUTOMATION.NONE_OPTION') || 'None',
},
...(list || []),
];
/** /**
* Gets the condition dropdown values for a given type. * Gets the condition dropdown values for a given type.
* @param {string} type - The type of condition. * @param {string} type - The type of condition.
@@ -95,6 +107,7 @@ export default function useAutomationValues() {
slaPolicies: slaPolicies.value, slaPolicies: slaPolicies.value,
languages, languages,
type, type,
addNoneToListFn: addNoneToList,
}); });
}; };

View File

@@ -87,6 +87,7 @@ export const generateCustomAttributeTypes = (customAttributes, type) => {
}; };
export const generateConditionOptions = (options, key = 'id') => { export const generateConditionOptions = (options, key = 'id') => {
if (!options || !Array.isArray(options)) return [];
return options.map(i => { return options.map(i => {
return { return {
id: i[key], id: i[key],
@@ -95,25 +96,17 @@ export const generateConditionOptions = (options, key = 'id') => {
}); });
}; };
// Add the "None" option to the agent list
export const addNoneToList = agents => [
{
id: 'nil',
name: 'None',
},
...(agents || []),
];
export const getActionOptions = ({ export const getActionOptions = ({
agents, agents,
teams, teams,
labels, labels,
slaPolicies, slaPolicies,
type, type,
addNoneToListFn,
}) => { }) => {
const actionsMap = { const actionsMap = {
assign_agent: addNoneToList(agents), assign_agent: addNoneToListFn ? addNoneToListFn(agents) : agents,
assign_team: addNoneToList(teams), assign_team: addNoneToListFn ? addNoneToListFn(teams) : teams,
send_email_to_team: teams, send_email_to_team: teams,
add_label: generateConditionOptions(labels, 'title'), add_label: generateConditionOptions(labels, 'title'),
remove_label: generateConditionOptions(labels, 'title'), remove_label: generateConditionOptions(labels, 'title'),

View File

@@ -118,6 +118,46 @@ describe('getActionOptions', () => {
expectedOptions expectedOptions
); );
}); });
it('adds None option when addNoneToListFn is provided', () => {
const mockAddNoneToListFn = list => [
{ id: 'nil', name: 'None' },
...(list || []),
];
const agents = [
{ id: 1, name: 'Agent 1' },
{ id: 2, name: 'Agent 2' },
];
const expectedOptions = [
{ id: 'nil', name: 'None' },
{ id: 1, name: 'Agent 1' },
{ id: 2, name: 'Agent 2' },
];
expect(
helpers.getActionOptions({
agents,
type: 'assign_agent',
addNoneToListFn: mockAddNoneToListFn,
})
).toEqual(expectedOptions);
});
it('does not add None option when addNoneToListFn is not provided', () => {
const agents = [
{ id: 1, name: 'Agent 1' },
{ id: 2, name: 'Agent 2' },
];
expect(
helpers.getActionOptions({
agents,
type: 'assign_agent',
})
).toEqual(agents);
});
}); });
describe('getConditionOptions', () => { describe('getConditionOptions', () => {

View File

@@ -125,6 +125,7 @@
"ACTION_PARAMETERS_REQUIRED": "Action parameters are required", "ACTION_PARAMETERS_REQUIRED": "Action parameters are required",
"ATLEAST_ONE_CONDITION_REQUIRED": "At least one condition is required", "ATLEAST_ONE_CONDITION_REQUIRED": "At least one condition is required",
"ATLEAST_ONE_ACTION_REQUIRED": "At least one action is required" "ATLEAST_ONE_ACTION_REQUIRED": "At least one action is required"
} },
"NONE_OPTION": "None"
} }
} }