Skip to content

Commit

Permalink
Fix bug of infinite loader when removing the y axis dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Oct 2, 2020
1 parent 35b8297 commit a27df91
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useEffect, useReducer } from 'react';
import React, { useEffect, useReducer, useState } from 'react';
import { CoreSetup, CoreStart } from 'kibana/public';
import { ReactExpressionRendererType } from '../../../../../../src/plugins/expressions/public';
import { Datasource, FramePublicAPI, Visualization } from '../../types';
Expand Down Expand Up @@ -52,6 +52,9 @@ export interface EditorFrameProps {

export function EditorFrame(props: EditorFrameProps) {
const [state, dispatch] = useReducer(reducer, props, getInitialState);
const [visualizeTriggerFieldContext, setVisualizeTriggerFieldContext] = useState(
props.initialContext
);
const { onError } = props;
const activeVisualization =
state.visualization.activeId && props.visualizationMap[state.visualization.activeId];
Expand All @@ -70,7 +73,7 @@ export function EditorFrame(props: EditorFrameProps) {
props.datasourceMap,
state.datasourceStates,
props.doc?.references,
props.initialContext
visualizeTriggerFieldContext
)
.then((result) => {
if (!isUnmounted) {
Expand Down Expand Up @@ -189,16 +192,17 @@ export function EditorFrame(props: EditorFrameProps) {

// Get suggestions for visualize field when all datasources are ready
useEffect(() => {
if (allLoaded && props.initialContext && !props.doc) {
if (allLoaded && visualizeTriggerFieldContext && !props.doc) {
applyVisualizeFieldSuggestions({
datasourceMap: props.datasourceMap,
datasourceStates: state.datasourceStates,
visualizationMap: props.visualizationMap,
activeVisualizationId: state.visualization.activeId,
visualizationState: state.visualization.state,
visualizeTriggerFieldContext: props.initialContext,
visualizeTriggerFieldContext,
dispatch,
});
setVisualizeTriggerFieldContext(undefined);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [allLoaded]);
Expand Down Expand Up @@ -298,7 +302,7 @@ export function EditorFrame(props: EditorFrameProps) {
ExpressionRenderer={props.ExpressionRenderer}
core={props.core}
plugins={props.plugins}
visualizeTriggerFieldContext={props.initialContext}
visualizeTriggerFieldContext={visualizeTriggerFieldContext}
/>
)
}
Expand Down

0 comments on commit a27df91

Please sign in to comment.