mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
NewPanelEditor: Fixed cleanup that could cause crash (#22384)
* NewPanelEditor: Fixed cleanup that could cause crash * Fixed unit test
This commit is contained in:
@@ -7,7 +7,7 @@ const setup = (propOverrides?: object) => {
|
||||
const props: Props = {
|
||||
dashboard: {} as DashboardModel,
|
||||
panel: {} as PanelModel,
|
||||
addPanelToDashboard: jest.fn() as any,
|
||||
addPanel: jest.fn() as any,
|
||||
};
|
||||
|
||||
Object.assign(props, propOverrides);
|
||||
|
||||
@@ -10,7 +10,7 @@ import store from 'app/core/store';
|
||||
// Store
|
||||
import { store as reduxStore } from 'app/store/store';
|
||||
import { updateLocation } from 'app/core/actions';
|
||||
import { addPanelToDashboard } from 'app/features/dashboard/state/reducers';
|
||||
import { addPanel } from 'app/features/dashboard/state/reducers';
|
||||
// Types
|
||||
import { DashboardModel, PanelModel } from '../../state';
|
||||
import { LS_PANEL_COPY_KEY } from 'app/core/constants';
|
||||
@@ -23,7 +23,7 @@ export interface OwnProps {
|
||||
}
|
||||
|
||||
export interface DispatchProps {
|
||||
addPanelToDashboard: typeof addPanelToDashboard;
|
||||
addPanel: typeof addPanel;
|
||||
}
|
||||
|
||||
export type Props = OwnProps & DispatchProps;
|
||||
@@ -197,6 +197,6 @@ export class AddPanelWidgetUnconnected extends React.Component<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps: MapDispatchToProps<DispatchProps, OwnProps> = { addPanelToDashboard };
|
||||
const mapDispatchToProps: MapDispatchToProps<DispatchProps, OwnProps> = { addPanel };
|
||||
|
||||
export const AddPanelWidget = connect(null, mapDispatchToProps)(AddPanelWidgetUnconnected);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { thunkTester } from '../../../../../../test/core/thunk/thunkTester';
|
||||
import { initialState } from './reducers';
|
||||
import { initPanelEditor, panelEditorCleanUp } from './actions';
|
||||
import { PanelEditorStateNew, closeCompleted } from './reducers';
|
||||
import { cleanUpEditPanel } from '../../../state/reducers';
|
||||
import { PanelModel, DashboardModel } from '../../../state';
|
||||
|
||||
describe('panelEditor actions', () => {
|
||||
@@ -51,8 +52,9 @@ describe('panelEditor actions', () => {
|
||||
.givenThunk(panelEditorCleanUp)
|
||||
.whenThunkIsDispatched();
|
||||
|
||||
expect(dispatchedActions.length).toBe(1);
|
||||
expect(dispatchedActions[0].type).toBe(closeCompleted.type);
|
||||
expect(dispatchedActions.length).toBe(2);
|
||||
expect(dispatchedActions[0].type).toBe(cleanUpEditPanel.type);
|
||||
expect(dispatchedActions[1].type).toBe(closeCompleted.type);
|
||||
expect(sourcePanel.getOptions()).toEqual({ prop: true });
|
||||
expect(sourcePanel.id).toEqual(12);
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
setPanelEditorUIState,
|
||||
PANEL_EDITOR_UI_STATE_STORAGE_KEY,
|
||||
} from './reducers';
|
||||
import { cleanUpEditPanel } from '../../../state/reducers';
|
||||
import store from '../../../../../core/store';
|
||||
|
||||
export function initPanelEditor(sourcePanel: PanelModel, dashboard: DashboardModel): ThunkResult<void> {
|
||||
@@ -50,6 +51,7 @@ export function panelEditorCleanUp(): ThunkResult<void> {
|
||||
dashboard.exitPanelEditor();
|
||||
querySubscription.unsubscribe();
|
||||
|
||||
dispatch(cleanUpEditPanel());
|
||||
dispatch(closeCompleted());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,11 +15,13 @@ export const DEFAULT_PANEL_EDITOR_UI_STATE: PanelEditorUIState = {
|
||||
};
|
||||
|
||||
export interface PanelEditorUIState {
|
||||
/* Visualization options pane visibility */
|
||||
isPanelOptionsVisible: boolean;
|
||||
// annotating as number or string since size can be expressed as static value or percentage
|
||||
/* Pixels or percentage */
|
||||
rightPaneSize: number | string;
|
||||
// annotating as number or string since size can be expressed as static value or percentage
|
||||
/* Pixels or percentage */
|
||||
topPaneSize: number | string;
|
||||
/* Visualization size mode */
|
||||
mode: DisplayMode;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user