2021-05-28 12:31:13 +00:00
|
|
|
import React from 'react';
|
2021-04-26 05:32:02 +00:00
|
|
|
import { toast } from 'react-toastify';
|
2021-05-18 13:57:54 +00:00
|
|
|
import { getDynamicVariables, resolveReferences } from '@/_helpers/utils';
|
2021-04-26 05:32:02 +00:00
|
|
|
import { dataqueryService } from '@/_services';
|
2021-05-13 09:54:58 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
import moment from 'moment';
|
2021-05-28 12:31:13 +00:00
|
|
|
import Tooltip from 'react-bootstrap/Tooltip';
|
2021-06-28 06:36:23 +00:00
|
|
|
import { history } from '@/_helpers';
|
2021-08-26 15:03:59 +00:00
|
|
|
import { serializeNestedObjectToQueryParams } from './utils';
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-06-04 14:51:36 +00:00
|
|
|
export function setStateAsync(_ref, state) {
|
2021-04-30 08:10:57 +00:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
|
_ref.setState(state, resolve);
|
|
|
|
|
});
|
2021-04-26 17:40:43 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
export function onComponentOptionsChanged(_ref, component, options) {
|
|
|
|
|
const componentName = component.name;
|
|
|
|
|
const components = _ref.state.currentState.components;
|
|
|
|
|
let componentData = components[componentName];
|
|
|
|
|
componentData = componentData || { };
|
2021-04-26 17:40:43 +00:00
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
for (const option of options) {
|
|
|
|
|
componentData[option[0]] = option[1];
|
|
|
|
|
}
|
2021-04-26 17:40:43 +00:00
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
return setStateAsync(_ref, {
|
|
|
|
|
currentState: { ..._ref.state.currentState, components: { ...components, [componentName]: componentData } }
|
|
|
|
|
});
|
2021-04-26 17:40:43 +00:00
|
|
|
}
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
export function onComponentOptionChanged(_ref, component, option_name, value) {
|
|
|
|
|
const componentName = component.name;
|
|
|
|
|
const components = _ref.state.currentState.components;
|
|
|
|
|
let componentData = components[componentName];
|
|
|
|
|
componentData = componentData || { };
|
|
|
|
|
componentData[option_name] = value;
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
return setStateAsync(_ref, {
|
|
|
|
|
currentState: { ..._ref.state.currentState, components: { ...components, [componentName]: componentData } }
|
|
|
|
|
});
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchOAuthToken(authUrl, dataSourceId) {
|
2021-04-30 08:10:57 +00:00
|
|
|
localStorage.setItem('sourceWaitingForOAuth', dataSourceId);
|
|
|
|
|
window.open(authUrl);
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-08 13:51:38 +00:00
|
|
|
export function runTransformation(_ref, rawData, transformation, query) {
|
2021-04-30 08:10:57 +00:00
|
|
|
const data = rawData;
|
2021-09-08 07:00:06 +00:00
|
|
|
const evalFunction = Function(['data', 'moment', '_', 'components', 'queries', 'globals'], transformation);
|
2021-04-30 08:10:57 +00:00
|
|
|
let result = [];
|
|
|
|
|
|
2021-09-08 07:00:06 +00:00
|
|
|
const currentState = _ref.state.currentState || {};
|
|
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
try {
|
2021-09-08 07:00:06 +00:00
|
|
|
result = evalFunction(data, moment, _, currentState.components, currentState.queries, currentState.globals);
|
2021-04-30 08:10:57 +00:00
|
|
|
} catch (err) {
|
2021-09-08 13:51:38 +00:00
|
|
|
console.log('Transformation failed for query: ', query.name ,err);
|
2021-04-30 08:10:57 +00:00
|
|
|
toast.error(err.message, { hideProgressBar: true });
|
|
|
|
|
}
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
return result;
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-24 06:51:09 +00:00
|
|
|
export async function executeActionsForEventId(_ref, eventId, component, mode) {
|
2021-09-10 07:29:04 +00:00
|
|
|
const events = component.definition.events || [];
|
|
|
|
|
const filteredEvents = events.filter(event => event.eventId === eventId);
|
2021-08-24 06:51:09 +00:00
|
|
|
|
2021-09-10 07:29:04 +00:00
|
|
|
for(const event of filteredEvents) {
|
2021-08-24 06:51:09 +00:00
|
|
|
await executeAction(_ref, event, mode);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 06:36:23 +00:00
|
|
|
export function onComponentClick(_ref, id, component, mode = 'edit') {
|
2021-08-24 06:51:09 +00:00
|
|
|
executeActionsForEventId(_ref, 'onClick', component, mode);
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function onQueryConfirm(_ref, queryConfirmationData) {
|
2021-04-30 08:10:57 +00:00
|
|
|
_ref.setState({
|
|
|
|
|
showQueryConfirmation: false
|
|
|
|
|
});
|
|
|
|
|
runQuery(_ref, queryConfirmationData.queryId, queryConfirmationData.queryName, true);
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function onQueryCancel(_ref) {
|
2021-04-30 08:10:57 +00:00
|
|
|
_ref.setState({
|
|
|
|
|
showQueryConfirmation: false
|
|
|
|
|
});
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-11 13:21:55 +00:00
|
|
|
async function copyToClipboard(text) {
|
|
|
|
|
try {
|
|
|
|
|
await navigator.clipboard.writeText(text);
|
|
|
|
|
toast.success('Copied to clipboard!', { hideProgressBar: true, autoClose: 3000 });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log('Failed to copy!', err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-25 07:53:52 +00:00
|
|
|
function showModal(_ref, modalId, show) {
|
|
|
|
|
const modalMeta = _ref.state.appDefinition.components[modalId];
|
|
|
|
|
|
|
|
|
|
const newState = {
|
|
|
|
|
currentState: {
|
|
|
|
|
..._ref.state.currentState,
|
|
|
|
|
components: {
|
|
|
|
|
..._ref.state.currentState.components,
|
|
|
|
|
[modalMeta.component.name]: {
|
|
|
|
|
..._ref.state.currentState.components[modalMeta.component.name],
|
|
|
|
|
show: show
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ref.setState(newState)
|
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
resolve();
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 06:36:23 +00:00
|
|
|
function executeAction(_ref, event, mode) {
|
2021-04-30 08:10:57 +00:00
|
|
|
if (event) {
|
|
|
|
|
if (event.actionId === 'show-alert') {
|
2021-08-24 06:51:09 +00:00
|
|
|
const message = resolveReferences(event.message, _ref.state.currentState);
|
2021-06-14 10:17:48 +00:00
|
|
|
toast(message, { hideProgressBar: true });
|
2021-08-24 06:51:09 +00:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
resolve();
|
|
|
|
|
})
|
2021-04-30 08:10:57 +00:00
|
|
|
}
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-08-30 15:39:12 +00:00
|
|
|
if (event.actionId === 'run-query') {
|
|
|
|
|
const { queryId, queryName } = event;
|
|
|
|
|
return runQuery(_ref, queryId, queryName);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
if (event.actionId === 'open-webpage') {
|
2021-08-24 06:51:09 +00:00
|
|
|
const url = resolveReferences(event.url, _ref.state.currentState);
|
2021-04-30 08:10:57 +00:00
|
|
|
window.open(url, '_blank');
|
2021-08-24 06:51:09 +00:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
resolve();
|
|
|
|
|
})
|
2021-04-30 08:10:57 +00:00
|
|
|
}
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-06-28 06:36:23 +00:00
|
|
|
if (event.actionId === 'go-to-app') {
|
2021-08-24 06:51:09 +00:00
|
|
|
const slug = resolveReferences(event.slug, _ref.state.currentState);
|
2021-08-26 15:03:59 +00:00
|
|
|
const queryParams = event.queryParams?.reduce((result, queryParam) => ({
|
|
|
|
|
...result,
|
|
|
|
|
...{
|
|
|
|
|
[resolveReferences(queryParam[0], _ref.state.currentState)]: resolveReferences(queryParam[1], _ref.state.currentState)
|
|
|
|
|
}
|
|
|
|
|
}), {})
|
|
|
|
|
|
|
|
|
|
let url =`/applications/${slug}`;
|
|
|
|
|
|
|
|
|
|
if (queryParams) {
|
|
|
|
|
const queryPart = serializeNestedObjectToQueryParams(queryParams)
|
2021-06-28 06:36:23 +00:00
|
|
|
|
2021-08-26 15:03:59 +00:00
|
|
|
if (queryPart.length > 0)
|
|
|
|
|
url = url + `?${queryPart}`
|
|
|
|
|
}
|
2021-06-28 06:36:23 +00:00
|
|
|
|
|
|
|
|
if(mode === 'view') {
|
|
|
|
|
_ref.props.history.push(url);
|
|
|
|
|
} else {
|
|
|
|
|
if(confirm("The app will be opened in a new tab as the action is triggered from the editor.")) {
|
|
|
|
|
window.open(url, '_blank');
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-24 06:51:09 +00:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
resolve();
|
|
|
|
|
})
|
2021-06-28 06:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-25 07:53:52 +00:00
|
|
|
if (event.actionId === 'show-modal')
|
|
|
|
|
return showModal(_ref, event.modal, true)
|
2021-05-09 18:06:11 +00:00
|
|
|
|
2021-08-25 07:53:52 +00:00
|
|
|
if (event.actionId === 'close-modal')
|
|
|
|
|
return showModal(_ref, event.modal, false)
|
2021-06-11 13:21:55 +00:00
|
|
|
|
|
|
|
|
if (event.actionId === 'copy-to-clipboard') {
|
2021-08-24 06:51:09 +00:00
|
|
|
const contentToCopy = resolveReferences(event.contentToCopy, _ref.state.currentState);
|
2021-06-11 13:21:55 +00:00
|
|
|
copyToClipboard(contentToCopy);
|
2021-08-24 06:51:09 +00:00
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
resolve();
|
|
|
|
|
})
|
2021-06-11 13:21:55 +00:00
|
|
|
}
|
2021-04-30 08:10:57 +00:00
|
|
|
}
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-24 06:51:09 +00:00
|
|
|
export async function onEvent(_ref, eventName, options, mode = 'edit') {
|
2021-04-30 08:10:57 +00:00
|
|
|
let _self = _ref;
|
2021-05-02 13:45:13 +00:00
|
|
|
console.log('Event: ', eventName);
|
2021-04-30 08:10:57 +00:00
|
|
|
|
2021-09-06 14:40:51 +00:00
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
if (eventName === 'onRowClicked') {
|
|
|
|
|
const { component, data } = options;
|
|
|
|
|
_self.setState({
|
|
|
|
|
currentState: {
|
|
|
|
|
..._self.state.currentState,
|
|
|
|
|
components: {
|
|
|
|
|
..._self.state.currentState.components,
|
|
|
|
|
[component.name]: {
|
|
|
|
|
..._self.state.currentState.components[component.name],
|
|
|
|
|
selectedRow: data
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, () => {
|
2021-08-24 06:51:09 +00:00
|
|
|
executeActionsForEventId(_ref, 'onRowClicked', component, mode);
|
2021-04-30 08:10:57 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (eventName === 'onTableActionButtonClicked') {
|
|
|
|
|
const { component, data, action } = options;
|
|
|
|
|
|
|
|
|
|
_self.setState({
|
|
|
|
|
currentState: {
|
|
|
|
|
..._self.state.currentState,
|
|
|
|
|
components: {
|
|
|
|
|
..._self.state.currentState.components,
|
|
|
|
|
[component.name]: {
|
|
|
|
|
..._self.state.currentState.components[component.name],
|
|
|
|
|
selectedRow: data
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, () => {
|
2021-08-26 15:03:59 +00:00
|
|
|
if(action) {
|
|
|
|
|
action.events?.forEach((event => {
|
|
|
|
|
if (event.actionId) {
|
|
|
|
|
// the event param uses a hacky workaround for using same format used by event manager ( multiple handlers )
|
|
|
|
|
executeAction(_self, { ...event, ...event.options } , mode);
|
|
|
|
|
}
|
|
|
|
|
}) )
|
2021-09-06 14:40:51 +00:00
|
|
|
} else {
|
2021-05-07 07:41:32 +00:00
|
|
|
console.log('No action is associated with this event');
|
2021-04-30 08:10:57 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-09-10 07:20:20 +00:00
|
|
|
if (['onDetect', 'onCheck', 'onUnCheck', 'onBoundsChange', 'onCreateMarker', 'onMarkerClick', 'onPageChanged', 'onSearch', 'onChange', 'onSelectionChange', 'onSelect'].includes(eventName)) {
|
2021-04-30 08:10:57 +00:00
|
|
|
const { component } = options;
|
2021-08-24 06:51:09 +00:00
|
|
|
executeActionsForEventId(_ref, eventName, component, mode);
|
2021-08-18 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
if (eventName === 'onBulkUpdate') {
|
2021-08-24 06:51:09 +00:00
|
|
|
onComponentOptionChanged(_self, options.component, 'isSavingChanges', true);
|
|
|
|
|
await executeActionsForEventId(_self, eventName, options.component, mode);
|
|
|
|
|
onComponentOptionChanged(_self, options.component, 'isSavingChanges', false);
|
2021-04-30 08:10:57 +00:00
|
|
|
}
|
2021-09-06 14:40:51 +00:00
|
|
|
|
|
|
|
|
if (['onDataQuerySuccess', 'onDataQueryFailure'].includes(eventName)) {
|
|
|
|
|
await executeActionsForEventId(_self, eventName, options, mode);
|
|
|
|
|
}
|
2021-04-30 08:10:57 +00:00
|
|
|
}
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-09-06 14:40:51 +00:00
|
|
|
function getQueryVariables(options, state) {
|
2021-05-18 13:57:54 +00:00
|
|
|
|
|
|
|
|
let queryVariables = {};
|
|
|
|
|
|
|
|
|
|
if( typeof options === 'string' ) {
|
|
|
|
|
const dynamicVariables = getDynamicVariables(options) || [];
|
2021-09-06 14:40:51 +00:00
|
|
|
dynamicVariables.forEach((variable) => {
|
2021-05-18 13:57:54 +00:00
|
|
|
queryVariables[variable] = resolveReferences(variable, state);
|
|
|
|
|
});
|
2021-09-06 14:40:51 +00:00
|
|
|
} else if(Array.isArray(options)) {
|
|
|
|
|
options.forEach((element) => {
|
2021-05-18 13:57:54 +00:00
|
|
|
_.merge(queryVariables, getQueryVariables(element, state))
|
|
|
|
|
})
|
|
|
|
|
} else if(typeof options ==="object") {
|
2021-08-30 17:21:53 +00:00
|
|
|
Object.keys(options || {}).forEach((key) => {
|
2021-05-18 13:57:54 +00:00
|
|
|
_.merge(queryVariables, getQueryVariables(options[key], state))
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return queryVariables;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-22 11:29:27 +00:00
|
|
|
export function previewQuery(_ref, query) {
|
2021-05-30 14:05:10 +00:00
|
|
|
const options = getQueryVariables(query.options, _ref.props.currentState);
|
2021-05-22 11:29:27 +00:00
|
|
|
|
|
|
|
|
_ref.setState({ previewLoading: true });
|
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
dataqueryService.preview(query, options).then(data => {
|
2021-09-06 14:40:51 +00:00
|
|
|
|
2021-05-31 17:04:45 +00:00
|
|
|
let finalData = data.data;
|
|
|
|
|
|
|
|
|
|
if (query.options.enableTransformation) {
|
2021-09-08 13:51:38 +00:00
|
|
|
finalData = runTransformation(_ref, finalData, query.options.transformation, query);
|
2021-05-31 17:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ref.setState({ previewLoading: false, queryPreviewData: finalData });
|
2021-07-17 07:36:21 +00:00
|
|
|
|
|
|
|
|
if(data.status === 'failed') {
|
|
|
|
|
toast.error(`${data.message}: ${data.description}`, { position: 'bottom-center', hideProgressBar: true, autoClose: 10000 });
|
2021-09-06 14:40:51 +00:00
|
|
|
} else {
|
2021-07-25 17:32:36 +00:00
|
|
|
if (data.status === 'needs_oauth') {
|
|
|
|
|
const url = data.data.auth_url; // Backend generates and return sthe auth url
|
|
|
|
|
fetchOAuthToken(url, query.data_source_id);
|
|
|
|
|
}
|
|
|
|
|
if(data.status === 'ok') {
|
|
|
|
|
toast.info(`Query completed.`, {
|
|
|
|
|
hideProgressBar: true,
|
|
|
|
|
position: 'bottom-center',
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-07-17 07:36:21 +00:00
|
|
|
}
|
|
|
|
|
|
2021-05-22 11:29:27 +00:00
|
|
|
resolve();
|
2021-05-23 17:57:47 +00:00
|
|
|
}).catch(({ error, data } ) => {
|
|
|
|
|
_ref.setState({ previewLoading: false, queryPreviewData: data });
|
2021-05-22 11:29:27 +00:00
|
|
|
toast.error(error, { hideProgressBar: true, autoClose: 3000 });
|
2021-05-23 17:57:47 +00:00
|
|
|
reject( { error, data });
|
2021-05-22 11:29:27 +00:00
|
|
|
});;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
export function runQuery(_ref, queryId, queryName, confirmed = undefined) {
|
|
|
|
|
const query = _ref.state.app.data_queries.find(query => query.id === queryId);
|
|
|
|
|
let dataQuery = {};
|
|
|
|
|
|
|
|
|
|
if (query) {
|
|
|
|
|
dataQuery = JSON.parse(JSON.stringify(query));
|
|
|
|
|
} else {
|
|
|
|
|
toast.error('No query has been associated with the action.', { hideProgressBar: true, autoClose: 3000 });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-18 13:57:54 +00:00
|
|
|
const options = getQueryVariables(dataQuery.options, _ref.state.currentState);
|
2021-04-30 08:10:57 +00:00
|
|
|
|
|
|
|
|
if (options.requestConfirmation) {
|
|
|
|
|
if (confirmed === undefined) {
|
|
|
|
|
_ref.setState({
|
|
|
|
|
showQueryConfirmation: true,
|
|
|
|
|
queryConfirmationData: {
|
|
|
|
|
queryId, queryName
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
2021-04-30 08:10:57 +00:00
|
|
|
});
|
|
|
|
|
return;
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
2021-04-30 08:10:57 +00:00
|
|
|
}
|
|
|
|
|
const newState = {
|
|
|
|
|
..._ref.state.currentState,
|
|
|
|
|
queries: {
|
|
|
|
|
..._ref.state.currentState.queries,
|
|
|
|
|
[queryName]: {
|
|
|
|
|
..._ref.state.currentState.queries[queryName],
|
2021-05-02 13:45:13 +00:00
|
|
|
isLoading: true,
|
|
|
|
|
data: [],
|
|
|
|
|
rawData: []
|
2021-04-30 08:10:57 +00:00
|
|
|
}
|
2021-08-27 06:35:53 +00:00
|
|
|
},
|
|
|
|
|
errors: {}
|
2021-04-30 08:10:57 +00:00
|
|
|
};
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
let _self = _ref;
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
_self.setState({ currentState: newState }, () => {
|
|
|
|
|
dataqueryService.run(queryId, options).then(data => {
|
2021-04-26 05:32:02 +00:00
|
|
|
|
2021-07-25 17:20:19 +00:00
|
|
|
if (data.status === 'needs_oauth') {
|
|
|
|
|
const url = data.data.auth_url; // Backend generates and return sthe auth url
|
|
|
|
|
fetchOAuthToken(url, dataQuery.data_source_id);
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
if (data.status === 'failed') {
|
2021-08-23 11:31:52 +00:00
|
|
|
toast.error(data.message, { hideProgressBar: true, autoClose: 3000 });
|
2021-09-06 14:40:51 +00:00
|
|
|
|
2021-08-27 06:35:53 +00:00
|
|
|
return (
|
|
|
|
|
_self.setState({
|
|
|
|
|
currentState: {
|
|
|
|
|
..._self.state.currentState,
|
|
|
|
|
queries: {
|
|
|
|
|
..._self.state.currentState.queries,
|
|
|
|
|
[queryName]: {
|
|
|
|
|
..._self.state.currentState.queries[queryName],
|
|
|
|
|
isLoading: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
errors: {
|
|
|
|
|
..._self.state.currentState.errors,
|
|
|
|
|
[queryName]: {
|
|
|
|
|
type: 'query',
|
|
|
|
|
data: data,
|
|
|
|
|
options: options
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-08 07:12:28 +00:00
|
|
|
}, () => {
|
|
|
|
|
resolve();
|
|
|
|
|
onEvent(
|
|
|
|
|
_self,
|
|
|
|
|
'onDataQueryFailure',
|
|
|
|
|
{ definition: { events: dataQuery.options.events } }
|
|
|
|
|
)
|
2021-08-27 06:35:53 +00:00
|
|
|
})
|
|
|
|
|
)
|
2021-04-30 08:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let rawData = data.data;
|
|
|
|
|
let finalData = data.data;
|
|
|
|
|
|
2021-05-20 05:59:55 +00:00
|
|
|
if (dataQuery.options.enableTransformation) {
|
2021-09-08 13:51:38 +00:00
|
|
|
finalData = runTransformation(_self, rawData, dataQuery.options.transformation, dataQuery);
|
2021-04-30 08:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
2021-05-20 05:59:55 +00:00
|
|
|
if (dataQuery.options.showSuccessNotification) {
|
|
|
|
|
const notificationDuration = dataQuery.options.notificationDuration || 5;
|
|
|
|
|
toast.success(dataQuery.options.successMessage, { hideProgressBar: true, autoClose: notificationDuration * 1000 });
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-30 08:10:57 +00:00
|
|
|
_self.setState({
|
|
|
|
|
currentState: {
|
|
|
|
|
..._self.state.currentState,
|
|
|
|
|
queries: {
|
|
|
|
|
..._self.state.currentState.queries,
|
|
|
|
|
[queryName]: {
|
|
|
|
|
..._self.state.currentState.queries[queryName],
|
|
|
|
|
data: finalData,
|
|
|
|
|
rawData,
|
|
|
|
|
isLoading: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-08 07:12:28 +00:00
|
|
|
}, () => {
|
|
|
|
|
resolve();
|
|
|
|
|
onEvent(
|
|
|
|
|
_self,
|
|
|
|
|
'onDataQuerySuccess',
|
|
|
|
|
{ definition: { events: dataQuery.options.events } }
|
|
|
|
|
)
|
2021-04-26 05:32:02 +00:00
|
|
|
});
|
2021-05-23 17:57:47 +00:00
|
|
|
}).catch(( { error } ) => {
|
2021-05-02 06:23:56 +00:00
|
|
|
toast.error(error, { hideProgressBar: true, autoClose: 3000 });
|
|
|
|
|
_self.setState({
|
|
|
|
|
currentState: {
|
|
|
|
|
..._self.state.currentState,
|
|
|
|
|
queries: {
|
|
|
|
|
..._self.state.currentState.queries,
|
|
|
|
|
[queryName]: {
|
|
|
|
|
isLoading: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-08 07:12:28 +00:00
|
|
|
}, () => {
|
|
|
|
|
resolve();
|
2021-05-02 06:23:56 +00:00
|
|
|
});
|
2021-04-30 08:10:57 +00:00
|
|
|
});
|
2021-04-26 05:32:02 +00:00
|
|
|
});
|
2021-04-30 08:10:57 +00:00
|
|
|
});
|
2021-04-26 05:32:02 +00:00
|
|
|
}
|
2021-05-28 12:31:13 +00:00
|
|
|
|
|
|
|
|
export function renderTooltip({props, text}) {
|
|
|
|
|
return <Tooltip id="button-tooltip" {...props}>
|
|
|
|
|
{text}
|
|
|
|
|
</Tooltip>
|
|
|
|
|
};
|