all files / src/datasource/ datasourceFrames.ui.tsx

78.95% Statements 30/38
55.56% Branches 5/9
75% Functions 9/12
82.86% Lines 29/35
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                                                             
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var React = require("react");
var react_redux_1 = require("react-redux");
var _ = require("lodash");
var dashboard_1 = require("../dashboard");
var DatasourceFrames = (function (_super) {
    __extends(DatasourceFrames, _super);
    function DatasourceFrames() {
        _super.apply(this, arguments);
    }
    DatasourceFrames.prototype.render = function () {
        var _this = this;
        return React.createElement("div", {style: { width: 1, height: 1, position: "fixed", left: 0, top: 0 }}, _.valuesIn(this.props.datasources).map(function (dsState) {
            var pluginLoaded = dashboard_1.default.getInstance().datasourcePluginRegistry.hasPlugin(dsState.type);
            var datasourcePluginState = _this.props.datasourcePlugins[dsState.type];
            return pluginLoaded
                ? React.createElement(DatasourceIFrame, {key: dsState.id, datasourcePluginState: datasourcePluginState, datasourceState: dsState})
                : React.createElement("div", {key: dsState.id}, "Datasource Loading ...");
        }));
    };
    return DatasourceFrames;
}(React.Component));
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = react_redux_1.connect(function (state) {
    return {
        datasources: state.datasources,
        datasourcePlugins: state.datasourcePlugins
    };
}, function (dispatch) {
    return {};
})(DatasourceFrames);
var DatasourceIFrame = (function (_super) {
    __extends(DatasourceIFrame, _super);
    function DatasourceIFrame(props) {
        _super.call(this, props);
    }
    DatasourceIFrame.prototype.componentDidMount = function () {
        var element = this.refs['frame'];
        // TODO: UI is loaded before the datasource is loaded to the registry, this throws then ...
        var dsFactory = dashboard_1.default.getInstance().datasourcePluginRegistry.getPlugin(this.props.datasourceState.type);
        var dsInstance = dsFactory.getInstance(this.props.datasourceState.id);
        dsInstance.iFrame = element;
    };
    // allow-popups allow-same-origin allow-modals allow-forms
    // A sandbox that includes both the allow-same-origin and allow-scripts flags,
    // then the framed page can reach up into the parent, and remove the sandbox attribute entirely.
    // Only if the framed content comes from the same origin of course.
    DatasourceIFrame.prototype.render = function () {
        return React.createElement("iframe", {id: 'frame-' + this.props.datasourceState.id, ref: "frame", src: "datasource.html#" + this.props.datasourcePluginState.url, frameBorder: "0", width: "100%", height: "100%", scrolling: "no", sandbox: "allow-scripts"}, "Browser does not support iFrames.");
    };
    ;
    return DatasourceIFrame;
}(React.Component));