2018-11-07 13:36:35 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
2020-12-15 13:18:40 +02:00
|
|
|
import { connect, ConnectedProps } from 'react-redux';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2020-02-10 14:23:54 +01:00
|
|
|
import { StoreState } from 'app/types';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2021-10-13 08:53:36 +02:00
|
|
|
import { initPanelState } from '../../panel/state/actions';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { setPanelInstanceState } from '../../panel/state/reducers';
|
|
|
|
import { DashboardModel, PanelModel } from '../state';
|
|
|
|
|
2021-12-13 12:42:33 +00:00
|
|
|
import { LazyLoader } from './LazyLoader';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { PanelChromeAngular } from './PanelChromeAngular';
|
2022-10-17 16:03:38 +02:00
|
|
|
import { PanelStateWrapper } from './PanelStateWrapper';
|
2018-11-06 18:14:29 +01:00
|
|
|
|
2020-02-10 14:23:54 +01:00
|
|
|
export interface OwnProps {
|
2017-10-10 09:34:14 +02:00
|
|
|
panel: PanelModel;
|
2021-10-13 08:53:36 +02:00
|
|
|
stateKey: string;
|
2018-01-03 13:33:54 +01:00
|
|
|
dashboard: DashboardModel;
|
2018-11-07 16:03:33 +01:00
|
|
|
isEditing: boolean;
|
2020-04-10 16:37:26 +02:00
|
|
|
isViewing: boolean;
|
2023-04-26 09:06:38 -03:00
|
|
|
isDraggable?: boolean;
|
2021-06-22 14:44:18 +02:00
|
|
|
width: number;
|
|
|
|
height: number;
|
2021-12-13 12:42:33 +00:00
|
|
|
lazy?: boolean;
|
2022-11-23 12:14:35 +01:00
|
|
|
timezone?: string;
|
2023-02-24 04:23:56 +00:00
|
|
|
hideMenu?: boolean;
|
2020-02-10 14:23:54 +01:00
|
|
|
}
|
|
|
|
|
2020-12-15 13:18:40 +02:00
|
|
|
const mapStateToProps = (state: StoreState, props: OwnProps) => {
|
2021-10-13 08:53:36 +02:00
|
|
|
const panelState = state.panels[props.stateKey];
|
2020-12-15 13:18:40 +02:00
|
|
|
if (!panelState) {
|
|
|
|
return { plugin: null };
|
|
|
|
}
|
2020-02-10 14:23:54 +01:00
|
|
|
|
2020-12-15 13:18:40 +02:00
|
|
|
return {
|
|
|
|
plugin: panelState.plugin,
|
2021-10-01 11:08:11 +02:00
|
|
|
instanceState: panelState.instanceState,
|
2020-12-15 13:18:40 +02:00
|
|
|
};
|
|
|
|
};
|
2020-02-10 14:23:54 +01:00
|
|
|
|
2021-10-01 11:08:11 +02:00
|
|
|
const mapDispatchToProps = {
|
2021-10-13 08:53:36 +02:00
|
|
|
initPanelState,
|
2021-10-25 13:55:06 +02:00
|
|
|
setPanelInstanceState,
|
2021-10-01 11:08:11 +02:00
|
|
|
};
|
2020-12-15 13:18:40 +02:00
|
|
|
|
|
|
|
const connector = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
export type Props = OwnProps & ConnectedProps<typeof connector>;
|
2018-07-05 13:10:39 -07:00
|
|
|
|
2021-12-13 12:42:33 +00:00
|
|
|
export class DashboardPanelUnconnected extends PureComponent<Props> {
|
|
|
|
static defaultProps: Partial<Props> = {
|
|
|
|
lazy: true,
|
|
|
|
};
|
2018-07-09 13:24:15 -07:00
|
|
|
|
2018-07-09 18:17:51 +02:00
|
|
|
componentDidMount() {
|
2021-12-13 12:42:33 +00:00
|
|
|
this.props.panel.isInView = !this.props.lazy;
|
2022-04-20 10:56:19 +01:00
|
|
|
if (!this.props.lazy) {
|
|
|
|
this.onPanelLoad();
|
2021-10-13 08:53:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-25 13:55:06 +02:00
|
|
|
onInstanceStateChange = (value: any) => {
|
|
|
|
this.props.setPanelInstanceState({ key: this.props.stateKey, value });
|
|
|
|
};
|
|
|
|
|
2021-12-13 12:42:33 +00:00
|
|
|
onVisibilityChange = (v: boolean) => {
|
|
|
|
this.props.panel.isInView = v;
|
|
|
|
};
|
|
|
|
|
2022-04-20 10:56:19 +01:00
|
|
|
onPanelLoad = () => {
|
|
|
|
if (!this.props.plugin) {
|
|
|
|
this.props.initPanelState(this.props.panel);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-04-11 10:51:54 +01:00
|
|
|
renderPanel = ({ isInView }: { isInView: boolean }) => {
|
2023-04-26 09:06:38 -03:00
|
|
|
const {
|
|
|
|
dashboard,
|
|
|
|
panel,
|
|
|
|
isViewing,
|
|
|
|
isEditing,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
plugin,
|
|
|
|
timezone,
|
|
|
|
hideMenu,
|
|
|
|
isDraggable = true,
|
|
|
|
} = this.props;
|
2022-10-26 15:38:20 -07:00
|
|
|
|
|
|
|
if (!plugin) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-06-22 14:44:18 +02:00
|
|
|
|
2022-10-26 15:38:20 -07:00
|
|
|
if (plugin && plugin.angularPanelCtrl) {
|
|
|
|
return (
|
2021-06-22 14:44:18 +02:00
|
|
|
<PanelChromeAngular
|
|
|
|
plugin={plugin}
|
|
|
|
panel={panel}
|
|
|
|
dashboard={dashboard}
|
|
|
|
isViewing={isViewing}
|
|
|
|
isEditing={isEditing}
|
|
|
|
isInView={isInView}
|
2023-04-26 09:06:38 -03:00
|
|
|
isDraggable={isDraggable}
|
2021-06-22 14:44:18 +02:00
|
|
|
width={width}
|
|
|
|
height={height}
|
|
|
|
/>
|
2022-10-26 15:38:20 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<PanelStateWrapper
|
|
|
|
plugin={plugin}
|
|
|
|
panel={panel}
|
|
|
|
dashboard={dashboard}
|
|
|
|
isViewing={isViewing}
|
|
|
|
isEditing={isEditing}
|
|
|
|
isInView={isInView}
|
2023-04-26 09:06:38 -03:00
|
|
|
isDraggable={isDraggable}
|
2022-10-26 15:38:20 -07:00
|
|
|
width={width}
|
|
|
|
height={height}
|
|
|
|
onInstanceStateChange={this.onInstanceStateChange}
|
2022-11-23 12:14:35 +01:00
|
|
|
timezone={timezone}
|
2023-02-24 04:23:56 +00:00
|
|
|
hideMenu={hideMenu}
|
2022-10-26 15:38:20 -07:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { width, height, lazy } = this.props;
|
2018-11-06 18:14:29 +01:00
|
|
|
|
2021-12-13 12:42:33 +00:00
|
|
|
return lazy ? (
|
2022-04-20 10:56:19 +01:00
|
|
|
<LazyLoader width={width} height={height} onChange={this.onVisibilityChange} onLoad={this.onPanelLoad}>
|
2022-10-26 15:38:20 -07:00
|
|
|
{this.renderPanel}
|
2021-12-13 12:42:33 +00:00
|
|
|
</LazyLoader>
|
|
|
|
) : (
|
2023-04-11 10:51:54 +01:00
|
|
|
this.renderPanel({ isInView: true })
|
2019-04-01 22:22:52 -07:00
|
|
|
);
|
2018-11-15 09:46:21 +01:00
|
|
|
}
|
2018-06-19 08:42:41 +02:00
|
|
|
}
|
2020-02-10 14:23:54 +01:00
|
|
|
|
2020-12-15 13:18:40 +02:00
|
|
|
export const DashboardPanel = connector(DashboardPanelUnconnected);
|