2019-12-16 02:18:48 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { css } from 'emotion';
|
|
|
|
import { GrafanaTheme } from '@grafana/data';
|
2020-02-07 07:59:04 -06:00
|
|
|
import { stylesFactory, Forms } from '@grafana/ui';
|
2019-12-16 02:18:48 -06:00
|
|
|
import config from 'app/core/config';
|
|
|
|
|
|
|
|
import { PanelModel } from '../../state/PanelModel';
|
|
|
|
import { DashboardModel } from '../../state/DashboardModel';
|
|
|
|
import { DashboardPanel } from '../../dashgrid/DashboardPanel';
|
|
|
|
import { QueriesTab } from '../../panel_editor/QueriesTab';
|
2020-02-07 07:59:04 -06:00
|
|
|
import { StoreState } from '../../../../types/store';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { updateLocation } from '../../../../core/reducers/location';
|
2019-12-16 02:18:48 -06:00
|
|
|
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => ({
|
|
|
|
wrapper: css`
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
position: fixed;
|
|
|
|
z-index: ${theme.zIndex.modal};
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
|
|
|
background: ${theme.colors.pageBg};
|
|
|
|
display: flex;
|
|
|
|
padding: ${theme.spacing.md};
|
|
|
|
flex-direction: row;
|
|
|
|
`,
|
|
|
|
leftPane: css`
|
|
|
|
flex-grow: 1;
|
|
|
|
height: 100%;
|
|
|
|
`,
|
|
|
|
rightPane: css`
|
|
|
|
width: 450px;
|
|
|
|
height: 100%;
|
|
|
|
flex-grow: 0;
|
|
|
|
`,
|
|
|
|
leftPaneViz: css`
|
|
|
|
width: 100%;
|
|
|
|
height: 50%;
|
|
|
|
`,
|
|
|
|
leftPaneData: css`
|
|
|
|
width: 100%;
|
|
|
|
height: 50%;
|
|
|
|
padding-top: ${theme.spacing.md};
|
|
|
|
`,
|
|
|
|
}));
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
dashboard: DashboardModel;
|
|
|
|
panel: PanelModel;
|
2020-02-07 07:59:04 -06:00
|
|
|
updateLocation: typeof updateLocation;
|
2019-12-16 02:18:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
dirtyPanel?: PanelModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class PanelEditor extends PureComponent<Props, State> {
|
2020-02-07 07:59:04 -06:00
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
const { panel } = props;
|
|
|
|
const dirtyPanel = panel.getEditClone();
|
|
|
|
this.state = { dirtyPanel };
|
|
|
|
}
|
2019-12-16 02:18:48 -06:00
|
|
|
|
2020-02-07 07:59:04 -06:00
|
|
|
onPanelUpdate = () => {
|
|
|
|
const { dirtyPanel } = this.state;
|
|
|
|
const { dashboard } = this.props;
|
|
|
|
dashboard.updatePanel(dirtyPanel);
|
|
|
|
};
|
2019-12-16 02:18:48 -06:00
|
|
|
|
2020-02-07 07:59:04 -06:00
|
|
|
onPanelExit = () => {
|
|
|
|
const { updateLocation } = this.props;
|
|
|
|
this.onPanelUpdate();
|
|
|
|
updateLocation({
|
|
|
|
query: { editPanel: null },
|
|
|
|
partial: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
onDiscard = () => {
|
|
|
|
this.props.updateLocation({
|
|
|
|
query: { editPanel: null },
|
|
|
|
partial: true,
|
|
|
|
});
|
|
|
|
};
|
2019-12-16 02:18:48 -06:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { dashboard } = this.props;
|
|
|
|
const { dirtyPanel } = this.state;
|
|
|
|
|
|
|
|
const styles = getStyles(config.theme);
|
|
|
|
|
|
|
|
if (!dirtyPanel) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-02-07 07:59:04 -06:00
|
|
|
<>
|
|
|
|
<div className={styles.wrapper}>
|
|
|
|
<div className={styles.leftPane}>
|
|
|
|
<div className={styles.leftPaneViz}>
|
|
|
|
<DashboardPanel
|
|
|
|
dashboard={dashboard}
|
|
|
|
panel={dirtyPanel}
|
|
|
|
isEditing={false}
|
|
|
|
isInEditMode
|
|
|
|
isFullscreen={false}
|
|
|
|
isInView={true}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className={styles.leftPaneData}>
|
|
|
|
<QueriesTab panel={dirtyPanel} dashboard={dashboard} />
|
|
|
|
</div>
|
2019-12-16 02:18:48 -06:00
|
|
|
</div>
|
2020-02-07 07:59:04 -06:00
|
|
|
<div className={styles.rightPane}>
|
|
|
|
<Forms.Button variant="destructive" onClick={this.onDiscard}>
|
|
|
|
Discard
|
|
|
|
</Forms.Button>
|
|
|
|
<Forms.Button onClick={this.onPanelExit}>Exit</Forms.Button>
|
2019-12-16 02:18:48 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-02-07 07:59:04 -06:00
|
|
|
</>
|
2019-12-16 02:18:48 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-02-07 07:59:04 -06:00
|
|
|
|
|
|
|
const mapStateToProps = (state: StoreState) => ({
|
|
|
|
location: state.location,
|
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
updateLocation,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(PanelEditor);
|