Skip to content

Commit 0f97d38

Browse files
committed
Merge branch 'react-panels' of github.com:grafana/grafana into react-panels
2 parents 1420147 + 1099dae commit 0f97d38

16 files changed

+126
-91
lines changed

public/app/core/components/grafana_app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { createStore } from 'app/stores/store';
1010
import colors from 'app/core/utils/colors';
1111
import { BackendSrv } from 'app/core/services/backend_srv';
1212
import { DatasourceSrv } from 'app/features/plugins/datasource_srv';
13+
import { AngularLoader, setAngularLoader } from 'app/core/services/angular_loader';
1314

1415
export class GrafanaCtrl {
1516
/** @ngInject */
@@ -22,8 +23,12 @@ export class GrafanaCtrl {
2223
contextSrv,
2324
bridgeSrv,
2425
backendSrv: BackendSrv,
26+
angularLoader: AngularLoader,
2527
datasourceSrv: DatasourceSrv
2628
) {
29+
// make angular loader service available to react components
30+
setAngularLoader(angularLoader);
31+
// create store with env services
2732
createStore({ backendSrv, datasourceSrv });
2833

2934
$scope.init = function() {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import angular from 'angular';
2+
import coreModule from 'app/core/core_module';
3+
import _ from 'lodash';
4+
5+
export interface AngularComponent {
6+
destroy();
7+
}
8+
9+
export class AngularLoader {
10+
/** @ngInject */
11+
constructor(private $compile, private $rootScope) {}
12+
13+
load(elem, scopeProps, template): AngularComponent {
14+
var scope = this.$rootScope.$new();
15+
16+
_.assign(scope, scopeProps);
17+
18+
const compiledElem = this.$compile(template)(scope);
19+
const rootNode = angular.element(elem);
20+
rootNode.append(compiledElem);
21+
22+
return {
23+
destroy: () => {
24+
scope.$destroy();
25+
compiledElem.remove();
26+
},
27+
};
28+
}
29+
}
30+
31+
coreModule.service('angularLoader', AngularLoader);
32+
33+
let angularLoaderInstance: AngularLoader;
34+
35+
export function setAngularLoader(pl: AngularLoader) {
36+
angularLoaderInstance = pl;
37+
}
38+
39+
// away to access it from react
40+
export function getAngularLoader(): AngularLoader {
41+
return angularLoaderInstance;
42+
}

public/app/features/dashboard/all.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import './export_data/export_data_modal';
2222
import './ad_hoc_filters';
2323
import './repeat_option/repeat_option';
2424
import './dashgrid/DashboardGridDirective';
25-
import './dashgrid/PanelLoader';
2625
import './dashgrid/RowOptions';
2726
import './folder_picker/folder_picker';
2827
import './move_to_folder_modal/move_to_folder';

public/app/features/dashboard/dashboard_ctrl.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import config from 'app/core/config';
22

33
import coreModule from 'app/core/core_module';
4-
import { PanelContainer } from './dashgrid/PanelContainer';
54
import { DashboardModel } from './dashboard_model';
65
import { PanelModel } from './panel_model';
76

8-
export class DashboardCtrl implements PanelContainer {
7+
export class DashboardCtrl {
98
dashboard: DashboardModel;
109
dashboardViewState: any;
1110
loadedFallbackDashboard: boolean;
@@ -22,8 +21,7 @@ export class DashboardCtrl implements PanelContainer {
2221
private dashboardSrv,
2322
private unsavedChangesSrv,
2423
private dashboardViewStateSrv,
25-
public playlistSrv,
26-
private panelLoader
24+
public playlistSrv
2725
) {
2826
// temp hack due to way dashboards are loaded
2927
// can't use controllerAs on route yet
@@ -119,10 +117,6 @@ export class DashboardCtrl implements PanelContainer {
119117
return this.dashboard;
120118
}
121119

122-
getPanelLoader() {
123-
return this.panelLoader;
124-
}
125-
126120
timezoneChanged() {
127121
this.$rootScope.$broadcast('refresh');
128122
}

public/app/features/dashboard/dashgrid/DashboardGrid.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import ReactGridLayout from 'react-grid-layout';
33
import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, GRID_COLUMN_COUNT } from 'app/core/constants';
44
import { DashboardPanel } from './DashboardPanel';
55
import { DashboardModel } from '../dashboard_model';
6-
import { PanelContainer } from './PanelContainer';
76
import { PanelModel } from '../panel_model';
87
import classNames from 'classnames';
98
import sizeMe from 'react-sizeme';
@@ -60,18 +59,15 @@ function GridWrapper({
6059
const SizedReactLayoutGrid = sizeMe({ monitorWidth: true })(GridWrapper);
6160

6261
export interface DashboardGridProps {
63-
getPanelContainer: () => PanelContainer;
62+
dashboard: DashboardModel;
6463
}
6564

6665
export class DashboardGrid extends React.Component<DashboardGridProps, any> {
6766
gridToPanelMap: any;
68-
panelContainer: PanelContainer;
69-
dashboard: DashboardModel;
7067
panelMap: { [id: string]: PanelModel };
7168

7269
constructor(props) {
7370
super(props);
74-
this.panelContainer = this.props.getPanelContainer();
7571
this.onLayoutChange = this.onLayoutChange.bind(this);
7672
this.onResize = this.onResize.bind(this);
7773
this.onResizeStop = this.onResizeStop.bind(this);
@@ -81,20 +77,20 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
8177
this.state = { animated: false };
8278

8379
// subscribe to dashboard events
84-
this.dashboard = this.panelContainer.getDashboard();
85-
this.dashboard.on('panel-added', this.triggerForceUpdate.bind(this));
86-
this.dashboard.on('panel-removed', this.triggerForceUpdate.bind(this));
87-
this.dashboard.on('repeats-processed', this.triggerForceUpdate.bind(this));
88-
this.dashboard.on('view-mode-changed', this.onViewModeChanged.bind(this));
89-
this.dashboard.on('row-collapsed', this.triggerForceUpdate.bind(this));
90-
this.dashboard.on('row-expanded', this.triggerForceUpdate.bind(this));
80+
let dashboard = this.props.dashboard;
81+
dashboard.on('panel-added', this.triggerForceUpdate.bind(this));
82+
dashboard.on('panel-removed', this.triggerForceUpdate.bind(this));
83+
dashboard.on('repeats-processed', this.triggerForceUpdate.bind(this));
84+
dashboard.on('view-mode-changed', this.onViewModeChanged.bind(this));
85+
dashboard.on('row-collapsed', this.triggerForceUpdate.bind(this));
86+
dashboard.on('row-expanded', this.triggerForceUpdate.bind(this));
9187
}
9288

9389
buildLayout() {
9490
const layout = [];
9591
this.panelMap = {};
9692

97-
for (let panel of this.dashboard.panels) {
93+
for (let panel of this.props.dashboard.panels) {
9894
let stringId = panel.id.toString();
9995
this.panelMap[stringId] = panel;
10096

@@ -129,15 +125,15 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
129125
this.panelMap[newPos.i].updateGridPos(newPos);
130126
}
131127

132-
this.dashboard.sortPanelsByGridPos();
128+
this.props.dashboard.sortPanelsByGridPos();
133129
}
134130

135131
triggerForceUpdate() {
136132
this.forceUpdate();
137133
}
138134

139135
onWidthChange() {
140-
for (const panel of this.dashboard.panels) {
136+
for (const panel of this.props.dashboard.panels) {
141137
panel.resizeDone();
142138
}
143139
}
@@ -176,11 +172,11 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
176172
renderPanels() {
177173
const panelElements = [];
178174

179-
for (let panel of this.dashboard.panels) {
175+
for (let panel of this.props.dashboard.panels) {
180176
const panelClasses = classNames({ panel: true, 'panel--fullscreen': panel.fullscreen });
181177
panelElements.push(
182178
<div key={panel.id.toString()} className={panelClasses}>
183-
<DashboardPanel panel={panel} dashboard={this.dashboard} panelContainer={this.panelContainer} />
179+
<DashboardPanel panel={panel} dashboard={this.props.dashboard} />
184180
</div>
185181
);
186182
}
@@ -193,8 +189,8 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
193189
<SizedReactLayoutGrid
194190
className={classNames({ layout: true, animated: this.state.animated })}
195191
layout={this.buildLayout()}
196-
isResizable={this.dashboard.meta.canEdit}
197-
isDraggable={this.dashboard.meta.canEdit}
192+
isResizable={this.props.dashboard.meta.canEdit}
193+
isDraggable={this.props.dashboard.meta.canEdit}
198194
onLayoutChange={this.onLayoutChange}
199195
onWidthChange={this.onWidthChange}
200196
onDragStop={this.onDragStop}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { react2AngularDirective } from 'app/core/utils/react2angular';
22
import { DashboardGrid } from './DashboardGrid';
33

4-
react2AngularDirective('dashboardGrid', DashboardGrid, [
5-
['getPanelContainer', { watchDepth: 'reference', wrapApply: false }],
6-
]);
4+
react2AngularDirective('dashboardGrid', DashboardGrid, [['dashboard', { watchDepth: 'reference' }]]);

public/app/features/dashboard/dashgrid/DashboardPanel.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@ import React from 'react';
22
import config from 'app/core/config';
33
import { PanelModel } from '../panel_model';
44
import { DashboardModel } from '../dashboard_model';
5-
import { AttachedPanel } from './PanelLoader';
5+
import { getAngularLoader, AngularComponent } from 'app/core/services/angular_loader';
66
import { DashboardRow } from './DashboardRow';
7-
import { PanelContainer } from './PanelContainer';
87
import { AddPanelPanel } from './AddPanelPanel';
98
import { importPluginModule } from 'app/features/plugins/plugin_loader';
109
import { PanelChrome } from './PanelChrome';
1110

1211
export interface DashboardPanelProps {
1312
panel: PanelModel;
1413
dashboard: DashboardModel;
15-
panelContainer: PanelContainer;
1614
}
1715

1816
export class DashboardPanel extends React.Component<DashboardPanelProps, any> {
1917
element: any;
20-
attachedPanel: AttachedPanel;
18+
angularPanel: AngularComponent;
2119
pluginInfo: any;
2220
pluginExports: any;
2321
specialPanels = {};
@@ -55,17 +53,19 @@ export class DashboardPanel extends React.Component<DashboardPanelProps, any> {
5553
componentDidUpdate() {
5654
// skip loading angular component if we have no element
5755
// or we have already loaded it
58-
if (!this.element || this.attachedPanel) {
56+
if (!this.element || this.angularPanel) {
5957
return;
6058
}
6159

62-
const loader = this.props.panelContainer.getPanelLoader();
63-
this.attachedPanel = loader.load(this.element, this.props.panel, this.props.dashboard);
60+
let loader = getAngularLoader();
61+
var template = '<plugin-component type="panel" class="panel-height-helper"></plugin-component>';
62+
let scopeProps = { panel: this.props.panel, dashboard: this.props.dashboard };
63+
this.angularPanel = loader.load(this.element, scopeProps, template);
6464
}
6565

6666
componentWillUnmount() {
67-
if (this.attachedPanel) {
68-
this.attachedPanel.destroy();
67+
if (this.angularPanel) {
68+
this.angularPanel.destroy();
6969
}
7070
}
7171

public/app/features/dashboard/dashgrid/PanelChrome.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class PanelChrome extends React.Component<PanelChromeProps, any> {
3232
};
3333

3434
let PanelComponent = this.props.component;
35-
console.log('PanelChrome render');
3635

3736
return (
3837
<div className="panel-height-helper">
@@ -42,9 +41,7 @@ export class PanelChrome extends React.Component<PanelChromeProps, any> {
4241
{<PanelComponent />}
4342
</div>
4443
</div>
45-
<div>
46-
{this.props.panel.isEditing && <PanelEditor panel={this.props.panel} dashboard={this.props.dashboard} />}
47-
</div>
44+
{this.props.panel.isEditing && <PanelEditor panel={this.props.panel} dashboard={this.props.dashboard} />}
4845
</div>
4946
);
5047
}
@@ -55,7 +52,7 @@ export class PanelChrome extends React.Component<PanelChromeProps, any> {
5552

5653
if (panel.fullscreen) {
5754
var docHeight = $(window).height();
58-
var editHeight = Math.floor(docHeight * 0.4);
55+
var editHeight = Math.floor(docHeight * 0.3);
5956
var fullscreenHeight = Math.floor(docHeight * 0.8);
6057
height = panel.isEditing ? editHeight : fullscreenHeight;
6158
} else {

public/app/features/dashboard/dashgrid/PanelContainer.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

public/app/features/dashboard/dashgrid/PanelEditor.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,46 @@
11
import React from 'react';
22
import { PanelModel } from '../panel_model';
33
import { DashboardModel } from '../dashboard_model';
4+
import { getAngularLoader, AngularComponent } from 'app/core/services/angular_loader';
45

56
interface PanelEditorProps {
67
panel: PanelModel;
78
dashboard: DashboardModel;
89
}
910

1011
export class PanelEditor extends React.Component<PanelEditorProps, any> {
12+
queryElement: any;
13+
queryComp: AngularComponent;
14+
15+
constructor(props) {
16+
super(props);
17+
}
18+
19+
componentDidMount() {
20+
if (!this.queryElement) {
21+
return;
22+
}
23+
24+
let loader = getAngularLoader();
25+
var template = '<plugin-component type="query-ctrl" />';
26+
let scopeProps = {
27+
ctrl: {
28+
panel: this.props.panel,
29+
dashboard: this.props.dashboard,
30+
panelCtrl: {
31+
panel: this.props.panel,
32+
dashboard: this.props.dashboard,
33+
},
34+
},
35+
target: {},
36+
};
37+
38+
this.queryComp = loader.load(this.queryElement, scopeProps, template);
39+
}
40+
1141
render() {
1242
return (
13-
<div className="tabbed-view tabbed-view--panel-edit">
43+
<div className="tabbed-view tabbed-view--panel-edit-new">
1444
<div className="tabbed-view-header">
1545
<ul className="gf-tabs">
1646
<li className="gf-tabs-item">
@@ -26,7 +56,9 @@ export class PanelEditor extends React.Component<PanelEditorProps, any> {
2656
</button>
2757
</div>
2858

29-
<div className="tabbed-view-body">testing</div>
59+
<div className="tabbed-view-body">
60+
<div ref={element => (this.queryElement = element)} className="panel-height-helper" />
61+
</div>
3062
</div>
3163
);
3264
}

public/app/features/dashboard/dashgrid/PanelLoader.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)