Skip to content

Commit 2175287

Browse files
authored
Merge pull request #901 from StackStorm/fix_empty_screen_on_array
2 parents 9c578e2 + 807fba2 commit 2175287

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

Diff for: .circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
DEPLOY_PACKAGES: 1
1313
DEB: bionic focal
1414
RPM: el7 el8
15-
ST2_VERSION: "3.5dev"
15+
ST2_VERSION: "3.6dev"
1616
ST2_HOST: localhost
1717
ST2_PROTOCOL: http
1818
ST2_USERNAME: st2admin

Diff for: modules/st2-auto-form/fields/array.js

+32-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import _ from 'lodash';
1616
import validator from 'validator';
1717

18-
import { BaseTextField, isJinja } from './base';
18+
import { BaseTextField, isJinja, isYaql } from './base';
1919

2020
const jsonCheck = (value) => {
2121
try {
@@ -78,13 +78,26 @@ export default class ArrayField extends BaseTextField {
7878
return v;
7979
}
8080

81+
/* YAQL parameter that came input as single yaql */
82+
if (isYaql(v) && !v.includes(',')) {
83+
return v;
84+
}
85+
8186
const { items } = this.props.spec || {};
82-
return split(v)
83-
.map((v) => typeConversions(items && items.type, v))
87+
88+
let t = v;
89+
/* Trim [], required for when kept [] around YAQL parameter */
90+
if (v && v.startsWith('[') && v.endsWith(']')) {
91+
t = v.substring(1, v.length-1).trim();
92+
}
93+
94+
return split(t)
95+
.map((t) => typeConversions(items && items.type, t))
8496
;
8597
}
8698

8799
toStateValue(v) {
100+
88101
if (jsonCheck(v)) {
89102
return JSON.stringify(v);
90103
}
@@ -93,11 +106,27 @@ export default class ArrayField extends BaseTextField {
93106
return v;
94107
}
95108

109+
/* string which is YAQL */
110+
if (isYaql(v)) {
111+
return v;
112+
}
113+
96114
const { secret } = this.props.spec || {};
115+
97116
if (secret && v && !Array.isArray(v)) {
98117
return v;
99118
}
100119

120+
/*
121+
* Keep [] if after converting to comma separated string would be treated
122+
* as YAQL, as need to distingish between when pass an array parameter or
123+
* an array of string parameters.
124+
*/
125+
if (v && Array.isArray(v) && isYaql(v.join(', ')) && v.length === 1) {
126+
return '[ '.concat(v.join(', '),' ]');
127+
}
128+
129+
101130
return v ? v.join(', ') : '';
102131
}
103132

Diff for: modules/st2-auto-form/fields/base.js

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export function isJinja(v) {
3434
return _.isString(v) && v.startsWith('{{') && v.endsWith('}}');
3535
}
3636

37+
export function isYaql(v) {
38+
return _.isString(v) && v.startsWith('<%') && v.endsWith('%>');
39+
}
40+
3741
// TODO: make controlled
3842
export class BaseTextField extends React.Component {
3943
static propTypes = {

0 commit comments

Comments
 (0)