From dcfc74ef008e9bc8abe8ead1f4fb3c1c392eb11c Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Fri, 8 Nov 2019 10:02:51 +0100 Subject: [PATCH] ReactMigration: Migrate Prometheus config page to React (#20248) * add basic components * adding onchange handler for Prom settings * move options outside component * reorder imports * Add missing setting --- .../datasource/prometheus/config_ctrl.ts | 9 -- .../prometheus/configuration/ConfigEditor.tsx | 21 +++ .../prometheus/configuration/PromSettings.tsx | 122 ++++++++++++++++++ .../plugins/datasource/prometheus/module.ts | 20 +-- .../prometheus/partials/config.html | 70 ---------- 5 files changed, 153 insertions(+), 89 deletions(-) delete mode 100644 public/app/plugins/datasource/prometheus/config_ctrl.ts create mode 100644 public/app/plugins/datasource/prometheus/configuration/ConfigEditor.tsx create mode 100644 public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx delete mode 100644 public/app/plugins/datasource/prometheus/partials/config.html diff --git a/public/app/plugins/datasource/prometheus/config_ctrl.ts b/public/app/plugins/datasource/prometheus/config_ctrl.ts deleted file mode 100644 index 0385b92f3f5..00000000000 --- a/public/app/plugins/datasource/prometheus/config_ctrl.ts +++ /dev/null @@ -1,9 +0,0 @@ -export class PrometheusConfigCtrl { - static templateUrl = 'public/app/plugins/datasource/prometheus/partials/config.html'; - current: any; - - /** @ngInject */ - constructor($scope: any) { - this.current.jsonData.httpMethod = this.current.jsonData.httpMethod || 'GET'; - } -} diff --git a/public/app/plugins/datasource/prometheus/configuration/ConfigEditor.tsx b/public/app/plugins/datasource/prometheus/configuration/ConfigEditor.tsx new file mode 100644 index 00000000000..7053115d4ce --- /dev/null +++ b/public/app/plugins/datasource/prometheus/configuration/ConfigEditor.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { DataSourceHttpSettings } from '@grafana/ui'; +import { DataSourcePluginOptionsEditorProps } from '@grafana/data'; +import { PromSettings } from './PromSettings'; +import { PromOptions } from '../types'; + +export type Props = DataSourcePluginOptionsEditorProps; +export const ConfigEditor = (props: Props) => { + const { options, onOptionsChange } = props; + return ( + <> + + + + + ); +}; diff --git a/public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx b/public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx new file mode 100644 index 00000000000..54546e534f0 --- /dev/null +++ b/public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx @@ -0,0 +1,122 @@ +import React, { SyntheticEvent } from 'react'; +import { EventsWithValidation, FormField, FormLabel, Input, regexValidation, Select } from '@grafana/ui'; +import { DataSourceSettings } from '@grafana/data'; +import { PromOptions } from '../types'; + +const httpOptions = [{ value: 'GET', label: 'GET' }, { value: 'POST', label: 'POST' }]; + +type Props = { + value: DataSourceSettings; + onChange: (value: DataSourceSettings) => void; +}; + +export const PromSettings = (props: Props) => { + const { value, onChange } = props; + + return ( + <> +
+
+
+ + } + tooltip="Set this to your global scrape interval defined in your Prometheus config file. This will be used as a lower limit for the + Prometheus step query parameter." + /> +
+
+
+
+ + } + tooltip="Set the Prometheus query timeout." + /> +
+
+
+ + HTTP Method + + - - Set this to your global scrape interval defined in your Prometheus config file. This will be used as a lower limit for the - Prometheus step query parameter. - -
-
- -
-
- Query timeout - - - Set the Prometheus query timeout. - -
-
- -
- -
- - - Specify the HTTP Method to query Prometheus. (POST is only available in Prometheus >= v2.1.0) - -
-
- - -

Misc

-
-
-
- Custom query parameters - - - Add Custom parameters to Prometheus or Thanos queries. - -
-
-
- -