Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 3x 3x 3x 3x 1x 1x 1x 98x 98x 14x 1x 1x 1x 14x 13x 13x 13x 14x 13x 3x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 16x 16x 14x 9x 14x 5x 14x 14x 14x 14x 14x 14x 14x 14x 1x 1x 1x 14x 14x 14x 98x 16x 16x 16x 16x 16x 16x 16x 1x 1x 16x 15x 15x 15x 16x 16x 16x 16x 16x 16x 16x 16x 16x 6x 6x 1x 1x 5x 6x 6x 6x 6x 6x 6x 6x 6x 6x 16x 16x 15x 15x 15x 15x 15x 15x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 3x 15x 15x 15x 15x 15x 15x 15x 98x 98x 98x 98x 98x 98x 97x 98x 98x 98x 98x | import { SPLIT_GROUPS, FormData, NodeConfig, FlowTypes } from '../types';
import { Node } from '../../store/flow-definition';
import { createRulesRouter } from '../../utils';
import {
getWaitForResponseOperators,
operatorsToSelectOptions,
getOperatorConfig
} from '../operators';
import {
resultNameField,
localizeRulesField,
localizeCategoriesField,
nodeOptionsAccordion
} from './shared';
import {
createRulesArrayConfig,
extractUserRules,
casesToFormRules
} from './shared-rules';
import { getStore } from '../../store/Store';
import { validateWith } from '../utils';
// delimit index options (first through 20th)
const DELIMIT_INDEX_OPTIONS = [
{ value: '0', name: 'first result' },
{ value: '1', name: 'second result' },
{ value: '2', name: 'third result' },
{ value: '3', name: 'fourth result' },
{ value: '4', name: 'fifth result' },
{ value: '5', name: 'sixth result' },
{ value: '6', name: 'seventh result' },
{ value: '7', name: 'eighth result' },
{ value: '8', name: 'ninth result' },
{ value: '9', name: 'tenth result' },
{ value: '10', name: '11th result' },
{ value: '11', name: '12th result' },
{ value: '12', name: '13th result' },
{ value: '13', name: '14th result' },
{ value: '14', name: '15th result' },
{ value: '15', name: '16th result' },
{ value: '16', name: '17th result' },
{ value: '17', name: '18th result' },
{ value: '18', name: '19th result' },
{ value: '19', name: '20th result' }
];
// delimit by options - includes "don't delimit" and delimiter characters
const DELIMIT_BY_OPTIONS = [
{ value: '', name: "Don't delimit result" },
{ value: ' ', name: 'Delimited by spaces' },
{ value: '.', name: 'Delimited by periods' },
{ value: '+', name: 'Delimited by plusses' }
];
export const split_by_run_result: NodeConfig = {
type: 'split_by_run_result',
name: 'Split by Result',
aliases: ['split_by_run_result_delimited'], // backwards compatibility with old flow editor
group: SPLIT_GROUPS.split,
flowTypes: [FlowTypes.VOICE, FlowTypes.MESSAGE, FlowTypes.BACKGROUND],
dialogSize: 'large',
form: {
result: {
type: 'select',
required: true,
searchable: false,
clearable: false,
placeholder: 'Select a result...',
getDynamicOptions: () => {
const store = getStore();
return store
? store
.getState()
.getFlowResults()
.map((r) => ({ value: r.key, name: r.name }))
: [];
},
valueKey: 'value',
nameKey: 'name'
},
delimit_by: {
type: 'select',
required: false,
searchable: false,
clearable: false,
options: DELIMIT_BY_OPTIONS,
valueKey: 'value',
nameKey: 'name',
maxWidth: '180px'
},
delimit_index: {
type: 'select',
required: false,
searchable: false,
clearable: false,
options: DELIMIT_INDEX_OPTIONS,
valueKey: 'value',
nameKey: 'name',
maxWidth: '140px',
conditions: {
visible: (formData: FormData) => {
const delimitBy = formData.delimit_by?.[0]?.value;
return delimitBy !== undefined && delimitBy !== '';
}
}
},
rules: createRulesArrayConfig(
operatorsToSelectOptions(getWaitForResponseOperators()),
''
),
result_name: resultNameField,
localizeRules: localizeRulesField,
localizeCategories: localizeCategoriesField
},
layout: [
{
type: 'row',
label: 'Flow Result',
helpText:
'Select a flow result and optionally delimit it to split on a specific part',
items: ['result', 'delimit_by', 'delimit_index']
},
'rules',
nodeOptionsAccordion
],
validate: validateWith((formData, errors) => {
if (!formData.result || formData.result.length === 0) {
errors.result = 'A flow result is required';
}
}),
toFormData: (node: Node, nodeUI?: any) => {
// Get the result from the UI config operand (source of truth)
// Normalize: toUIConfig saves { id, name, type } but the Select component
// (valueKey: 'value') and fromFormData expect a 'value' property.
const savedOperand = nodeUI?.config?.operand;
const result = savedOperand
? { ...savedOperand, value: savedOperand.value || savedOperand.id }
: null;
// Extract rules from router cases using shared function
const rules = casesToFormRules(node);
// Extract delimiter configuration by checking the actual operand string
// If operand contains field() function, we have a delimiter
const operand = node.router?.operand || '';
const fieldFunctionMatch = operand.match(
/field\(results\.[\w]+,\s*(\d+),\s*"(.+?)"\)/
);
const hasDelimiter = fieldFunctionMatch !== null;
const delimitIndex = hasDelimiter
? parseInt(fieldFunctionMatch![1], 10)
: 0;
const delimiter = hasDelimiter ? fieldFunctionMatch![2] : '';
return {
uuid: node.uuid,
result: result ? [result] : [],
delimit_by: hasDelimiter
? [DELIMIT_BY_OPTIONS.find((opt) => opt.value === delimiter)]
: [DELIMIT_BY_OPTIONS[0]],
delimit_index: hasDelimiter
? [
DELIMIT_INDEX_OPTIONS.find(
(opt) => opt.value === String(delimitIndex)
)
]
: [DELIMIT_INDEX_OPTIONS[0]],
rules: rules,
result_name: node.router?.result_name || '',
localizeRules: nodeUI?.config?.localizeRules || false,
localizeCategories: nodeUI?.config?.localizeCategories || false
};
},
fromFormData: (formData: FormData, originalNode: Node): Node => {
// Get selected result (it's an array from the select component)
const selectedResult = formData.result?.[0];
if (!selectedResult) {
return originalNode;
}
// Build operand based on whether delimiter is selected
let operand: string;
const resultKey = selectedResult.value || selectedResult.id;
const delimitBy = formData.delimit_by?.[0]?.value;
const hasDelimiter = delimitBy !== undefined && delimitBy !== '';
if (hasDelimiter) {
// Get delimiter configuration
const delimitIndex = formData.delimit_index?.[0]?.value ?? '0';
// Build operand with field() function
operand = `@(field(results.${resultKey}, ${delimitIndex}, "${delimitBy}"))`;
} else {
// Standard operand without delimiter
operand = `@results.${resultKey}`;
}
// Get user rules using shared extraction function
const userRules = extractUserRules(formData);
// Get existing router data for preservation
const existingCategories = originalNode.router?.categories || [];
const existingExits = originalNode.exits || [];
const existingCases = originalNode.router?.cases || [];
// Create router and exits using existing data when possible
const { router, exits } = createRulesRouter(
operand,
userRules,
getOperatorConfig,
existingCategories,
existingExits,
existingCases
);
// Build final router with result_name
const finalRouter: any = {
...router
};
// Only set result_name if provided
if (formData.result_name && formData.result_name.trim() !== '') {
finalRouter.result_name = formData.result_name.trim();
}
return {
...originalNode,
router: finalRouter,
exits: exits
};
},
toUIConfig: (formData: FormData) => {
// Get selected result (it's an array from the select component)
const selectedResult = formData.result?.[0];
if (!selectedResult) {
return {};
}
// Build UI config with operand information
const config: any = {
operand: {
id: selectedResult.value,
name: selectedResult.name,
type: 'result'
}
};
// Add delimiter configuration if selected
const delimitBy = formData.delimit_by?.[0]?.value;
const hasDelimiter = delimitBy !== undefined && delimitBy !== '';
if (hasDelimiter) {
config.index = parseInt(formData.delimit_index?.[0]?.value ?? '0', 10);
config.delimiter = delimitBy;
}
// Set the type based on whether delimiter is configured
// Use split_by_run_result_delimited for backward compatibility with old editor
config.type = hasDelimiter
? 'split_by_run_result_delimited'
: 'split_by_run_result';
config.localizeRules = !!formData.localizeRules;
config.localizeCategories = formData.result_name
? !!formData.localizeCategories
: false;
return config;
},
// Localization support for categories
localizable: 'categories'
};
|