Skip to content

Commit b3b978e

Browse files
authored
Merge pull request #144 from glific/enhancement/skip-validation
skipping validation for flow results
2 parents f5b89a2 + 597dbfe commit b3b978e

File tree

7 files changed

+25
-15
lines changed

7 files changed

+25
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@glific/flow-editor",
33
"license": "AGPL-3.0",
44
"repository": "git://github.com/glific/floweditor.git",
5-
"version": "1.26.3-21",
5+
"version": "1.26.3-22",
66
"description": "'Standalone flow editing tool designed for use within the Glific suite of messaging tools'",
77
"browser": "umd/flow-editor.min.js",
88
"unpkg": "umd/flow-editor.min.js",

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@
300300
showNodeLabel: true,
301301
mutable: true,
302302
filters: ['whatsapp', 'classifier', 'ticketer', 'optins', 'groups'],
303+
skipValidation: false,
303304

304305
excludeTypes: [
305306
'add_contact_urn',

src/components/flow/actions/sendmsg/SendMsgForm.module.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
@import 'variables.module.scss';
22

3-
.checkbox {
4-
margin-top: 20px;
5-
}
6-
73
.quick_reply_summary {
84
margin-top: -20px;
95
position: relative;

src/components/flow/actions/sendmsg/SendMsgForm.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Template, TemplateTranslation } from 'flowTypes';
2121
import mutate from 'immutability-helper';
2222
import * as React from 'react';
2323
import { Asset } from 'store/flowContext';
24+
2425
import {
2526
FormState,
2627
mergeForm,
@@ -62,6 +63,7 @@ export interface SendMsgFormState extends FormState {
6263
templateTranslation?: TemplateTranslation;
6364
labels?: any;
6465
expression?: any;
66+
skipValidation?: boolean;
6567
}
6668

6769
// this is an additonal item in templates that need to have a same format as other list items
@@ -80,9 +82,9 @@ const additionalOption = {
8082
export default class SendMsgForm extends React.Component<ActionFormProps, SendMsgFormState> {
8183
private timeout: any;
8284

83-
constructor(props: ActionFormProps) {
85+
constructor(props: ActionFormProps, context: any) {
8486
super(props);
85-
this.state = stateToForm(this.props.nodeSettings, this.props.assetStore);
87+
this.state = stateToForm(this.props.nodeSettings, context.config);
8688
bindCallbacks(this, {
8789
include: [/^handle/, /^on/]
8890
});
@@ -113,13 +115,17 @@ export default class SendMsgForm extends React.Component<ActionFormProps, SendMs
113115
): boolean {
114116
const updates: Partial<SendMsgFormState> = {};
115117
if (keys.hasOwnProperty('text')) {
116-
updates.message = validate(i18n.t('forms.message', 'Message'), keys.text, [
117-
validateIf(ValidField(this.props.assetStore), submitting),
118+
let validatorFuncs = [
118119
shouldRequireIf(
119120
submitting && !this.state.template.value && this.state.attachments.length === 0
120121
),
121122
CharactersLessThan(4096, '4096 characters')
122-
]);
123+
];
124+
125+
if (!this.state.skipValidation) {
126+
validatorFuncs.push(validateIf(ValidField(this.props.assetStore), submitting));
127+
}
128+
updates.message = validate(i18n.t('forms.message', 'Message'), keys.text, validatorFuncs);
123129
}
124130

125131
if (keys.hasOwnProperty('template')) {

src/components/flow/actions/sendmsg/__snapshots__/SendMsgForm.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ Object {
264264
"value": "",
265265
},
266266
"sendAll": true,
267+
"skipValidation": false,
267268
"template": Object {
268269
"value": null,
269270
},

src/components/flow/actions/sendmsg/helpers.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import { getActionUUID } from 'components/flow/actions/helpers';
33
import { SendMsgFormState } from 'components/flow/actions/sendmsg/SendMsgForm';
44
import { Types } from 'config/interfaces';
5-
import { Label, MsgTemplating, SendMsg } from 'flowTypes';
6-
import { AssetStore } from 'store/flowContext';
5+
import { FlowEditorConfig, Label, MsgTemplating, SendMsg } from 'flowTypes';
76
import { FormEntry, NodeEditorSettings, StringEntry } from 'store/nodeEditor';
87
import { SelectOption } from 'components/form/select/SelectElement';
98
import { createUUID } from 'utils';
@@ -18,10 +17,11 @@ export const TOPIC_OPTIONS: SelectOption[] = [
1817

1918
export const initializeForm = (
2019
settings: NodeEditorSettings,
21-
assetStore: AssetStore
20+
config: FlowEditorConfig
2221
): SendMsgFormState => {
2322
let template: FormEntry = { value: null };
2423
let templateVariables: StringEntry[] = [];
24+
let skipValidation = false;
2525

2626
if (settings.originalAction && settings.originalAction.type === Types.send_msg) {
2727
const action = settings.originalAction as SendMsg;
@@ -68,6 +68,10 @@ export const initializeForm = (
6868
})
6969
: [];
7070

71+
if (config.skipValidation) {
72+
skipValidation = config.skipValidation;
73+
}
74+
7175
return {
7276
expression: expressionValue,
7377
topic: { value: TOPIC_OPTIONS.find(option => option.value === action.topic) },
@@ -83,7 +87,8 @@ export const initializeForm = (
8387
quickReplies: { value: action.quick_replies || [] },
8488
quickReplyEntry: { value: '' },
8589
sendAll: action.all_urns,
86-
valid: true
90+
valid: true,
91+
skipValidation
8792
};
8893
}
8994

@@ -136,7 +141,6 @@ export const stateToAction = (settings: NodeEditorSettings, state: SendMsgFormSt
136141
templating.expression = state.expression.value;
137142
}
138143
}
139-
140144
const result: SendMsg = {
141145
attachments,
142146
text: state.message.value,

src/flowTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export interface FlowEditorConfig {
8383
excludeTypes?: string[];
8484

8585
excludeOperators?: string[];
86+
skipValidation?: boolean;
8687
}
8788

8889
export interface LocalizationMap {
@@ -397,6 +398,7 @@ export interface SendMsg extends Action {
397398
topic?: string;
398399
templating?: MsgTemplating;
399400
labels?: Label[];
401+
skipValidation?: boolean;
400402
}
401403

402404
export interface SendInteractiveMsg extends Action {

0 commit comments

Comments
 (0)