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