[ML] Set new index pattern as default one if no default index pattern exists yet. (#24337)

This replicates the behaviour of the management UI: If there's no default index pattern, the one created via file visualizer's import will be set as the default index pattern.
This commit is contained in:
Walter Rafelsberger 2018-10-31 12:04:23 +01:00 committed by GitHub
parent 8f4b0e9bf8
commit e97b019815
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View file

@ -308,6 +308,7 @@ export class FileDataVisualizerView extends Component {
fileContents={fileContents}
fileSize={fileSize}
indexPatterns={this.props.indexPatterns}
kibanaConfig={this.props.kibanaConfig}
showBottomBar={this.showBottomBar}
hideBottomBar={this.hideBottomBar}
/>

View file

@ -170,7 +170,11 @@ export class ImportView extends Component {
if (success && createIndexPattern) {
const indexPatternName = (indexPattern === '') ? index : indexPattern;
const indexPatternResp = await createKibanaIndexPattern(indexPatternName, this.props.indexPatterns);
const indexPatternResp = await createKibanaIndexPattern(
indexPatternName,
this.props.indexPatterns,
this.props.kibanaConfig,
);
success = indexPatternResp.success;
this.setState({
indexPatternCreatedStatus: indexPatternResp.success ? IMPORT_STATUS.COMPLETE : IMPORT_STATUS.FAILED,
@ -429,7 +433,7 @@ export class ImportView extends Component {
}
}
async function createKibanaIndexPattern(indexPatternName, indexPatterns, timeFieldName = DEFAULT_TIME_FIELD) {
async function createKibanaIndexPattern(indexPatternName, indexPatterns, kibanaConfig, timeFieldName = DEFAULT_TIME_FIELD) {
try {
const emptyPattern = await indexPatterns.get();
@ -440,6 +444,13 @@ async function createKibanaIndexPattern(indexPatternName, indexPatterns, timeFie
});
const id = await emptyPattern.create();
// check if there's a default index pattern, if not,
// set the newly created one as the default index pattern.
if (!kibanaConfig.get('defaultIndex')) {
await kibanaConfig.set('defaultIndex', id);
}
return {
success: true,
id,
@ -505,5 +516,3 @@ function isIndexPatternNameValid(name, indexPatternNames, index) {
return '';
}

View file

@ -9,10 +9,10 @@ import { FileDataVisualizerView } from './components/file_datavisualizer_view';
import React from 'react';
export function FileDataVisualizerPage({ indexPatterns }) {
export function FileDataVisualizerPage({ indexPatterns, kibanaConfig }) {
return (
<div className="file-datavisualizer-container">
<FileDataVisualizerView indexPatterns={indexPatterns} />
<FileDataVisualizerView indexPatterns={indexPatterns} kibanaConfig={kibanaConfig} />
</div>
);
}

View file

@ -41,6 +41,7 @@ import { FileDataVisualizerPage } from './file_datavisualizer';
module.directive('fileDatavisualizerPage', function ($injector) {
const reactDirective = $injector.get('reactDirective');
const indexPatterns = $injector.get('indexPatterns');
const kibanaConfig = $injector.get('config');
return reactDirective(FileDataVisualizerPage, undefined, { restrict: 'E' }, { indexPatterns });
return reactDirective(FileDataVisualizerPage, undefined, { restrict: 'E' }, { indexPatterns, kibanaConfig });
});