Skip to content

Commit 038496a

Browse files
committed
Resolve problem when after split got [ in array
1 parent 0ae66c4 commit 038496a

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

modules/st2-auto-form/fields/array.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,26 @@ export default class ArrayField extends BaseTextField {
7878
return v;
7979
}
8080

81-
/* YAQL parameter without , assume is array parameter */
81+
/* YAQL parameter that came input as single yaql */
8282
if (isYaql(v) && !v.includes(',')) {
8383
return v;
8484
}
8585

8686
const { items } = this.props.spec || {};
8787

88+
let t = v;
8889
/* Trim [], required for when kept [] around YAQL parameter */
8990
if (v && v.startsWith('[') && v.endsWith(']')) {
90-
v = v.substring(1, v.length-1).trim();
91+
t = v.substring(1, v.length-1).trim();
9192
}
9293

93-
return split(v)
94-
.map((v) => typeConversions(items && items.type, v))
94+
return split(t)
95+
.map((t) => typeConversions(items && items.type, t))
9596
;
9697
}
9798

9899
toStateValue(v) {
100+
99101
if (jsonCheck(v)) {
100102
return JSON.stringify(v);
101103
}
@@ -120,10 +122,11 @@ export default class ArrayField extends BaseTextField {
120122
* as YAQL, as need to distingish between when pass an array parameter or
121123
* an array of string parameters.
122124
*/
123-
if (v && isYaql(v.join(', '))) {
125+
if (v && Array.isArray(v) && isYaql(v.join(', ')) && v.length === 1) {
124126
return '[ '.concat(v.join(', '),' ]');
125127
}
126128

129+
127130
return v ? v.join(', ') : '';
128131
}
129132

0 commit comments

Comments
 (0)