From 84b1519480b687f0b00f859cc92aafabe9ecedbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 20 Sep 2017 17:44:23 +0200 Subject: [PATCH 1/2] tech: initial react poc --- package.json | 11 +- public/app/app.ts | 2 + public/app/core/components/CoolButton.tsx | 67 ++++++++ public/app/core/core.ts | 2 + .../features/plugins/partials/ds_edit.html | 4 + public/app/headers/common.d.ts | 6 - public/app/system.conf.js | 4 +- tasks/options/copy.js | 3 + tsconfig.json | 5 +- yarn.lock | 144 +++++++++++++++--- 10 files changed, 216 insertions(+), 32 deletions(-) create mode 100644 public/app/core/components/CoolButton.tsx diff --git a/package.json b/package.json index f83605611de..2e4f174dec0 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,8 @@ "url": "http://github.com/grafana/grafana.git" }, "devDependencies": { + "@types/react": "^16.0.5", + "@types/react-dom": "^15.5.4", "autoprefixer": "^6.4.0", "es6-promise": "^3.0.2", "es6-shim": "^0.35.1", @@ -48,7 +50,7 @@ "mocha": "3.2.0", "phantomjs-prebuilt": "^2.1.14", "reflect-metadata": "0.1.8", - "rxjs": "^5.0.0-rc.5", + "rxjs": "^5.4.3", "sass-lint": "^1.10.2", "systemjs": "0.19.41", "zone.js": "^0.7.2" @@ -70,13 +72,16 @@ "karma-sinon": "^1.0.5", "lodash": "^4.17.4", "mousetrap": "^1.6.0", + "ngreact": "^0.4.1", + "react": "^15.6.1", + "react-dom": "^15.6.1", "remarkable": "^1.7.1", "sinon": "1.17.6", "systemjs-builder": "^0.15.34", "tether": "^1.4.0", "tether-drop": "https://github.com/torkelo/drop", - "tslint": "^5.1.0", - "typescript": "^2.2.2", + "tslint": "^5.7.0", + "typescript": "^2.5.2", "virtual-scroll": "^1.1.1" } } diff --git a/public/app/app.ts b/public/app/app.ts index 3603e793d5c..27039c01350 100644 --- a/public/app/app.ts +++ b/public/app/app.ts @@ -9,6 +9,7 @@ import 'angular-sanitize'; import 'angular-dragdrop'; import 'angular-bindonce'; import 'angular-ui'; +import 'ngreact'; import $ from 'jquery'; import angular from 'angular'; @@ -84,6 +85,7 @@ export class GrafanaApp { 'pasvaz.bindonce', 'ui.bootstrap', 'ui.bootstrap.tpls', + 'react' ]; var module_types = ['controllers', 'directives', 'factories', 'services', 'filters', 'routes']; diff --git a/public/app/core/components/CoolButton.tsx b/public/app/core/components/CoolButton.tsx new file mode 100644 index 00000000000..7dd7988c421 --- /dev/null +++ b/public/app/core/components/CoolButton.tsx @@ -0,0 +1,67 @@ + +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 { + + constructor(props) { + super(props); + + this.state = {count: 1}; + } + + onClick() { + this.setState(prevState => ({ + count: prevState.count + 1 + })); + console.log(this.state.count); + } + + render() { + return ( +
+

Hello

+
{this.state.count}
+ Go to alerting +
+ ); + } +} + +export interface Props { + fname: string; + onClick: () => void; +} + +function SecondButton({fname, onClick}: Props) { + return ( +
+
+ Hello {fname} +
+
+ +
+
+ ); +} + +coreModule.directive('coolButton', function(reactDirective) { + return reactDirective(CoolButton); +}); + +coreModule.directive('secondButton', function(reactDirective) { + return reactDirective(SecondButton, [ + ['fname', {watchDepth: 'value'}] + ]); +}); diff --git a/public/app/core/core.ts b/public/app/core/core.ts index 6a5702d1f12..140c75fe863 100644 --- a/public/app/core/core.ts +++ b/public/app/core/core.ts @@ -51,6 +51,7 @@ import {helpModal} from './components/help/help'; import {collapseBox} from './components/collapse_box'; import {JsonExplorer} from './components/json_explorer/json_explorer'; import {NavModelSrv, NavModel} from './nav_model_srv'; +import {CoolButton} from './components/CoolButton'; export { @@ -80,4 +81,5 @@ export { JsonExplorer, NavModelSrv, NavModel, + CoolButton, }; diff --git a/public/app/features/plugins/partials/ds_edit.html b/public/app/features/plugins/partials/ds_edit.html index f01ca47153b..fd978d8b704 100644 --- a/public/app/features/plugins/partials/ds_edit.html +++ b/public/app/features/plugins/partials/ds_edit.html @@ -1,6 +1,10 @@
+ + + +