From 47d8c9335d6949b514cef6abbcc9c4927dc993e8 Mon Sep 17 00:00:00 2001 From: fayazara Date: Mon, 10 Oct 2022 19:31:01 +0530 Subject: [PATCH] Refactor markup and specs --- .../dashboard/helper/specs/macrosFixtures.js | 71 ++++++++++++++++++ .../helper/specs/macrosHelper.spec.js | 53 +++++++++++++ .../dashboard/i18n/locale/en/macros.json | 8 +- .../conversation/Macros/MacroPreview.vue | 14 ++-- .../dashboard/settings/macros/Index.vue | 65 ++-------------- .../dashboard/settings/macros/MacroEditor.vue | 11 ++- .../dashboard/settings/macros/MacroNode.vue | 11 ++- .../settings/macros/MacroProperties.vue | 9 +++ .../settings/macros/MacrosTableRow.vue | 74 +++++++++++++++++++ .../dashboard/settings/macros/macroHelper.js | 32 +------- .../dashboard/settings/macros/macrosMixin.js | 20 +++++ 11 files changed, 267 insertions(+), 101 deletions(-) create mode 100644 app/javascript/dashboard/helper/specs/macrosFixtures.js create mode 100644 app/javascript/dashboard/helper/specs/macrosHelper.spec.js create mode 100644 app/javascript/dashboard/routes/dashboard/settings/macros/MacrosTableRow.vue create mode 100644 app/javascript/dashboard/routes/dashboard/settings/macros/macrosMixin.js diff --git a/app/javascript/dashboard/helper/specs/macrosFixtures.js b/app/javascript/dashboard/helper/specs/macrosFixtures.js new file mode 100644 index 000000000..745168d40 --- /dev/null +++ b/app/javascript/dashboard/helper/specs/macrosFixtures.js @@ -0,0 +1,71 @@ +export const teams = [ + { + id: 1, + name: '⚙️ sales team', + description: 'This is our internal sales team', + allow_auto_assign: true, + account_id: 1, + is_member: true, + }, + { + id: 2, + name: '🤷‍♂️ fayaz', + description: 'Test', + allow_auto_assign: true, + account_id: 1, + is_member: true, + }, + { + id: 3, + name: '🇮🇳 apac sales', + description: 'Sales team for France Territory', + allow_auto_assign: true, + account_id: 1, + is_member: true, + }, +]; + +export const labels = [ + { + id: 6, + title: 'sales', + description: 'sales team', + color: '#8EA20F', + show_on_sidebar: true, + }, + { + id: 2, + title: 'billing', + description: 'billing', + color: '#4077DA', + show_on_sidebar: true, + }, + { + id: 1, + title: 'snoozed', + description: 'Items marked for later', + color: '#D12F42', + show_on_sidebar: true, + }, + { + id: 5, + title: 'mobile-app', + description: 'tech team', + color: '#2DB1CC', + show_on_sidebar: true, + }, + { + id: 14, + title: 'human-resources-department-with-long-title', + description: 'Test', + color: '#FF6E09', + show_on_sidebar: true, + }, + { + id: 22, + title: 'priority', + description: 'For important sales leads', + color: '#7E7CED', + show_on_sidebar: true, + }, +]; diff --git a/app/javascript/dashboard/helper/specs/macrosHelper.spec.js b/app/javascript/dashboard/helper/specs/macrosHelper.spec.js new file mode 100644 index 000000000..dffedd73c --- /dev/null +++ b/app/javascript/dashboard/helper/specs/macrosHelper.spec.js @@ -0,0 +1,53 @@ +import { MACRO_ACTION_TYPES } from '../../routes/dashboard/settings/macros/constants'; + +import { teams, labels } from './macrosFixtures'; +import { + resolveActionName, + emptyMacro, + resolveLabels, + resolveTeamIds, +} from '../../routes/dashboard/settings/macros/macroHelper'; + +describe('#resolveActionName', () => { + it('resolve action name from key and return the correct label', () => { + expect(resolveActionName(MACRO_ACTION_TYPES[0].key)).toEqual( + MACRO_ACTION_TYPES[0].label + ); + expect(resolveActionName(MACRO_ACTION_TYPES[1].key)).toEqual( + MACRO_ACTION_TYPES[1].label + ); + expect(resolveActionName(MACRO_ACTION_TYPES[1].key)).not.toEqual( + MACRO_ACTION_TYPES[0].label + ); + }); +}); + +describe('#emptyMacro', () => { + const defaultMacro = { + name: '', + actions: [ + { + action_name: 'assign_team', + action_params: [], + }, + ], + visibility: 'global', + }; + it('returns the default macro', () => { + expect(emptyMacro).toEqual(defaultMacro); + }); +}); + +describe('#resolveTeamIds', () => { + it('resolves team names from ids, and returns a joined string', () => { + const resolvedTeams = '⚙️ sales team, 🤷‍♂️ fayaz'; + expect(resolveTeamIds(teams, [1, 2])).toEqual(resolvedTeams); + }); +}); + +describe('#resolveLabels', () => { + it('resolves labels names from ids and returns a joined string', () => { + const resolvedLabels = 'sales, billing'; + expect(resolveLabels(labels, ['sales', 'billing'])).toEqual(resolvedLabels); + }); +}); diff --git a/app/javascript/dashboard/i18n/locale/en/macros.json b/app/javascript/dashboard/i18n/locale/en/macros.json index d9917f4fa..ab2f4af71 100644 --- a/app/javascript/dashboard/i18n/locale/en/macros.json +++ b/app/javascript/dashboard/i18n/locale/en/macros.json @@ -88,12 +88,12 @@ "VISIBILITY": { "LABEL": "Macro Visibility", "GLOBAL": { - "LABEL": "Global", - "DESCRIPTION": "This macro is available globally for all agents in this account." + "LABEL": "Public", + "DESCRIPTION": "This macro is available publicly for all agents in this account." }, "PERSONAL": { - "LABEL": "Personal", - "DESCRIPTION": "This macro will be personal to you and not be available to others." + "LABEL": "Private", + "DESCRIPTION": "This macro will be private to you and not be available to others." } } }, diff --git a/app/javascript/dashboard/routes/dashboard/conversation/Macros/MacroPreview.vue b/app/javascript/dashboard/routes/dashboard/conversation/Macros/MacroPreview.vue index 4f59721a5..9f276550f 100644 --- a/app/javascript/dashboard/routes/dashboard/conversation/Macros/MacroPreview.vue +++ b/app/javascript/dashboard/routes/dashboard/conversation/Macros/MacroPreview.vue @@ -15,8 +15,8 @@ import { resolveActionName, resolveTeamIds, resolveLabels, - resolveSendEmailToTeam, } from 'dashboard/routes/dashboard/settings/macros/macroHelper.js'; +import { mapGetters } from 'vuex'; export default { props: { @@ -37,23 +37,25 @@ export default { }; }); }, + ...mapGetters({ + labels: 'labels/getLabels', + teams: 'teams/getTeams', + }), }, methods: { getActionValue(key, params) { switch (key) { case 'assign_team': - return resolveTeamIds(this.$store, params); + return resolveTeamIds(this.teams, params); case 'add_label': - return resolveLabels(this.$store, params); - case 'send_email_to_team': - case 'send_email_transcript': - return resolveSendEmailToTeam(params[0]); + return resolveLabels(this.labels, params); case 'mute_conversation': case 'snooze_conversation': case 'resolve_conversation': return null; case 'send_webhook_event': case 'send_message': + case 'send_email_transcript': return params[0]; default: return ''; diff --git a/app/javascript/dashboard/routes/dashboard/settings/macros/Index.vue b/app/javascript/dashboard/routes/dashboard/settings/macros/Index.vue index 1f4bfcdce..8d7a4b723 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/macros/Index.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/macros/Index.vue @@ -31,45 +31,12 @@ - - {{ macro.name }} - -
- - {{ macro.created_by.name }} -
- - -
- - {{ macro.updated_by.name }} -
- - {{ macro.visibility }} - - - - - - - + @@ -93,11 +60,11 @@ - - diff --git a/app/javascript/dashboard/routes/dashboard/settings/macros/MacroEditor.vue b/app/javascript/dashboard/routes/dashboard/settings/macros/MacroEditor.vue index e57102d65..dd88acb97 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/macros/MacroEditor.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/macros/MacroEditor.vue @@ -15,15 +15,16 @@ import MacroForm from './MacroForm'; import { MACRO_ACTION_TYPES } from './constants'; import { mapGetters } from 'vuex'; -import { getDropdownValues, emptyMacro } from './macroHelper'; +import { emptyMacro } from './macroHelper'; import actionQueryGenerator from 'dashboard/helper/actionQueryGenerator.js'; import alertMixin from 'shared/mixins/alertMixin'; +import macrosMixin from './macrosMixin'; export default { components: { MacroForm, }, - mixins: [alertMixin], + mixins: [alertMixin, macrosMixin], provide() { return { macroActionTypes: this.macroActionTypes, @@ -39,6 +40,8 @@ export default { computed: { ...mapGetters({ uiFlags: 'macros/getUIFlags', + labels: 'labels/getLabels', + teams: 'teams/getTeams', }), macroId() { return this.$route.params.macroId; @@ -86,12 +89,12 @@ export default { ).inputType; if (inputType === 'multi_select') { actionParams = [ - ...getDropdownValues(action.action_name, this.$store), + ...this.getDropdownValues(action.action_name, this.$store), ].filter(item => [...action.action_params].includes(item.id)); } else if (inputType === 'team_message') { actionParams = { team_ids: [ - ...getDropdownValues(action.action_name, this.$store), + ...this.getDropdownValues(action.action_name, this.$store), ].filter(item => [...action.action_params[0].team_ids].includes(item.id) ), diff --git a/app/javascript/dashboard/routes/dashboard/settings/macros/MacroNode.vue b/app/javascript/dashboard/routes/dashboard/settings/macros/MacroNode.vue index 6f48c7c34..854284bab 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/macros/MacroNode.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/macros/MacroNode.vue @@ -37,12 +37,15 @@ + + diff --git a/app/javascript/dashboard/routes/dashboard/settings/macros/macroHelper.js b/app/javascript/dashboard/routes/dashboard/settings/macros/macroHelper.js index a9ef331e7..d9be7638a 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/macros/macroHelper.js +++ b/app/javascript/dashboard/routes/dashboard/settings/macros/macroHelper.js @@ -4,48 +4,24 @@ export const resolveActionName = key => { return macroActionTypes.find(i => i.key === key).label; }; -export const resolveTeamIds = (store, ids) => { - const allTeams = store.getters['teams/getTeams']; +export const resolveTeamIds = (teams, ids) => { return ids .map(id => { - const team = allTeams.find(i => i.id === id); + const team = teams.find(i => i.id === id); return team ? team.name : ''; }) .join(', '); }; -export const resolveLabels = (store, ids) => { - const allLabels = store.getters['labels/getLabels']; +export const resolveLabels = (labels, ids) => { return ids .map(id => { - const label = allLabels.find(i => i.title === id); + const label = labels.find(i => i.title === id); return label ? label.title : ''; }) .join(', '); }; -export const resolveSendEmailToTeam = obj => { - return ` ${obj.message} - - ${resolveTeamIds(obj.team_ids)}`; -}; - -export const getDropdownValues = (type, store) => { - switch (type) { - case 'assign_team': - case 'send_email_to_team': - return store.getters['teams/getTeams']; - case 'add_label': - return store.getters['labels/getLabels'].map(i => { - return { - id: i.title, - name: i.title, - }; - }); - default: - return []; - } -}; - export const emptyMacro = { name: '', actions: [ diff --git a/app/javascript/dashboard/routes/dashboard/settings/macros/macrosMixin.js b/app/javascript/dashboard/routes/dashboard/settings/macros/macrosMixin.js new file mode 100644 index 000000000..d28f82ab5 --- /dev/null +++ b/app/javascript/dashboard/routes/dashboard/settings/macros/macrosMixin.js @@ -0,0 +1,20 @@ +export default { + methods: { + getDropdownValues(type) { + switch (type) { + case 'assign_team': + case 'send_email_to_team': + return this.teams; + case 'add_label': + return this.labels.map(i => { + return { + id: i.title, + name: i.title, + }; + }); + default: + return []; + } + }, + }, +};