diff --git a/.circleci/config.yml b/.circleci/config.yml index e3671038a..a590ab470 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 diff --git a/modules/st2-auto-form/fields/array.js b/modules/st2-auto-form/fields/array.js index 35e0e80b5..3810ed756 100644 --- a/modules/st2-auto-form/fields/array.js +++ b/modules/st2-auto-form/fields/array.js @@ -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 { @@ -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); } @@ -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(', ') : ''; } diff --git a/modules/st2-auto-form/fields/base.js b/modules/st2-auto-form/fields/base.js index 5bcd15e87..0c387787b 100644 --- a/modules/st2-auto-form/fields/base.js +++ b/modules/st2-auto-form/fields/base.js @@ -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 = {