mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
b48832c0f7
commit
395d7eb74c
@ -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);
|
||||
});
|
||||
|
@ -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 = () => {
|
||||
|
Loading…
Reference in New Issue
Block a user