Skip to content

Commit e7d97d0

Browse files
authored
[ML] Set new index pattern as default one if no default index pattern exists yet. (#24337) (#24896)
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.
1 parent 1b42f30 commit e7d97d0

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

x-pack/plugins/ml/public/file_datavisualizer/components/file_datavisualizer_view/file_datavisualizer_view.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ export class FileDataVisualizerView extends Component {
308308
fileContents={fileContents}
309309
fileSize={fileSize}
310310
indexPatterns={this.props.indexPatterns}
311+
kibanaConfig={this.props.kibanaConfig}
311312
showBottomBar={this.showBottomBar}
312313
hideBottomBar={this.hideBottomBar}
313314
/>

x-pack/plugins/ml/public/file_datavisualizer/components/import_view/import_view.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ export class ImportView extends Component {
170170
if (success && createIndexPattern) {
171171
const indexPatternName = (indexPattern === '') ? index : indexPattern;
172172

173-
const indexPatternResp = await createKibanaIndexPattern(indexPatternName, this.props.indexPatterns);
173+
const indexPatternResp = await createKibanaIndexPattern(
174+
indexPatternName,
175+
this.props.indexPatterns,
176+
this.props.kibanaConfig,
177+
);
174178
success = indexPatternResp.success;
175179
this.setState({
176180
indexPatternCreatedStatus: indexPatternResp.success ? IMPORT_STATUS.COMPLETE : IMPORT_STATUS.FAILED,
@@ -429,7 +433,7 @@ export class ImportView extends Component {
429433
}
430434
}
431435

432-
async function createKibanaIndexPattern(indexPatternName, indexPatterns, timeFieldName = DEFAULT_TIME_FIELD) {
436+
async function createKibanaIndexPattern(indexPatternName, indexPatterns, kibanaConfig, timeFieldName = DEFAULT_TIME_FIELD) {
433437
try {
434438
const emptyPattern = await indexPatterns.get();
435439

@@ -440,6 +444,13 @@ async function createKibanaIndexPattern(indexPatternName, indexPatterns, timeFie
440444
});
441445

442446
const id = await emptyPattern.create();
447+
448+
// check if there's a default index pattern, if not,
449+
// set the newly created one as the default index pattern.
450+
if (!kibanaConfig.get('defaultIndex')) {
451+
await kibanaConfig.set('defaultIndex', id);
452+
}
453+
443454
return {
444455
success: true,
445456
id,
@@ -505,5 +516,3 @@ function isIndexPatternNameValid(name, indexPatternNames, index) {
505516

506517
return '';
507518
}
508-
509-

x-pack/plugins/ml/public/file_datavisualizer/file_datavisualizer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { FileDataVisualizerView } from './components/file_datavisualizer_view';
99

1010
import React from 'react';
1111

12-
export function FileDataVisualizerPage({ indexPatterns }) {
12+
export function FileDataVisualizerPage({ indexPatterns, kibanaConfig }) {
1313
return (
1414
<div className="file-datavisualizer-container">
15-
<FileDataVisualizerView indexPatterns={indexPatterns} />
15+
<FileDataVisualizerView indexPatterns={indexPatterns} kibanaConfig={kibanaConfig} />
1616
</div>
1717
);
1818
}

x-pack/plugins/ml/public/file_datavisualizer/file_datavisualizer_directive.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { FileDataVisualizerPage } from './file_datavisualizer';
4141
module.directive('fileDatavisualizerPage', function ($injector) {
4242
const reactDirective = $injector.get('reactDirective');
4343
const indexPatterns = $injector.get('indexPatterns');
44+
const kibanaConfig = $injector.get('config');
4445

45-
return reactDirective(FileDataVisualizerPage, undefined, { restrict: 'E' }, { indexPatterns });
46+
return reactDirective(FileDataVisualizerPage, undefined, { restrict: 'E' }, { indexPatterns, kibanaConfig });
4647
});

0 commit comments

Comments
 (0)