Skip to content

Commit

Permalink
Merge pull request #901 from StackStorm/fix_empty_screen_on_array
Browse files Browse the repository at this point in the history
  • Loading branch information
amanda11 committed Aug 19, 2021
2 parents 9c578e2 + 807fba2 commit 2175287
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
DEPLOY_PACKAGES: 1
DEB: bionic focal
RPM: el7 el8
ST2_VERSION: "3.5dev"
ST2_VERSION: "3.6dev"
ST2_HOST: localhost
ST2_PROTOCOL: http
ST2_USERNAME: st2admin
Expand Down
35 changes: 32 additions & 3 deletions modules/st2-auto-form/fields/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import _ from 'lodash';
import validator from 'validator';

import { BaseTextField, isJinja } from './base';
import { BaseTextField, isJinja, isYaql } from './base';

const jsonCheck = (value) => {
try {
Expand Down Expand Up @@ -78,13 +78,26 @@ export default class ArrayField extends BaseTextField {
return v;
}

/* YAQL parameter that came input as single yaql */
if (isYaql(v) && !v.includes(',')) {
return v;
}

const { items } = this.props.spec || {};
return split(v)
.map((v) => typeConversions(items && items.type, v))

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

return split(t)
.map((t) => typeConversions(items && items.type, t))
;
}

toStateValue(v) {

if (jsonCheck(v)) {
return JSON.stringify(v);
}
Expand All @@ -93,11 +106,27 @@ export default class ArrayField extends BaseTextField {
return v;
}

/* string which is YAQL */
if (isYaql(v)) {
return v;
}

const { secret } = this.props.spec || {};

if (secret && v && !Array.isArray(v)) {
return v;
}

/*
* Keep [] if after converting to comma separated string would be treated
* as YAQL, as need to distingish between when pass an array parameter or
* an array of string parameters.
*/
if (v && Array.isArray(v) && isYaql(v.join(', ')) && v.length === 1) {
return '[ '.concat(v.join(', '),' ]');
}


return v ? v.join(', ') : '';
}

Expand Down
4 changes: 4 additions & 0 deletions modules/st2-auto-form/fields/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export function isJinja(v) {
return _.isString(v) && v.startsWith('{{') && v.endsWith('}}');
}

export function isYaql(v) {
return _.isString(v) && v.startsWith('<%') && v.endsWith('%>');
}

// TODO: make controlled
export class BaseTextField extends React.Component {
static propTypes = {
Expand Down

0 comments on commit 2175287

Please sign in to comment.