mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 08:58:26 +00:00
fixes: onload queries fail and fixes the app crash on runjs calling itslef (#4697)
This commit is contained in:
parent
142d2efa11
commit
46a6125b96
3 changed files with 21 additions and 7 deletions
|
|
@ -323,6 +323,7 @@ class EditorComponent extends React.Component {
|
|||
},
|
||||
showQuerySearchField: false,
|
||||
});
|
||||
this.runQueries(data.data_queries);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
@ -383,9 +384,7 @@ class EditorComponent extends React.Component {
|
|||
async () => {
|
||||
if (isEmpty(this.state.editingVersion)) await this.createInitVersion(appId);
|
||||
|
||||
computeComponentState(this, this.state.appDefinition.components).then(() => {
|
||||
this.runQueries(data.data_queries);
|
||||
});
|
||||
computeComponentState(this, this.state.appDefinition.components);
|
||||
this.setWindowTitle(data.name);
|
||||
this.setState({
|
||||
showComments: !!queryString.parse(this.props.location.search).threadId,
|
||||
|
|
|
|||
|
|
@ -669,7 +669,7 @@ export function previewQuery(_ref, query, editorState, calledFromQuery = false)
|
|||
return new Promise(function (resolve, reject) {
|
||||
let queryExecutionPromise = null;
|
||||
if (query.kind === 'runjs') {
|
||||
queryExecutionPromise = executeMultilineJS(_ref, query.options.code, editorState, true);
|
||||
queryExecutionPromise = executeMultilineJS(_ref, query.options.code, editorState, query.id, true);
|
||||
} else {
|
||||
queryExecutionPromise = dataqueryService.preview(query, options);
|
||||
}
|
||||
|
|
@ -773,7 +773,7 @@ export function runQuery(_ref, queryId, queryName, confirmed = undefined, mode =
|
|||
_self.setState({ currentState: newState }, () => {
|
||||
let queryExecutionPromise = null;
|
||||
if (query.kind === 'runjs') {
|
||||
queryExecutionPromise = executeMultilineJS(_self, query.options.code, _ref, false, confirmed, mode);
|
||||
queryExecutionPromise = executeMultilineJS(_self, query.options.code, _ref, query.id, false, confirmed, mode);
|
||||
} else {
|
||||
queryExecutionPromise = dataqueryService.run(queryId, options);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import _ from 'lodash';
|
|||
import axios from 'axios';
|
||||
import JSON5 from 'json5';
|
||||
import { previewQuery, executeAction } from '@/_helpers/appUtils';
|
||||
import { toast } from 'react-hot-toast';
|
||||
|
||||
export function findProp(obj, prop, defval) {
|
||||
if (typeof defval === 'undefined') defval = null;
|
||||
|
|
@ -318,7 +319,16 @@ export function validateEmail(email) {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
export async function executeMultilineJS(_ref, code, editorState, isPreview, confirmed = undefined, mode = '') {
|
||||
export async function executeMultilineJS(
|
||||
_ref,
|
||||
code,
|
||||
editorState,
|
||||
queryId,
|
||||
isPreview,
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
confirmed = undefined,
|
||||
mode = ''
|
||||
) {
|
||||
//:: confirmed arg is unused
|
||||
const { currentState } = _ref.state;
|
||||
let result = {},
|
||||
|
|
@ -327,7 +337,12 @@ export async function executeMultilineJS(_ref, code, editorState, isPreview, con
|
|||
const actions = {
|
||||
runQuery: function (queryName = '') {
|
||||
const query = _ref.state.dataQueries.find((query) => query.name === queryName);
|
||||
if (_.isEmpty(query)) return;
|
||||
|
||||
if (_.isEmpty(query) || queryId === query?.id) {
|
||||
const errorMsg = queryId === query?.id ? 'Cannot run query from itself' : 'Query not found';
|
||||
toast.error(errorMsg);
|
||||
return;
|
||||
}
|
||||
if (isPreview) {
|
||||
return previewQuery(_ref, query, editorState, true);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue