Skip to content

Commit

Permalink
Merge branch 'master' into node_14
Browse files Browse the repository at this point in the history
  • Loading branch information
amanda11 authored Sep 14, 2021
2 parents dd82da8 + 2175287 commit b8c3a42
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 20 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ then you need to bootstrap the micromodules
$ lerna bootstrap
```

to avoid conflicts on node_modules, delete those generated by lerna:

```shell
$ rm -rf apps/st2-workflows/node_modules/
```

and finally run build system to fetch the font, compile css and so on

```shell
Expand Down
14 changes: 12 additions & 2 deletions apps/st2-actions/actions-details.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default class ActionsDetails extends React.Component {
static propTypes = {
handleNavigate: PropTypes.func.isRequired,
handleRun: PropTypes.func.isRequired,
handleDelete: PropTypes.func.isRequired,

id: PropTypes.string,
section: PropTypes.string,
Expand Down Expand Up @@ -127,8 +128,6 @@ export default class ActionsDetails extends React.Component {
}
}



componentDidUpdate(prevProps) {
const { id } = this.props;
if (id && id !== prevProps.id) {
Expand Down Expand Up @@ -242,6 +241,15 @@ export default class ActionsDetails extends React.Component {
return this.props.handleRun(...args);
}

handleDelete (ref) {
const { id } = this.props;

if (!window.confirm(`You are about to delete the action "${id}". This operation is irreversible. Are you sure?`)) {
return undefined;
}
return this.props.handleDelete(id);
}

render() {
const { section, action, executions, entrypoint } = this.props;
if (!action) {
Expand Down Expand Up @@ -281,6 +289,8 @@ export default class ActionsDetails extends React.Component {
/>
<Button flat value="Preview" onClick={() => this.handleToggleRunPreview()} />
<DetailsToolbarSeparator />
<Button className="st2-forms__button st2-details__toolbar-button" value="Delete" onClick={() => this.handleDelete()} />

{ action.runner_type === 'mistral-v2' || action.runner_type === 'orquesta' ? (
<Link
target="_blank"
Expand Down
30 changes: 26 additions & 4 deletions apps/st2-actions/actions-panel.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import './style.css';
return { collapsed, ...props };
}, (dispatch, props) => {
const { uid } = props;

return {
onToggle: () => store.dispatch(flexActions.toggle(uid)),
};
Expand Down Expand Up @@ -116,7 +115,6 @@ export default class ActionsPanel extends React.Component {
.then(() => {
const { id } = this.urlParams;
const { groups } = this.props;

if (id && groups && !groups.some(({ actions }) => actions.some(({ ref }) => ref === id))) {
this.navigate({ id: false });
}
Expand All @@ -128,8 +126,7 @@ export default class ActionsPanel extends React.Component {
const {
ref = get('groups[0].actions[0].ref', this.props),
section = 'general',
} = this.props.match.params;

} = this.props.match.params;
return {
id: ref,
section,
Expand Down Expand Up @@ -211,6 +208,30 @@ export default class ActionsPanel extends React.Component {
});
}

handleDelete (ref) {
return store.dispatch({
type: 'DELETE_ACTION',
ref,
promise: api.request({
method: 'delete',
path: `/actions/${ref}`,
})
.then((res) => {
notification.success(`Action "${ref}" has been deleted successfully.`);
this.navigate({ id: null });
store.dispatch(flexActions.toggleAll());
return res;
})
.catch((err) => {
notification.error(`Unable to delete action "${ref}".`, {
err,

});
throw err;
}),
});
}

render() {
const { groups, filter, collapsed } = this.props;
const { id, section } = this.urlParams;
Expand Down Expand Up @@ -282,6 +303,7 @@ export default class ActionsPanel extends React.Component {
ref={(ref) => this._details = ref}
handleNavigate={(...args) => this.navigate(...args)}
handleRun={(...args) => this.handleRun(...args)}
handleDelete={(...arg) => this.handleDelete(...arg)}

id={id}
section={section}
Expand Down
26 changes: 26 additions & 0 deletions apps/st2-actions/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@ const actionReducer = (state = {}, input) => {
};
}

case 'DELETE_ACTION': {
const { ref } = input;



switch(input.status) {
case 'success':
actions = [ ...actions ]
.filter(action => action.ref !== ref)
;
groups = makeGroups( actions, filter);

break;
case 'error':
break;
default:
break;
}

return {
...state,
actions,
groups,
};
}

case 'SET_FILTER': {
filter = input.filter;
groups = makeGroups(actions, filter);
Expand Down
2 changes: 1 addition & 1 deletion apps/st2-history/history-details.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default class HistoryDetails extends React.Component {
}

setTitle([ execution.action.ref, 'History' ]);

return (
<PanelDetails data-test="details">
<DetailsHeader
Expand Down
29 changes: 28 additions & 1 deletion apps/st2-history/history-popup.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export default class HistoryPopup extends React.Component {
payload: {
...props.payload,
},
payloadCopy: {
...props.payload, // Here first made copy of data for later comparison
},
...state,
};
}
Expand All @@ -59,8 +62,32 @@ export default class HistoryPopup extends React.Component {
}

handleSubmit(e) {
// 1. Whenever user changes any parameter,it is stored into payload.So we get changed data into payload.
// 2. We have copy of original data without any parameter change in payloadCopy object on line no 49.
// 3. Here we are first identifying key name of secret parameter, payloadKey is key variable name for
// payload object and payloadCopyKey is variable name for payloadCopy object.
// 4. Once we get both key, we are checking value of that key in both object.
// 5. So if user change secret parameter data, it will get in payload.
// 6. When user does not change secret parameter,in payload secret parameter value is *** and in
// payloadCopyKey object it is always *** because we are getting changed value in payload object only.
// 7. If data in both key same, then there is no any change and if data is not same in both key
// i.e payloadKey and payloadCopyKey, data is changed and we will send changed data to API.
e.preventDefault();

const hasValue = Object.values(this.state.payload).includes('********');
let payLoadKey;
if (hasValue === true) {
payLoadKey = Object.keys(this.state.payload).find(key => this.state.payload[key] === '********');
}

const isValue = Object.values(this.state.payloadCopy).includes('********');
let payloadCopyKey ;
if (isValue === true) {
payloadCopyKey = Object.keys(this.state.payloadCopy).find(key => this.state.payloadCopy[key] === '********');
}

if (this.state.payload[payLoadKey] === this.state.payloadCopy[payloadCopyKey]) {
delete this.state.payload[payLoadKey];
}
this.props.onSubmit(this.state.payload);
}

Expand Down
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ angular.module('main')
// render and likely freeze the browser window for deeply nested JSON object results.
// Value is in bytes.
// max_execution_result_size_for_render: 200 * 1024,
//
// set application inactivity time default for 2 hr, here it is in seconds.
// application_inactivity_time : 7200,
// Set to true to display StackStorm and st2web version in the header
//show_version_in_header: false;

Expand Down
5 changes: 4 additions & 1 deletion modules/st2-action-reporter/reporters/run-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ export default function runLocal(execution) {
execution.result && execution.result.stderr ? [
<div key="error" className={style.source}>Error</div>,
<Highlight well lines={20} className={style.highlight} key="error-code" code={execution.result.stderr} type="result" id={execution.id} />,
] : execution.result && execution.result.error ? [
<div key="error" className={style.source}>Error</div>,
<Highlight well lines={20} className={style.highlight} key="error-code" code={execution.result.error} type="result" id={execution.id} />,
] : null,

execution.result && execution.result.traceback ? [
<div key="traceback" className={style.source}>Traceback</div>,
<Highlight well lines={20} className={style.highlight} key="traceback-code" code={[ execution.result.error, execution.result.traceback ].join('\n')} type="result" id={execution.id} />,
] : null,

!execution.result || (!execution.result.stdout && !execution.result.stderr && !execution.result.traceback) ? (
!execution.result || (!execution.result.stdout && !execution.result.stderr && !execution.result.error && !execution.result.traceback) ? (
<Highlight well className={style.highlight} key="none" code="// Action produced no data" type="result" id={execution.id} />
) : null,
];
Expand Down
5 changes: 4 additions & 1 deletion modules/st2-action-reporter/reporters/run-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ export default function runPython(execution) {
execution.result && execution.result.stderr ? [
<div key="error" className={style.source}>Error</div>,
<Highlight well lines={20} className={style.highlight} key="error-code" code={execution.result.stderr} type="result" id={execution.id} />,
] : execution.result && execution.result.error ? [
<div key="error" className={style.source}>Error</div>,
<Highlight well lines={20} className={style.highlight} key="error-code" code={execution.result.error} type="result" id={execution.id} />,
] : null,

execution.result && execution.result.traceback ? [
<div key="traceback" className={style.source}>Traceback</div>,
<Highlight well lines={20} className={style.highlight} key="traceback-code" code={[ execution.result.error, execution.result.traceback ].join('\n')} type="result" id={execution.id} />,
] : null,

!execution.result || (!execution.result.result && !execution.result.stdout && !execution.result.stderr && !execution.result.traceback) ? (
!execution.result || (!execution.result.result && !execution.result.stdout && !execution.result.stderr && !execution.result.error && !execution.result.traceback) ? (
<Highlight well className={style.highlight} key="none" code="// Action produced no data" />
) : null,
].filter(v => v);
Expand Down
5 changes: 4 additions & 1 deletion modules/st2-action-reporter/reporters/run-remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ export default function runRemote(execution) {
result && result.stderr ? [
<div key="error" className={style.source}>Error</div>,
<Highlight well lines={20} className={style.highlight} key="error-code" code={result.stderr} type="result" id={execution.id} />,
] :result && result.error ? [
<div key="error" className={style.source}>Error</div>,
<Highlight well lines={20} className={style.highlight} key="error-code" code={result.error} type="result" id={execution.id} />,
] : null,

result && result.traceback ? [
<div key="traceback" className={style.source}>Traceback</div>,
<Highlight well lines={20} className={style.highlight} key="traceback-code" code={[ result.error, result.traceback ].join('\n')} type="result" id={execution.id} />,
] : null,

!result || (!result.result && !result.stderr && !result.stdout && !result.traceback) ? (
!result || (!result.result && !result.stderr && !result.stdout && !result.error && !result.traceback) ? (
<Highlight well className={style.highlight} key="none" code="// Action produced no data" />
) : null,
];
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
Loading

0 comments on commit b8c3a42

Please sign in to comment.