Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Input Controls] Fix Resize Resetting Selections #76573

Merged
merged 9 commits into from
Sep 10, 2020
25 changes: 20 additions & 5 deletions src/plugins/input_control_vis/public/vis_controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
*/

import React from 'react';
import { isEqual } from 'lodash';
import { render, unmountComponentAtNode } from 'react-dom';

import { Subscription } from 'rxjs';
import { I18nStart } from 'kibana/public';
import { InputControlVis } from './components/vis/input_control_vis';
import { getControlFactory } from './control/control_factory';
Expand All @@ -34,11 +36,13 @@ import { VisParams, Vis } from '../../visualizations/public';
export const createInputControlVisController = (deps: InputControlVisDependencies) => {
return class InputControlVisController {
private I18nContext?: I18nStart['Context'];
private isLoaded = false;

controls: Array<RangeControl | ListControl>;
queryBarUpdateHandler: () => void;
filterManager: FilterManager;
updateSubsciption: any;
timeFilterSubscription: Subscription;
visParams?: VisParams;

constructor(public el: Element, public vis: Vis) {
Expand All @@ -50,19 +54,30 @@ export const createInputControlVisController = (deps: InputControlVisDependencie
this.updateSubsciption = this.filterManager
.getUpdates$()
.subscribe(this.queryBarUpdateHandler);
this.timeFilterSubscription = deps.data.query.timefilter.timefilter
.getTimeUpdate$()
.subscribe(() => {
if (this.visParams?.useTimeFilter) {
this.isLoaded = false;
}
});
Comment on lines +57 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure do you really need the subscription?
I didn't find the case where do you need to handle this specific parameter.
Could you please clarify this approach? Thnx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This subscription is used to re-initialize the input controls when the 'useTimeFilter' setting is on, and the time filter has changed. This is an expected behaviour of input controls, and was missing after I stopped the 're-initialize everything on each render' behavior.

}

async render(visData: any, visParams: VisParams) {
this.visParams = visParams;
this.controls = [];
this.controls = await this.initControls();
const [{ i18n }] = await deps.core.getStartServices();
this.I18nContext = i18n.Context;
if (!this.isLoaded || !isEqual(visParams, this.visParams)) {
this.visParams = visParams;
this.controls = [];
this.controls = await this.initControls();
const [{ i18n }] = await deps.core.getStartServices();
ThomThomson marked this conversation as resolved.
Show resolved Hide resolved
this.I18nContext = i18n.Context;
this.isLoaded = true;
}
this.drawVis();
}

destroy() {
this.updateSubsciption.unsubscribe();
this.timeFilterSubscription.unsubscribe();
unmountComponentAtNode(this.el);
this.controls.forEach((control) => control.destroy());
}
Expand Down