2017-12-21 04:56:45 -06:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2018-04-26 04:58:42 -05:00
|
|
|
import { Provider } from 'mobx-react';
|
|
|
|
|
2017-12-21 04:56:45 -06:00
|
|
|
import coreModule from 'app/core/core_module';
|
|
|
|
import { store } from 'app/stores/store';
|
2018-04-26 04:58:42 -05:00
|
|
|
import { BackendSrv } from 'app/core/services/backend_srv';
|
|
|
|
import { DatasourceSrv } from 'app/features/plugins/datasource_srv';
|
2017-12-21 04:56:45 -06:00
|
|
|
|
|
|
|
function WrapInProvider(store, Component, props) {
|
|
|
|
return (
|
2018-01-03 13:11:07 -06:00
|
|
|
<Provider {...store}>
|
2017-12-21 04:56:45 -06:00
|
|
|
<Component {...props} />
|
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @ngInject */
|
2018-04-26 04:58:42 -05:00
|
|
|
export function reactContainer($route, $location, backendSrv: BackendSrv, datasourceSrv: DatasourceSrv) {
|
2017-12-21 04:56:45 -06:00
|
|
|
return {
|
|
|
|
restrict: 'E',
|
2017-12-27 06:15:27 -06:00
|
|
|
template: '',
|
2017-12-21 04:56:45 -06:00
|
|
|
link(scope, elem) {
|
2018-04-27 04:49:11 -05:00
|
|
|
let component = $route.current.locals.component;
|
|
|
|
// Dynamic imports return whole module, need to extract default export
|
|
|
|
if (component.default) {
|
|
|
|
component = component.default;
|
|
|
|
}
|
|
|
|
const props = {
|
2018-01-17 09:11:34 -06:00
|
|
|
backendSrv: backendSrv,
|
2018-04-26 04:58:42 -05:00
|
|
|
datasourceSrv: datasourceSrv,
|
2018-01-17 09:11:34 -06:00
|
|
|
};
|
2017-12-21 04:56:45 -06:00
|
|
|
|
|
|
|
ReactDOM.render(WrapInProvider(store, component, props), elem[0]);
|
|
|
|
|
|
|
|
scope.$on('$destroy', function() {
|
|
|
|
ReactDOM.unmountComponentAtNode(elem[0]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
coreModule.directive('reactContainer', reactContainer);
|