Dashboard: Move some plugin & panel state to redux (#22052)

* WIP: dashboard panel redux

* Progress

* Progress

* Changing plugin type

* Progress

* Updated

* Progess

* Fixed timing issue

* Updated

* Fixed unit tests

* Fixed issue in dashboard page

* Updated test
This commit is contained in:
Torkel Ödegaard
2020-02-10 14:23:54 +01:00
committed by GitHub
parent 258b507179
commit 49407987fe
21 changed files with 688 additions and 146 deletions

View File

@@ -1,12 +1,13 @@
import React from 'react';
import { shallow } from 'enzyme';
import { AddPanelWidget, Props } from './AddPanelWidget';
import { AddPanelWidgetUnconnected as AddPanelWidget, Props } from './AddPanelWidget';
import { DashboardModel, PanelModel } from '../../state';
const setup = (propOverrides?: object) => {
const props: Props = {
dashboard: {} as DashboardModel,
panel: {} as PanelModel,
addPanelToDashboard: jest.fn() as any,
};
Object.assign(props, propOverrides);

View File

@@ -3,28 +3,36 @@ import React from 'react';
import _ from 'lodash';
import { LocationUpdate } from '@grafana/runtime';
import { e2e } from '@grafana/e2e';
import { connect, MapDispatchToProps } from 'react-redux';
// Utils
import config from 'app/core/config';
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';
// Types
import { DashboardModel, PanelModel } from '../../state';
import { LS_PANEL_COPY_KEY } from 'app/core/constants';
export type PanelPluginInfo = { id: any; defaults: { gridPos: { w: any; h: any }; title: any } };
export interface Props {
export interface OwnProps {
panel: PanelModel;
dashboard: DashboardModel;
}
export interface DispatchProps {
addPanelToDashboard: typeof addPanelToDashboard;
}
export type Props = OwnProps & DispatchProps;
export interface State {
copiedPanelPlugins: any[];
}
export class AddPanelWidget extends React.Component<Props, State> {
export class AddPanelWidgetUnconnected extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.handleCloseAddPanel = this.handleCloseAddPanel.bind(this);
@@ -188,3 +196,7 @@ export class AddPanelWidget extends React.Component<Props, State> {
);
}
}
const mapDispatchToProps: MapDispatchToProps<DispatchProps, OwnProps> = { addPanelToDashboard };
export const AddPanelWidget = connect(null, mapDispatchToProps)(AddPanelWidgetUnconnected);