DashboardRow: fixes time variable not updating when used in row title (#34523)

* DashboardRow: fixes time variable not updating when used in row title

* adds test cases for subscribe event
This commit is contained in:
Uchechukwu Obasi 2021-05-24 14:28:26 +01:00 committed by GitHub
parent b48832c0f7
commit 395d7eb74c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -13,6 +13,7 @@ describe('DashboardRow', () => {
meta: {
canEdit: true,
},
events: { subscribe: jest.fn() },
};
panel = new PanelModel({ collapsed: false });
@ -31,6 +32,10 @@ describe('DashboardRow', () => {
expect(dashboardMock.toggleRow.mock.calls).toHaveLength(1);
});
it('Should subscribe to event during mount', () => {
expect(dashboardMock.events.subscribe.mock.calls).toHaveLength(1);
});
it('should have two actions as admin', () => {
expect(wrapper.find('.dashboard-row__actions .pointer')).toHaveLength(2);
});

View File

@ -4,10 +4,10 @@ import { Icon } from '@grafana/ui';
import { PanelModel } from '../../state/PanelModel';
import { DashboardModel } from '../../state/DashboardModel';
import appEvents from 'app/core/app_events';
import { CoreEvents } from 'app/types';
import { RowOptionsButton } from '../RowOptions/RowOptionsButton';
import { getTemplateSrv } from '@grafana/runtime';
import { ShowConfirmModalEvent } from '../../../../types/events';
import { RefreshEvent, ShowConfirmModalEvent } from '../../../../types/events';
import { Unsubscribable } from 'rxjs';
export interface DashboardRowProps {
panel: PanelModel;
@ -15,18 +15,23 @@ export interface DashboardRowProps {
}
export class DashboardRow extends React.Component<DashboardRowProps, any> {
sub?: Unsubscribable;
constructor(props: DashboardRowProps) {
super(props);
this.state = {
collapsed: this.props.panel.collapsed,
};
}
this.props.dashboard.on(CoreEvents.templateVariableValueUpdated, this.onVariableUpdated);
componentDidMount() {
this.sub = this.props.dashboard.events.subscribe(RefreshEvent, this.onVariableUpdated);
}
componentWillUnmount() {
this.props.dashboard.off(CoreEvents.templateVariableValueUpdated, this.onVariableUpdated);
if (this.sub) {
this.sub.unsubscribe();
}
}
onVariableUpdated = () => {