mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* Queries default index in esdocs, essql, and timelion if index is not provided * Refactored essql
This commit is contained in:
parent
79cea1f906
commit
66c455a90f
5 changed files with 31 additions and 9 deletions
|
@ -20,7 +20,7 @@ class EssqlDatasource extends PureComponent {
|
|||
}
|
||||
}
|
||||
|
||||
defaultQuery = 'SELECT * FROM "logstash*"';
|
||||
defaultQuery = `SELECT * FROM "${this.props.defaultIndex}"`;
|
||||
|
||||
getQuery = () => getSimpleArg(this.getArgName(), this.props.args)[0];
|
||||
|
||||
|
@ -54,6 +54,7 @@ class EssqlDatasource extends PureComponent {
|
|||
|
||||
render() {
|
||||
const { isInvalid } = this.props;
|
||||
|
||||
return (
|
||||
<EuiFormRow isInvalid={isInvalid} label="Elasticsearch SQL query">
|
||||
<EuiTextArea
|
||||
|
@ -73,6 +74,7 @@ EssqlDatasource.propTypes = {
|
|||
updateArgs: PropTypes.func,
|
||||
isInvalid: PropTypes.bool,
|
||||
setInvalid: PropTypes.func,
|
||||
defaultIndex: PropTypes.string,
|
||||
};
|
||||
|
||||
export const essql = () => ({
|
||||
|
|
|
@ -18,7 +18,9 @@ import {
|
|||
import { getSimpleArg, setSimpleArg } from '../../../public/lib/arg_helpers';
|
||||
import { templateFromReactComponent } from '../../../public/lib/template_from_react_component';
|
||||
|
||||
const TimelionDatasource = ({ args, updateArgs }) => {
|
||||
const TimelionDatasource = ({ args, updateArgs, defaultIndex }) => {
|
||||
const DEFAULT_QUERY = `.es(index=${defaultIndex})`;
|
||||
|
||||
const setArg = (name, value) => {
|
||||
updateArgs &&
|
||||
updateArgs({
|
||||
|
@ -42,7 +44,7 @@ const TimelionDatasource = ({ args, updateArgs }) => {
|
|||
// TODO: This is a terrible way of doing defaults. We need to find a way to read the defaults for the function
|
||||
// and set them for the data source UI.
|
||||
const getQuery = () => {
|
||||
return getSimpleArg(argName, args)[0] || '.es(*)';
|
||||
return getSimpleArg(argName, args)[0] || DEFAULT_QUERY;
|
||||
};
|
||||
|
||||
const getInterval = () => {
|
||||
|
@ -98,6 +100,7 @@ const TimelionDatasource = ({ args, updateArgs }) => {
|
|||
TimelionDatasource.propTypes = {
|
||||
args: PropTypes.object.isRequired,
|
||||
updateArgs: PropTypes.func,
|
||||
defaultIndex: PropTypes.string,
|
||||
};
|
||||
|
||||
export const timelion = () => ({
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
EuiSpacer,
|
||||
} from '@elastic/eui';
|
||||
import { isEqual } from 'lodash';
|
||||
import { getDefaultIndex } from '../../lib/es_service';
|
||||
import { DatasourceSelector } from './datasource_selector';
|
||||
import { DatasourcePreview } from './datasource_preview';
|
||||
|
||||
|
@ -41,6 +42,12 @@ export class DatasourceComponent extends PureComponent {
|
|||
setInvalid: PropTypes.func,
|
||||
};
|
||||
|
||||
state = { defaultIndex: '' };
|
||||
|
||||
componentDidMount() {
|
||||
getDefaultIndex().then(defaultIndex => this.setState({ defaultIndex }));
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const { args, resetArgs, datasource, selectDatasource } = this.props;
|
||||
if (!isEqual(prevProps.args, args)) {
|
||||
|
@ -100,6 +107,8 @@ export class DatasourceComponent extends PureComponent {
|
|||
setInvalid,
|
||||
} = this.props;
|
||||
|
||||
const { defaultIndex } = this.state;
|
||||
|
||||
if (selecting) {
|
||||
return <DatasourceSelector datasources={datasources} onSelect={this.setSelectedDatasource} />;
|
||||
}
|
||||
|
@ -130,6 +139,7 @@ export class DatasourceComponent extends PureComponent {
|
|||
datasourceDef,
|
||||
isInvalid,
|
||||
setInvalid,
|
||||
defaultIndex,
|
||||
})}
|
||||
<EuiSpacer size="m" />
|
||||
<EuiFlexGroup justifyContent="flexEnd" gutterSize="s">
|
||||
|
|
|
@ -13,7 +13,7 @@ import { ESFieldSelect } from '../../components/es_field_select';
|
|||
import { ESIndexSelect } from '../../components/es_index_select';
|
||||
import { templateFromReactComponent } from '../../lib/template_from_react_component';
|
||||
|
||||
const EsdocsDatasource = ({ args, updateArgs }) => {
|
||||
const EsdocsDatasource = ({ args, updateArgs, defaultIndex }) => {
|
||||
const setArg = (name, value) => {
|
||||
updateArgs &&
|
||||
updateArgs({
|
||||
|
@ -35,7 +35,7 @@ const EsdocsDatasource = ({ args, updateArgs }) => {
|
|||
};
|
||||
|
||||
const getIndex = () => {
|
||||
return getSimpleArg('index', args)[0] || '';
|
||||
return getSimpleArg('index', args)[0] || defaultIndex;
|
||||
};
|
||||
|
||||
const getQuery = () => {
|
||||
|
@ -117,6 +117,7 @@ const EsdocsDatasource = ({ args, updateArgs }) => {
|
|||
EsdocsDatasource.propTypes = {
|
||||
args: PropTypes.object.isRequired,
|
||||
updateArgs: PropTypes.func,
|
||||
defaultIndex: PropTypes.string,
|
||||
};
|
||||
|
||||
export const esdocs = () => ({
|
||||
|
|
|
@ -11,6 +11,8 @@ import { notify } from './notify';
|
|||
|
||||
const basePath = chrome.getBasePath();
|
||||
const apiPath = basePath + API_ROUTE;
|
||||
const savedObjectsClient = chrome.getSavedObjectsClient();
|
||||
const AdvancedSettings = chrome.getUiSettingsClient();
|
||||
|
||||
export const getFields = (index = '_all') => {
|
||||
return fetch
|
||||
|
@ -25,9 +27,8 @@ export const getFields = (index = '_all') => {
|
|||
);
|
||||
};
|
||||
|
||||
export const getIndices = () => {
|
||||
const savedObjectsClient = chrome.getSavedObjectsClient();
|
||||
return savedObjectsClient
|
||||
export const getIndices = () =>
|
||||
savedObjectsClient
|
||||
.find({
|
||||
type: 'index-pattern',
|
||||
fields: ['title'],
|
||||
|
@ -40,4 +41,9 @@ export const getIndices = () => {
|
|||
});
|
||||
})
|
||||
.catch(err => notify.error(err, { title: `Couldn't fetch Elasticsearch indices` }));
|
||||
};
|
||||
|
||||
export const getDefaultIndex = () =>
|
||||
savedObjectsClient
|
||||
.get('index-pattern', AdvancedSettings.get('defaultIndex'))
|
||||
.then(defaultIndex => defaultIndex.attributes.title)
|
||||
.catch(err => notify.error(err, { title: `Couldn't fetch default index` }));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue