feat: Remove labels in macro (#5875)
This commit is contained in:
@@ -8,6 +8,7 @@ export default {
|
|||||||
case 'assign_agent':
|
case 'assign_agent':
|
||||||
return this.agents;
|
return this.agents;
|
||||||
case 'add_label':
|
case 'add_label':
|
||||||
|
case 'remove_label':
|
||||||
return this.labels.map(i => {
|
return this.labels.map(i => {
|
||||||
return {
|
return {
|
||||||
id: i.title,
|
id: i.title,
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export default {
|
|||||||
const actionsMap = {
|
const actionsMap = {
|
||||||
assign_team: resolveTeamIds(this.teams, params),
|
assign_team: resolveTeamIds(this.teams, params),
|
||||||
add_label: resolveLabels(this.labels, params),
|
add_label: resolveLabels(this.labels, params),
|
||||||
|
remove_label: resolveLabels(this.labels, params),
|
||||||
assign_agent: resolveAgents(this.agents, params),
|
assign_agent: resolveAgents(this.agents, params),
|
||||||
mute_conversation: null,
|
mute_conversation: null,
|
||||||
snooze_conversation: null,
|
snooze_conversation: null,
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ export const MACRO_ACTION_TYPES = [
|
|||||||
label: 'Add a label',
|
label: 'Add a label',
|
||||||
inputType: 'multi_select',
|
inputType: 'multi_select',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'remove_label',
|
||||||
|
label: 'Remove a label',
|
||||||
|
inputType: 'multi_select',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'send_email_transcript',
|
key: 'send_email_transcript',
|
||||||
label: 'Send an email transcript',
|
label: 'Send an email transcript',
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class Macro < ApplicationRecord
|
|||||||
|
|
||||||
validate :json_actions_format
|
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
|
resolve_conversation snooze_conversation send_email_transcript send_attachment add_private_note].freeze
|
||||||
|
|
||||||
def set_visibility(user, params)
|
def set_visibility(user, params)
|
||||||
|
|||||||
@@ -33,6 +33,13 @@ class ActionService
|
|||||||
@conversation.update!(assignee_id: @agent.id) if @agent.present?
|
@conversation.update!(assignee_id: @agent.id) if @agent.present?
|
||||||
end
|
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 = [])
|
def assign_team(team_ids = [])
|
||||||
return unless team_belongs_to_account?(team_ids)
|
return unless team_belongs_to_account?(team_ids)
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
|||||||
context 'when it is an authenticated user' do
|
context 'when it is an authenticated user' do
|
||||||
let(:params) 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': [
|
'actions': [
|
||||||
{
|
{
|
||||||
'action_name': :add_label,
|
'action_name': :add_label,
|
||||||
@@ -84,6 +84,10 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
'action_name': :resolve_conversation
|
'action_name': :resolve_conversation
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'action_name': :remove_label,
|
||||||
|
'action_params': %w[support]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
visibility: 'global',
|
visibility: 'global',
|
||||||
@@ -348,6 +352,20 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do
|
|||||||
expect(conversation.reload.status).to eql('snoozed')
|
expect(conversation.reload.status).to eql('snoozed')
|
||||||
end
|
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
|
it 'Adds the private note' do
|
||||||
expect(conversation.messages).to be_empty
|
expect(conversation.messages).to be_empty
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user