feat: Remove labels in macro (#5875)

This commit is contained in:
Tejaswini Chile 2022-11-17 12:30:47 +05:30 committed by GitHub
parent 66044a0dc3
commit e85f998a08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 2 deletions

View file

@ -8,6 +8,7 @@ export default {
case 'assign_agent':
return this.agents;
case 'add_label':
case 'remove_label':
return this.labels.map(i => {
return {
id: i.title,

View file

@ -49,6 +49,7 @@ export default {
const actionsMap = {
assign_team: resolveTeamIds(this.teams, params),
add_label: resolveLabels(this.labels, params),
remove_label: resolveLabels(this.labels, params),
assign_agent: resolveAgents(this.agents, params),
mute_conversation: null,
snooze_conversation: null,

View file

@ -14,6 +14,11 @@ export const MACRO_ACTION_TYPES = [
label: 'Add a label',
inputType: 'multi_select',
},
{
key: 'remove_label',
label: 'Remove a label',
inputType: 'multi_select',
},
{
key: 'send_email_transcript',
label: 'Send an email transcript',

View file

@ -30,7 +30,7 @@ class Macro < ApplicationRecord
validate :json_actions_format
ACTIONS_ATTRS = %w[send_message add_label assign_team assign_agent mute_conversation change_status
ACTIONS_ATTRS = %w[send_message add_label assign_team assign_agent mute_conversation change_status remove_label
resolve_conversation snooze_conversation send_email_transcript send_attachment add_private_note].freeze
def set_visibility(user, params)

View file

@ -33,6 +33,13 @@ class ActionService
@conversation.update!(assignee_id: @agent.id) if @agent.present?
end
def remove_label(labels)
return if labels.empty?
labels = @conversation.label_list - labels
@conversation.update(label_list: labels)
end
def assign_team(team_ids = [])
return unless team_belongs_to_account?(team_ids)

View file

@ -72,7 +72,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
context 'when it is an authenticated user' do
let(:params) do
{
'name': 'Add label, send message and close the chat',
'name': 'Add label, send message and close the chat, remove label',
'actions': [
{
'action_name': :add_label,
@ -84,6 +84,10 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
},
{
'action_name': :resolve_conversation
},
{
'action_name': :remove_label,
'action_params': %w[support]
}
],
visibility: 'global',
@ -348,6 +352,20 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
expect(conversation.reload.status).to eql('snoozed')
end
it 'Remove selected label' do
macro.update!(actions: [{ 'action_name' => 'remove_label', 'action_params' => ['support'] }])
conversation.add_labels(%w[support priority_customer])
expect(conversation.label_list).to match_array(%w[support priority_customer])
perform_enqueued_jobs do
post "/api/v1/accounts/#{account.id}/macros/#{macro.id}/execute",
params: { conversation_ids: [conversation.display_id] },
headers: administrator.create_new_auth_token
end
expect(conversation.reload.label_list).to match_array(%w[priority_customer])
end
it 'Adds the private note' do
expect(conversation.messages).to be_empty