Commit 84b15194 by Torkel Ödegaard

tech: initial react poc

parent 4326790b
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
"url": "http://github.com/grafana/grafana.git" "url": "http://github.com/grafana/grafana.git"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^16.0.5",
"@types/react-dom": "^15.5.4",
"autoprefixer": "^6.4.0", "autoprefixer": "^6.4.0",
"es6-promise": "^3.0.2", "es6-promise": "^3.0.2",
"es6-shim": "^0.35.1", "es6-shim": "^0.35.1",
...@@ -48,7 +50,7 @@ ...@@ -48,7 +50,7 @@
"mocha": "3.2.0", "mocha": "3.2.0",
"phantomjs-prebuilt": "^2.1.14", "phantomjs-prebuilt": "^2.1.14",
"reflect-metadata": "0.1.8", "reflect-metadata": "0.1.8",
"rxjs": "^5.0.0-rc.5", "rxjs": "^5.4.3",
"sass-lint": "^1.10.2", "sass-lint": "^1.10.2",
"systemjs": "0.19.41", "systemjs": "0.19.41",
"zone.js": "^0.7.2" "zone.js": "^0.7.2"
...@@ -70,13 +72,16 @@ ...@@ -70,13 +72,16 @@
"karma-sinon": "^1.0.5", "karma-sinon": "^1.0.5",
"lodash": "^4.17.4", "lodash": "^4.17.4",
"mousetrap": "^1.6.0", "mousetrap": "^1.6.0",
"ngreact": "^0.4.1",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"remarkable": "^1.7.1", "remarkable": "^1.7.1",
"sinon": "1.17.6", "sinon": "1.17.6",
"systemjs-builder": "^0.15.34", "systemjs-builder": "^0.15.34",
"tether": "^1.4.0", "tether": "^1.4.0",
"tether-drop": "https://github.com/torkelo/drop", "tether-drop": "https://github.com/torkelo/drop",
"tslint": "^5.1.0", "tslint": "^5.7.0",
"typescript": "^2.2.2", "typescript": "^2.5.2",
"virtual-scroll": "^1.1.1" "virtual-scroll": "^1.1.1"
} }
} }
...@@ -9,6 +9,7 @@ import 'angular-sanitize'; ...@@ -9,6 +9,7 @@ import 'angular-sanitize';
import 'angular-dragdrop'; import 'angular-dragdrop';
import 'angular-bindonce'; import 'angular-bindonce';
import 'angular-ui'; import 'angular-ui';
import 'ngreact';
import $ from 'jquery'; import $ from 'jquery';
import angular from 'angular'; import angular from 'angular';
...@@ -84,6 +85,7 @@ export class GrafanaApp { ...@@ -84,6 +85,7 @@ export class GrafanaApp {
'pasvaz.bindonce', 'pasvaz.bindonce',
'ui.bootstrap', 'ui.bootstrap',
'ui.bootstrap.tpls', 'ui.bootstrap.tpls',
'react'
]; ];
var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes']; var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes'];
......
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import coreModule from '../core_module';
export interface ICoolButtonProps {
count: number;
}
export interface ICoolButtonState {
count: number;
}
export class CoolButton extends React.Component<ICoolButtonProps, ICoolButtonState> {
constructor(props) {
super(props);
this.state = {count: 1};
}
onClick() {
this.setState(prevState => ({
count: prevState.count + 1
}));
console.log(this.state.count);
}
render() {
return (
<div>
<h2 onClick={this.onClick.bind(this)}>Hello</h2>
<div>{this.state.count}</div>
<a href="/alerting">Go to alerting</a>
</div>
);
}
}
export interface Props {
fname: string;
onClick: () => void;
}
function SecondButton({fname, onClick}: Props) {
return (
<div className="hello">
<div className="greeting">
Hello {fname}
</div>
<div>
<button onClick={onClick}>button</button>
</div>
</div>
);
}
coreModule.directive('coolButton', function(reactDirective) {
return reactDirective(CoolButton);
});
coreModule.directive('secondButton', function(reactDirective) {
return reactDirective(SecondButton, [
['fname', {watchDepth: 'value'}]
]);
});
...@@ -51,6 +51,7 @@ import {helpModal} from './components/help/help'; ...@@ -51,6 +51,7 @@ import {helpModal} from './components/help/help';
import {collapseBox} from './components/collapse_box'; import {collapseBox} from './components/collapse_box';
import {JsonExplorer} from './components/json_explorer/json_explorer'; import {JsonExplorer} from './components/json_explorer/json_explorer';
import {NavModelSrv, NavModel} from './nav_model_srv'; import {NavModelSrv, NavModel} from './nav_model_srv';
import {CoolButton} from './components/CoolButton';
export { export {
...@@ -80,4 +81,5 @@ export { ...@@ -80,4 +81,5 @@ export {
JsonExplorer, JsonExplorer,
NavModelSrv, NavModelSrv,
NavModel, NavModel,
CoolButton,
}; };
<navbar model="ctrl.navModel"></navbar> <navbar model="ctrl.navModel"></navbar>
<div class="page-container"> <div class="page-container">
<cool-button>
</cool-button>
<second-button fname="ctrl.current.name"></second-button>
<div class="page-header"> <div class="page-header">
<h1 ng-show="ctrl.isNew">Add data source</h1> <h1 ng-show="ctrl.isNew">Add data source</h1>
......
/// <reference path="./es6-shim/es6-shim.d.ts" />
declare var System: any; declare var System: any;
...@@ -53,11 +52,6 @@ declare module 'eventemitter3' { ...@@ -53,11 +52,6 @@ declare module 'eventemitter3' {
export default config; export default config;
} }
declare module 'virtual-scroll' {
var config: any;
export default config;
}
declare module 'mousetrap' { declare module 'mousetrap' {
var config: any; var config: any;
export default config; export default config;
......
...@@ -2,7 +2,9 @@ System.config({ ...@@ -2,7 +2,9 @@ System.config({
defaultJSExtenions: true, defaultJSExtenions: true,
baseURL: 'public', baseURL: 'public',
paths: { paths: {
'virtual-scroll': 'vendor/npm/virtual-scroll/src/index.js', 'react': 'vendor/npm/react/dist/react.js',
'react-dom': 'vendor/npm/react-dom/dist/react-dom.js',
'ngreact': 'vendor/npm/ngreact/ngReact.js',
'mousetrap': 'vendor/npm/mousetrap/mousetrap.js', 'mousetrap': 'vendor/npm/mousetrap/mousetrap.js',
'remarkable': 'vendor/npm/remarkable/dist/remarkable.js', 'remarkable': 'vendor/npm/remarkable/dist/remarkable.js',
'tether': 'vendor/npm/tether/dist/js/tether.js', 'tether': 'vendor/npm/tether/dist/js/tether.js',
......
...@@ -38,6 +38,9 @@ module.exports = function(config) { ...@@ -38,6 +38,9 @@ module.exports = function(config) {
'remarkable/dist/*', 'remarkable/dist/*',
'virtual-scroll/**/*', 'virtual-scroll/**/*',
'mousetrap/**/*', 'mousetrap/**/*',
'react/dist/*.js',
'react-dom/dist/*.js',
'ngreact/ngReact.js',
], ],
dest: '<%= srcDir %>/vendor/npm' dest: '<%= srcDir %>/vendor/npm'
} }
......
...@@ -5,19 +5,22 @@ ...@@ -5,19 +5,22 @@
"outDir": "public_gen", "outDir": "public_gen",
"noImplicitAny": false, "noImplicitAny": false,
"target": "es5", "target": "es5",
"lib": ["es6", "dom"],
"rootDir": "public/", "rootDir": "public/",
"module": "system", "module": "system",
"jsx": "react",
"noEmitOnError": true, "noEmitOnError": true,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"noImplicitReturns":false, "noImplicitReturns":false,
"noImplicitThis":false, "noImplicitThis": false,
"noImplicitUseStrict":false, "noImplicitUseStrict":false,
"noUnusedLocals":false, "noUnusedLocals":false,
"moduleResolution": "classic" "moduleResolution": "classic"
}, },
"include": [ "include": [
"public/app/**/*.ts", "public/app/**/*.ts",
"public/app/**/*.tsx",
"public/test/**/*.ts" "public/test/**/*.ts"
], ],
"exclude": [ "exclude": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment