diff --git a/app/javascript/dashboard/composables/useAutomationValues.js b/app/javascript/dashboard/composables/useAutomationValues.js index 88568fee5..4df46be8f 100644 --- a/app/javascript/dashboard/composables/useAutomationValues.js +++ b/app/javascript/dashboard/composables/useAutomationValues.js @@ -16,7 +16,6 @@ import { export default function useAutomationValues() { const getters = useStoreGetters(); const { t } = useI18n(); - const agents = useMapGetter('agents/getAgents'); const campaigns = useMapGetter('campaigns/getAllCampaigns'); 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. * @param {string} type - The type of condition. @@ -95,6 +107,7 @@ export default function useAutomationValues() { slaPolicies: slaPolicies.value, languages, type, + addNoneToListFn: addNoneToList, }); }; diff --git a/app/javascript/dashboard/helper/automationHelper.js b/app/javascript/dashboard/helper/automationHelper.js index 6ff941822..07186c122 100644 --- a/app/javascript/dashboard/helper/automationHelper.js +++ b/app/javascript/dashboard/helper/automationHelper.js @@ -87,6 +87,7 @@ export const generateCustomAttributeTypes = (customAttributes, type) => { }; export const generateConditionOptions = (options, key = 'id') => { + if (!options || !Array.isArray(options)) return []; return options.map(i => { return { 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 = ({ agents, teams, labels, slaPolicies, type, + addNoneToListFn, }) => { const actionsMap = { - assign_agent: addNoneToList(agents), - assign_team: addNoneToList(teams), + assign_agent: addNoneToListFn ? addNoneToListFn(agents) : agents, + assign_team: addNoneToListFn ? addNoneToListFn(teams) : teams, send_email_to_team: teams, add_label: generateConditionOptions(labels, 'title'), remove_label: generateConditionOptions(labels, 'title'), diff --git a/app/javascript/dashboard/helper/specs/automationHelper.spec.js b/app/javascript/dashboard/helper/specs/automationHelper.spec.js index b55da1bad..10088963a 100644 --- a/app/javascript/dashboard/helper/specs/automationHelper.spec.js +++ b/app/javascript/dashboard/helper/specs/automationHelper.spec.js @@ -118,6 +118,46 @@ describe('getActionOptions', () => { 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', () => { diff --git a/app/javascript/dashboard/i18n/locale/en/automation.json b/app/javascript/dashboard/i18n/locale/en/automation.json index 483965f53..bb4946416 100644 --- a/app/javascript/dashboard/i18n/locale/en/automation.json +++ b/app/javascript/dashboard/i18n/locale/en/automation.json @@ -125,6 +125,7 @@ "ACTION_PARAMETERS_REQUIRED": "Action parameters are required", "ATLEAST_ONE_CONDITION_REQUIRED": "At least one condition is required", "ATLEAST_ONE_ACTION_REQUIRED": "At least one action is required" - } + }, + "NONE_OPTION": "None" } }