How to use @grafana/runtime - 10 common examples

To help you get started, we’ve selected a few @grafana/runtime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mtanda / grafana-aws-athena-datasource / src / datasource.ts View on Github external
applyTemplateVariables(query: AwsAthenaQuery, scopedVars: ScopedVars) {
    // TODO: pass scopedVars to templateSrv.replace()
    const templateSrv = getTemplateSrv();
    query.region = templateSrv.replace(query.region, scopedVars);
    query.maxRows = query.maxRows || '';
    query.cacheDuration = query.cacheDuration || '';
    if (typeof query.queryString === 'undefined' || query.queryString === '') {
      query.queryExecutionId = templateSrv.replace(query.queryExecutionId, scopedVars);
      query.inputs = query.queryExecutionId.split(/,/).map(id => {
        return {
          queryExecutionId: id,
        };
      });
    } else {
      query.queryExecutionId = '';
      query.inputs = [];
    }
    query.queryString = templateSrv.replace(query.queryString, scopedVars) || '';
    query.outputLocation = this.outputLocation;
github grafana / grafana / public / app / routes / GrafanaCtrl.ts View on Github external
$scope: any,
    utilSrv: UtilSrv,
    $rootScope: GrafanaRootScope,
    contextSrv: ContextSrv,
    bridgeSrv: BridgeSrv,
    backendSrv: BackendSrv,
    timeSrv: TimeSrv,
    linkSrv: LinkSrv,
    datasourceSrv: DatasourceSrv,
    keybindingSrv: KeybindingSrv,
    angularLoader: AngularLoader
  ) {
    // make angular loader service available to react components
    setAngularLoader(angularLoader);
    setBackendSrv(backendSrv);
    setDataSourceSrv(datasourceSrv);
    setTimeSrv(timeSrv);
    setLinkSrv(linkSrv);
    setKeybindingSrv(keybindingSrv);
    const store = configureStore();
    setLocationSrv({
      update: (opt: LocationUpdate) => {
        store.dispatch(updateLocation(opt));
      },
    });

    $scope.init = () => {
      $scope.contextSrv = contextSrv;
      $scope.appSubUrl = config.appSubUrl;
      $scope._ = _;

      profiler.init(config, $rootScope);
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / routes / GrafanaCtrl.ts View on Github external
datasourceSrv: DatasourceSrv,
    keybindingSrv: KeybindingSrv,
    dashboardSrv: DashboardSrv,
    angularLoader: AngularLoader
  ) {
    // make angular loader service available to react components
    setAngularLoader(angularLoader);
    setBackendSrv(backendSrv);
    setDataSourceSrv(datasourceSrv);
    setTimeSrv(timeSrv);
    setLinkSrv(linkSrv);
    setKeybindingSrv(keybindingSrv);
    setDashboardSrv(dashboardSrv);

    const store = configureStore();
    setLocationSrv({
      update: (opt: LocationUpdate) => {
        store.dispatch(updateLocation(opt));
      },
    });

    $scope.init = () => {
      $scope.contextSrv = contextSrv;
      $scope.appSubUrl = config.appSubUrl;
      $scope._ = _;

      profiler.init(config, $rootScope);
      utilSrv.init();
      bridgeSrv.init();
    };

    $rootScope.colors = colors;
github grafana / grafana / public / app / routes / GrafanaCtrl.ts View on Github external
backendSrv: BackendSrv,
    timeSrv: TimeSrv,
    linkSrv: LinkSrv,
    datasourceSrv: DatasourceSrv,
    keybindingSrv: KeybindingSrv,
    angularLoader: AngularLoader
  ) {
    // make angular loader service available to react components
    setAngularLoader(angularLoader);
    setBackendSrv(backendSrv);
    setDataSourceSrv(datasourceSrv);
    setTimeSrv(timeSrv);
    setLinkSrv(linkSrv);
    setKeybindingSrv(keybindingSrv);
    const store = configureStore();
    setLocationSrv({
      update: (opt: LocationUpdate) => {
        store.dispatch(updateLocation(opt));
      },
    });

    $scope.init = () => {
      $scope.contextSrv = contextSrv;
      $scope.appSubUrl = config.appSubUrl;
      $scope._ = _;

      profiler.init(config, $rootScope);
      utilSrv.init();
      bridgeSrv.init();
    };

    $rootScope.colors = colors;
github grafana / grafana / public / app / features / dashboard / dashgrid / PanelChromeAngular.tsx View on Github external
loadAngularPanel() {
    const { panel, dashboard } = this.props;

    // if we have no element or already have loaded the panel return
    if (!this.element || panel.angularPanel) {
      return;
    }

    const loader = getAngularLoader();
    const template = '';
    const scopeProps = { panel: panel, dashboard: dashboard };
    const angularPanel = loader.load(this.element, scopeProps, template);

    panel.setAngularPanel(angularPanel);
  }
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / features / plugins / wrappers / AppConfigWrapper.tsx View on Github external
componentDidUpdate(prevProps: Props) {
    if (!this.element || this.state.angularCtrl) {
      return;
    }

    // Set a copy of the meta
    this.model = cloneDeep(this.props.app.meta);

    const loader = getAngularLoader();
    const template = '';
    const scopeProps = { ctrl: this };
    const angularCtrl = loader.load(this.element, scopeProps, template);

    this.setState({ angularCtrl });
  }
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / features / alerting / AlertTab.tsx View on Github external
async loadAlertTab() {
    const { angularPanel, panel } = this.props;

    const scope = angularPanel.getScope();

    // When full page reloading in edit mode the angular panel has on fully compiled & instantiated yet
    if (!scope.$$childHead) {
      setTimeout(() => {
        this.forceUpdate();
      });
      return;
    }

    this.panelCtrl = scope.$$childHead.ctrl;
    const loader = getAngularLoader();
    const template = '';

    const scopeProps = { ctrl: this.panelCtrl };

    this.component = loader.load(this.element, scopeProps, template);

    const validatonMessage = await getAlertingValidationMessage(
      panel.transformations,
      panel.targets,
      getDataSourceSrv(),
      panel.datasource
    );

    if (validatonMessage) {
      this.setState({ validatonMessage });
    }
github grafana / grafana / public / app / features / plugins / wrappers / AppConfigWrapper.tsx View on Github external
componentDidUpdate(prevProps: Props) {
    if (!this.element || this.state.angularCtrl) {
      return;
    }

    // Set a copy of the meta
    this.model = cloneDeep(this.props.app.meta);

    const loader = getAngularLoader();
    const template = '';
    const scopeProps = { ctrl: this };
    const angularCtrl = loader.load(this.element, scopeProps, template);

    this.setState({ angularCtrl });
  }
github GridProtectionAlliance / openHistorian / Source / Applications / openHistorian / openHistorian / Grafana / public / app / features / dashboard / panel_editor / QueryEditorRow.tsx View on Github external
// check if we need to load another datasource
    if (loadedDataSourceValue !== this.props.dataSourceValue) {
      if (this.angularQueryEditor) {
        this.angularQueryEditor.destroy();
        this.angularQueryEditor = null;
      }
      this.loadDatasource();
      return;
    }

    if (!this.element || this.angularQueryEditor) {
      return;
    }

    const loader = getAngularLoader();
    const template = '';
    const scopeProps = { ctrl: this.getAngularQueryComponentScope() };
    this.angularQueryEditor = loader.load(this.element, scopeProps, template);
    this.angularScope = scopeProps.ctrl;
  }
github sbueringer / grafana-consul-datasource / src / DataSource.ts View on Github external
query(options: DataQueryRequest): Observable {
    for (const target of options.targets) {
      target.target = getTemplateSrv().replace(target.target, options.scopedVars);
    }

    // store the targets in activeTargets so we can
    // access the legendFormat later on via the refId
    let activeTargets: { [key: string]: any } = {};
    for (const target of options.targets) {
      if (target.hide) {
        continue;
      }
      activeTargets[target.refId] = target;
    }

    return super.query(options).pipe(
      map((rsp: DataQueryResponse) => {
        const finalRsp: DataQueryResponse = { data: [], state: LoadingState.Done };