From fc0ea7e2211a663e4a02b645e52b8eb0b730ce5a Mon Sep 17 00:00:00 2001 From: Jeremy Steele Date: Thu, 4 Nov 2021 10:15:56 -0400 Subject: [PATCH] Adjust message labels to match addlabel action --- .../flow/actions/sendmsg/SendMsgForm.tsx | 3 +- .../flow/actions/sendmsg/helpers.ts | 44 ++++++++----------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/components/flow/actions/sendmsg/SendMsgForm.tsx b/src/components/flow/actions/sendmsg/SendMsgForm.tsx index 7612e081..f465a74a 100644 --- a/src/components/flow/actions/sendmsg/SendMsgForm.tsx +++ b/src/components/flow/actions/sendmsg/SendMsgForm.tsx @@ -29,7 +29,6 @@ import { StringArrayEntry, StringEntry, SelectOptionEntry, - AssetArrayEntry, FormEntry } from 'store/nodeEditor'; import { MaxOfTenItems, Required, shouldRequireIf, validate } from 'store/validators'; @@ -54,7 +53,7 @@ export interface SendMsgFormState extends FormState { topic: SelectOptionEntry; templateVariables: StringEntry[]; templateTranslation?: TemplateTranslation; - labels: AssetArrayEntry; + labels: any; } export default class SendMsgForm extends React.Component { diff --git a/src/components/flow/actions/sendmsg/helpers.ts b/src/components/flow/actions/sendmsg/helpers.ts index d1e69eae..ebc82ca7 100644 --- a/src/components/flow/actions/sendmsg/helpers.ts +++ b/src/components/flow/actions/sendmsg/helpers.ts @@ -2,9 +2,9 @@ import { getActionUUID } from 'components/flow/actions/helpers'; import { SendMsgFormState } from 'components/flow/actions/sendmsg/SendMsgForm'; import { Types } from 'config/interfaces'; -import { MsgTemplating, SendMsg } from 'flowTypes'; -import { Asset, AssetType, AssetStore } from 'store/flowContext'; -import { AssetArrayEntry, FormEntry, NodeEditorSettings, StringEntry } from 'store/nodeEditor'; +import { Label, MsgTemplating, SendMsg } from 'flowTypes'; +import { AssetStore } from 'store/flowContext'; +import { FormEntry, NodeEditorSettings, StringEntry } from 'store/nodeEditor'; import { SelectOption } from 'components/form/select/SelectElement'; import { createUUID } from 'utils'; import { Attachment } from './attachments'; @@ -54,14 +54,8 @@ export const initializeForm = ( }); } - let labels: AssetArrayEntry = { value: [] }; - - if (action.labels) { - labels = { - value: action.labels.map(label => { - return { id: label.uuid, name: label.name, type: AssetType.Label }; - }) - }; + if (!action.labels) { + action.labels = []; } return { @@ -73,7 +67,14 @@ export const initializeForm = ( quickReplies: { value: action.quick_replies || [] }, quickReplyEntry: { value: '' }, sendAll: action.all_urns, - labels: labels, + labels: { + value: action.labels.map((label: Label) => { + if (label.name_match) { + return { name: label.name_match, expression: true }; + } + return label; + }) + }, valid: true }; } @@ -128,7 +129,12 @@ export const stateToAction = (settings: NodeEditorSettings, state: SendMsgFormSt type: Types.send_msg, all_urns: state.sendAll, quick_replies: state.quickReplies.value, - labels: getAsset(state.labels.value!, AssetType.Label), + labels: state.labels.value.map((label: any) => { + if (label.expression) { + return { name_match: label.name }; + } + return label; + }), uuid: getActionUUID(settings, Types.send_msg) }; @@ -142,15 +148,3 @@ export const stateToAction = (settings: NodeEditorSettings, state: SendMsgFormSt return result; }; - -export const getAsset = (assets: Asset[], type: AssetType): any[] => { - if (assets) { - return assets - .filter((asset: Asset) => asset.type === type) - .map((asset: Asset) => { - return { uuid: asset.id, name: asset.name }; - }); - } - - return []; -};