import React, { Component, PropTypes } from 'react';
import AceEditor from 'react-ace';
import 'brace/mode/sql';
import 'brace/ext/linking';
import QueryForm from 'components/forms/queries/QueryForm';
import queryInterface from 'interfaces/query';
import SelectTargetsDropdown from 'components/forms/fields/SelectTargetsDropdown';
import targetInterface from 'interfaces/target';
import './mode';
import './theme';
const baseClass = 'query-composer';
class QueryComposer extends Component {
static propTypes = {
onFetchTargets: PropTypes.func,
onFormCancel: PropTypes.func,
onOsqueryTableSelect: PropTypes.func,
onRunQuery: PropTypes.func,
onSave: PropTypes.func,
onStopQuery: PropTypes.func,
onTargetSelect: PropTypes.func,
onTextEditorInputChange: PropTypes.func,
onUpdate: PropTypes.func,
query: queryInterface,
queryIsRunning: PropTypes.bool,
queryType: PropTypes.string,
selectedTargets: PropTypes.arrayOf(targetInterface),
targetsCount: PropTypes.number,
queryText: PropTypes.string,
};
static defaultProps = {
queryType: 'query',
targetsCount: 0,
};
onLoad = (editor) => {
editor.setOptions({
enableLinking: true,
});
editor.on('linkClick', (data) => {
const { type, value } = data.token;
const { onOsqueryTableSelect } = this.props;
if (type === 'osquery-token') {
return onOsqueryTableSelect(value);
}
return false;
});
}
renderForm = () => {
const {
onFormCancel,
onRunQuery,
onSave,
onStopQuery,
onUpdate,
query,
queryIsRunning,
queryText,
queryType,
} = this.props;
return (