mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[TSVB] [Performance]request for api/metrics/fields triggered after all UI changes
Fix: #34433
This commit is contained in:
parent
e710ef1528
commit
040f0b106b
4 changed files with 124 additions and 92 deletions
|
@ -21,12 +21,14 @@ import PropTypes from 'prop-types';
|
|||
import React, { Component } from 'react';
|
||||
import * as Rx from 'rxjs';
|
||||
import { share } from 'rxjs/operators';
|
||||
import { isEqual } from 'lodash';
|
||||
import VisEditorVisualization from './vis_editor_visualization';
|
||||
import Visualization from './visualization';
|
||||
import VisPicker from './vis_picker';
|
||||
import PanelConfig from './panel_config';
|
||||
import brushHandler from '../lib/create_brush_handler';
|
||||
import { fetchIndexPatternFields } from '../lib/fetch_fields';
|
||||
import { fetchFields } from '../lib/fetch_fields';
|
||||
import { extractIndexPatterns } from '../lib/extract_index_patterns';
|
||||
|
||||
class VisEditor extends Component {
|
||||
constructor(props) {
|
||||
|
@ -37,7 +39,8 @@ class VisEditor extends Component {
|
|||
model: props.visParams,
|
||||
dirty: false,
|
||||
autoApply: true,
|
||||
visFields: props.visFields
|
||||
visFields: props.visFields,
|
||||
extractedIndexPatterns: ['']
|
||||
};
|
||||
this.onBrush = brushHandler(props.vis.API.timeFilter);
|
||||
this.visDataSubject = new Rx.Subject();
|
||||
|
@ -59,17 +62,30 @@ class VisEditor extends Component {
|
|||
handleChange = async (partialModel) => {
|
||||
const nextModel = { ...this.state.model, ...partialModel };
|
||||
this.props.vis.params = nextModel;
|
||||
|
||||
if (this.state.autoApply) {
|
||||
this.props.vis.updateState();
|
||||
}
|
||||
this.setState({
|
||||
|
||||
let newState = {
|
||||
model: nextModel,
|
||||
dirty: !this.state.autoApply
|
||||
});
|
||||
const { params, fields } = this.props.vis;
|
||||
fetchIndexPatternFields(params, fields).then(visFields => {
|
||||
this.setState({ visFields });
|
||||
});
|
||||
dirty: !this.state.autoApply,
|
||||
};
|
||||
|
||||
if (this.props.isEditorMode) {
|
||||
const { params, fields } = this.props.vis;
|
||||
const extractedIndexPatterns = extractIndexPatterns(params, fields);
|
||||
|
||||
if (!isEqual(this.state.extractedIndexPatterns, extractedIndexPatterns)) {
|
||||
newState = {
|
||||
...newState,
|
||||
visFields: await fetchFields(extractedIndexPatterns),
|
||||
extractedIndexPatterns: extractedIndexPatterns
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
this.setState(newState);
|
||||
};
|
||||
|
||||
handleCommit = () => {
|
||||
|
|
|
@ -1,77 +1,89 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { render, unmountComponentAtNode } from 'react-dom';
|
||||
import { I18nContext } from 'ui/i18n';
|
||||
import chrome from 'ui/chrome';
|
||||
import { fetchIndexPatternFields } from '../lib/fetch_fields';
|
||||
|
||||
function ReactEditorControllerProvider(Private, config) {
|
||||
class ReactEditorController {
|
||||
constructor(el, savedObj) {
|
||||
this.el = el;
|
||||
this.savedObj = savedObj;
|
||||
this.vis = savedObj.vis;
|
||||
this.vis.fields = {};
|
||||
}
|
||||
|
||||
setDefaultIndexPattern = async () => {
|
||||
const savedObjectsClient = chrome.getSavedObjectsClient();
|
||||
const indexPattern = await savedObjectsClient.get('index-pattern', config.get('defaultIndex'));
|
||||
this.vis.params.default_index_pattern = indexPattern.attributes.title;
|
||||
};
|
||||
|
||||
async render(params) {
|
||||
const Component = this.vis.type.editorConfig.component;
|
||||
|
||||
await this.setDefaultIndexPattern();
|
||||
const visFields = await fetchIndexPatternFields(this.vis.params, this.vis.fields);
|
||||
|
||||
render(
|
||||
<I18nContext>
|
||||
<Component
|
||||
config={config}
|
||||
vis={this.vis}
|
||||
visFields={visFields}
|
||||
visParams={this.vis.params}
|
||||
savedObj={this.savedObj}
|
||||
timeRange={params.timeRange}
|
||||
renderComplete={() => {}}
|
||||
isEditorMode={true}
|
||||
appState={params.appState}
|
||||
/>
|
||||
</I18nContext>,
|
||||
this.el);
|
||||
}
|
||||
|
||||
resize() {}
|
||||
|
||||
destroy() {
|
||||
unmountComponentAtNode(this.el);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
name: 'react_editor',
|
||||
handler: ReactEditorController
|
||||
};
|
||||
}
|
||||
|
||||
export { ReactEditorControllerProvider };
|
||||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { render, unmountComponentAtNode } from 'react-dom';
|
||||
import { I18nContext } from 'ui/i18n';
|
||||
import chrome from 'ui/chrome';
|
||||
import { fetchIndexPatternFields } from '../lib/fetch_fields';
|
||||
|
||||
function ReactEditorControllerProvider(Private, config) {
|
||||
class ReactEditorController {
|
||||
constructor(el, savedObj) {
|
||||
this.el = el;
|
||||
|
||||
this.state = {
|
||||
savedObj: savedObj,
|
||||
vis: savedObj.vis,
|
||||
isLoaded: false,
|
||||
};
|
||||
}
|
||||
|
||||
getDefaultIndexPattern = async () => {
|
||||
const savedObjectsClient = chrome.getSavedObjectsClient();
|
||||
const indexPattern = await savedObjectsClient.get('index-pattern', config.get('defaultIndex'));
|
||||
|
||||
return indexPattern.attributes.title;
|
||||
};
|
||||
|
||||
getComponent = () => {
|
||||
return this.state.vis.type.editorConfig.component;
|
||||
};
|
||||
|
||||
async render(params) {
|
||||
const Component = this.getComponent();
|
||||
|
||||
// ReactEditorController it's a not React component! Not all hooks supported
|
||||
!this.state.isLoaded && await this.componentDidMount();
|
||||
|
||||
render(
|
||||
<I18nContext>
|
||||
<Component
|
||||
config={config}
|
||||
vis={this.state.vis}
|
||||
visFields={this.state.vis.fields}
|
||||
visParams={this.state.vis.params}
|
||||
savedObj={this.state.savedObj}
|
||||
timeRange={params.timeRange}
|
||||
renderComplete={() => {}}
|
||||
isEditorMode={true}
|
||||
appState={params.appState}
|
||||
/>
|
||||
</I18nContext>,
|
||||
this.el);
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
this.state.vis.params.default_index_pattern = await this.getDefaultIndexPattern();
|
||||
this.state.vis.fields = await fetchIndexPatternFields(this.state.vis);
|
||||
this.state.isLoaded = true;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
unmountComponentAtNode(this.el);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
name: 'react_editor',
|
||||
handler: ReactEditorController,
|
||||
};
|
||||
}
|
||||
|
||||
export { ReactEditorControllerProvider };
|
||||
|
|
|
@ -41,6 +41,9 @@ export function extractIndexPatterns(params, fetchedFields) {
|
|||
});
|
||||
}
|
||||
|
||||
return uniq(patternsToFetch);
|
||||
if (patternsToFetch.length === 0) {
|
||||
patternsToFetch.push('');
|
||||
}
|
||||
|
||||
return uniq(patternsToFetch);
|
||||
}
|
||||
|
|
|
@ -30,27 +30,28 @@ export async function fetchFields(indexPatterns = ['*']) {
|
|||
pathname: '/api/metrics/fields',
|
||||
query: {
|
||||
index: pattern,
|
||||
}
|
||||
},
|
||||
});
|
||||
}));
|
||||
const fields = patterns.reduce((cumulatedFields, currentPattern, index) => {
|
||||
return {
|
||||
...cumulatedFields,
|
||||
[currentPattern]: indexFields[index]
|
||||
[currentPattern]: indexFields[index],
|
||||
};
|
||||
}, {});
|
||||
return fields;
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
toastNotifications.addDanger({
|
||||
title: i18n.translate('tsvb.fetchFields.loadIndexPatternFieldsErrorMessage', {
|
||||
defaultMessage: 'Unable to load index_pattern fields'
|
||||
defaultMessage: 'Unable to load index_pattern fields',
|
||||
}),
|
||||
text: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchIndexPatternFields(params, fields) {
|
||||
export async function fetchIndexPatternFields({ params, fields = {} }) {
|
||||
const indexPatterns = extractIndexPatterns(params, fields);
|
||||
|
||||
return await fetchFields(indexPatterns);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue