The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/routes/ReactContainer.tsx

40 lines
1.0 KiB

import React from 'react';
import ReactDOM from 'react-dom';
8 years ago
import { Provider } from 'mobx-react';
import coreModule from 'app/core/core_module';
import { store } from 'app/stores/store';
8 years ago
import { BackendSrv } from 'app/core/services/backend_srv';
import { DatasourceSrv } from 'app/features/plugins/datasource_srv';
function WrapInProvider(store, Component, props) {
return (
<Provider {...store}>
<Component {...props} />
</Provider>
);
}
/** @ngInject */
8 years ago
export function reactContainer($route, $location, backendSrv: BackendSrv, datasourceSrv: DatasourceSrv) {
return {
restrict: 'E',
template: '',
link(scope, elem) {
8 years ago
let component = $route.current.locals.component.default;
let props = {
backendSrv: backendSrv,
8 years ago
datasourceSrv: datasourceSrv,
};
ReactDOM.render(WrapInProvider(store, component, props), elem[0]);
scope.$on('$destroy', function() {
ReactDOM.unmountComponentAtNode(elem[0]);
});
},
};
}
coreModule.directive('reactContainer', reactContainer);