Skip to content

Commit

Permalink
Adjust message labels to match addlabel action
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyist committed Nov 4, 2021
1 parent 20bbdc8 commit fc0ea7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
3 changes: 1 addition & 2 deletions src/components/flow/actions/sendmsg/SendMsgForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
StringArrayEntry,
StringEntry,
SelectOptionEntry,
AssetArrayEntry,
FormEntry
} from 'store/nodeEditor';
import { MaxOfTenItems, Required, shouldRequireIf, validate } from 'store/validators';
Expand All @@ -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<ActionFormProps, SendMsgFormState> {
Expand Down
44 changes: 19 additions & 25 deletions src/components/flow/actions/sendmsg/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand All @@ -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
};
}
Expand Down Expand Up @@ -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)
};

Expand All @@ -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 [];
};

0 comments on commit fc0ea7e

Please sign in to comment.