From c9b11bfc7ae1ce89d737c938993db5fa0e421fdb Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Fri, 18 Oct 2019 12:09:53 +0200 Subject: [PATCH] ReactMigration: Migrate DataSource HTTP Settings to React (#19452) * Basic components for HTTP settings migration WIP * Add secureJsonFields to DataSourceSettings * Introduce datasource-http-settings-next directive for backward compatibility * fix lint * renames * rename fix * TagsInput component * move tags from app to grafana/ui * implement tagsinput on datasourcesettings * capitalize * new file for react directive for testing * some layout touch ups * FormField story * Minor touch ups * add url validation * using prevent default to prevent updating datasource when adding tag * using Stylefactory and fix tslint issue on MouseEvent * only show tlsauthsettings if tls or ca cert * fix url input length * fix for showAccessOptions * Implemented CertTextArea, removed commented code * removed commented / not used code * Rename and add more elements to Certification component * fixing newSecureJsonData * spelling * Fix issue with checkboxes being undefined * Removed old partials and minor fix * removed unused props from story --- .../DataSourceSettings/BasicAuthSettings.tsx | 61 +++++ .../DataSourceSettings/CertificationKey.tsx | 40 ++++ .../DataSourceHttpSettings.story.tsx | 51 +++++ .../DataSourceHttpSettings.tsx | 208 ++++++++++++++++++ .../DataSourceSettings/HttpProxySettings.tsx | 45 ++++ .../DataSourceSettings/TLSAuthSettings.tsx | 87 ++++++++ .../components/DataSourceSettings/types.ts | 11 + .../components/FormField/FormField.story.tsx | 29 +++ .../src/components/TagsInput/TagItem.tsx | 48 ++++ .../components/TagsInput/TagsInput.story.tsx | 25 +++ .../src/components/TagsInput/TagsInput.tsx | 121 ++++++++++ packages/grafana-ui/src/components/index.ts | 3 +- packages/grafana-ui/src/types/datasource.ts | 2 + packages/grafana-ui/src/utils/index.ts | 1 + .../src/utils/storybook/UseState.tsx | 5 + .../grafana-ui/src}/utils/tags.ts | 0 public/app/core/angular_wrappers.ts | 14 +- .../core/components/TagFilter/TagBadge.tsx | 4 +- public/app/core/directives/tags.ts | 4 +- .../app/features/admin/AdminListUsersCtrl.ts | 4 +- .../datasources/partials/http_settings.html | 114 ---------- .../partials/http_settings_next.html | 1 + .../partials/tls_auth_settings.html | 62 ------ .../datasources/settings/HttpSettingsCtrl.ts | 17 +- 24 files changed, 760 insertions(+), 197 deletions(-) create mode 100644 packages/grafana-ui/src/components/DataSourceSettings/BasicAuthSettings.tsx create mode 100644 packages/grafana-ui/src/components/DataSourceSettings/CertificationKey.tsx create mode 100644 packages/grafana-ui/src/components/DataSourceSettings/DataSourceHttpSettings.story.tsx create mode 100644 packages/grafana-ui/src/components/DataSourceSettings/DataSourceHttpSettings.tsx create mode 100644 packages/grafana-ui/src/components/DataSourceSettings/HttpProxySettings.tsx create mode 100644 packages/grafana-ui/src/components/DataSourceSettings/TLSAuthSettings.tsx create mode 100644 packages/grafana-ui/src/components/DataSourceSettings/types.ts create mode 100644 packages/grafana-ui/src/components/FormField/FormField.story.tsx create mode 100644 packages/grafana-ui/src/components/TagsInput/TagItem.tsx create mode 100644 packages/grafana-ui/src/components/TagsInput/TagsInput.story.tsx create mode 100644 packages/grafana-ui/src/components/TagsInput/TagsInput.tsx rename {public/app/core => packages/grafana-ui/src}/utils/tags.ts (100%) delete mode 100644 public/app/features/datasources/partials/http_settings.html create mode 100644 public/app/features/datasources/partials/http_settings_next.html delete mode 100644 public/app/features/datasources/partials/tls_auth_settings.html diff --git a/packages/grafana-ui/src/components/DataSourceSettings/BasicAuthSettings.tsx b/packages/grafana-ui/src/components/DataSourceSettings/BasicAuthSettings.tsx new file mode 100644 index 00000000000..9fcf126fec4 --- /dev/null +++ b/packages/grafana-ui/src/components/DataSourceSettings/BasicAuthSettings.tsx @@ -0,0 +1,61 @@ +import React from 'react'; +import { HttpSettingsProps } from './types'; +import { FormField } from '../FormField/FormField'; +import { SecretFormField } from '../SecretFormFied/SecretFormField'; + +export const BasicAuthSettings: React.FC = ({ dataSourceConfig, onChange }) => { + const password = dataSourceConfig.secureJsonData ? dataSourceConfig.secureJsonData.basicAuthPassword : ''; + + const onPasswordReset = () => { + onChange({ + ...dataSourceConfig, + basicAuthPassword: '', + secureJsonData: { + ...dataSourceConfig.secureJsonData, + basicAuthPassword: '', + }, + secureJsonFields: { + ...dataSourceConfig.secureJsonFields, + basicAuthPassword: false, + }, + }); + }; + + const onPasswordChange = (event: React.SyntheticEvent) => { + onChange({ + ...dataSourceConfig, + secureJsonData: { + ...dataSourceConfig.secureJsonData, + basicAuthPassword: event.currentTarget.value, + }, + }); + }; + + return ( + <> +
+ onChange({ ...dataSourceConfig, basicAuthUser: event.currentTarget.value })} + /> +
+
+ +
+ + ); +}; diff --git a/packages/grafana-ui/src/components/DataSourceSettings/CertificationKey.tsx b/packages/grafana-ui/src/components/DataSourceSettings/CertificationKey.tsx new file mode 100644 index 00000000000..5ed9a27cb76 --- /dev/null +++ b/packages/grafana-ui/src/components/DataSourceSettings/CertificationKey.tsx @@ -0,0 +1,40 @@ +import React, { ChangeEvent, MouseEvent, FC } from 'react'; + +interface Props { + label: string; + hasCert: boolean; + placeholder: string; + + onChange: (event: ChangeEvent) => void; + onClick: (event: MouseEvent) => void; +} + +export const CertificationKey: FC = ({ hasCert, label, onChange, onClick, placeholder }) => { + return ( +
+
+ +
+ {!hasCert && ( +
+ -
- -
- - reset -
-
- - -
-
-
-
- -
-
- - reset -
-
- -
-
-
- -
-
- - reset -
-
-
- diff --git a/public/app/features/datasources/settings/HttpSettingsCtrl.ts b/public/app/features/datasources/settings/HttpSettingsCtrl.ts index 5b233118057..59b664a3272 100644 --- a/public/app/features/datasources/settings/HttpSettingsCtrl.ts +++ b/public/app/features/datasources/settings/HttpSettingsCtrl.ts @@ -1,5 +1,4 @@ import { coreModule } from 'app/core/core'; -import { createChangeHandler, createResetHandler, PasswordFieldEnum } from '../utils/passwordHandlers'; coreModule.directive('datasourceHttpSettings', () => { return { @@ -8,22 +7,14 @@ coreModule.directive('datasourceHttpSettings', () => { suggestUrl: '@', noDirectAccess: '@', }, - templateUrl: 'public/app/features/datasources/partials/http_settings.html', + templateUrl: 'public/app/features/datasources/partials/http_settings_next.html', link: { - pre: ($scope: any, elem, attrs) => { + pre: ($scope: any) => { // do not show access option if direct access is disabled $scope.showAccessOption = $scope.noDirectAccess !== 'true'; - $scope.showAccessHelp = false; - $scope.toggleAccessHelp = () => { - $scope.showAccessHelp = !$scope.showAccessHelp; + $scope.onChange = (datasourceSetting: any) => { + $scope.current = datasourceSetting; }; - - $scope.getSuggestUrls = () => { - return [$scope.suggestUrl]; - }; - - $scope.onBasicAuthPasswordReset = createResetHandler($scope, PasswordFieldEnum.BasicAuthPassword); - $scope.onBasicAuthPasswordChange = createChangeHandler($scope, PasswordFieldEnum.BasicAuthPassword); }, }, };