From c45da45300ee117f2caae444bb5c7dc53308d008 Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Wed, 7 Sep 2022 13:48:55 +0300 Subject: [PATCH] changes for add token form --- ...Code.module.css => SourceCode.module.scss} | 24 ++++--- .../src/components/SourceCode/SourceCode.tsx | 17 +++-- .../ApiTokenSettings/ApiTokenForm.module.css | 12 ++++ .../ApiTokenSettings/ApiTokenForm.tsx | 70 ++++++++++++++----- 4 files changed, 89 insertions(+), 34 deletions(-) rename grafana-plugin/src/components/SourceCode/{SourceCode.module.css => SourceCode.module.scss} (63%) create mode 100644 grafana-plugin/src/containers/ApiTokenSettings/ApiTokenForm.module.css diff --git a/grafana-plugin/src/components/SourceCode/SourceCode.module.css b/grafana-plugin/src/components/SourceCode/SourceCode.module.scss similarity index 63% rename from grafana-plugin/src/components/SourceCode/SourceCode.module.css rename to grafana-plugin/src/components/SourceCode/SourceCode.module.scss index beabde1e..baff26d5 100644 --- a/grafana-plugin/src/components/SourceCode/SourceCode.module.css +++ b/grafana-plugin/src/components/SourceCode/SourceCode.module.scss @@ -1,29 +1,33 @@ .root { position: relative; width: 100%; + + &:hover .button { + opacity: 1; + } } .scroller { overflow-y: auto; + + &--maxHeight { + max-height: 400px; + } } -.scroller_max-height { - max-height: 400px; -} - -.root .button { +.button { position: absolute; top: 15px; right: 15px; opacity: 0; transition: opacity 0.2s ease; + + &--top { + top: 4px; + } } -.root:hover .button { - opacity: 1; -} - -.root pre { +pre { border-radius: 2px; padding: 12px 20px; } diff --git a/grafana-plugin/src/components/SourceCode/SourceCode.tsx b/grafana-plugin/src/components/SourceCode/SourceCode.tsx index 91c3513c..61fc2202 100644 --- a/grafana-plugin/src/components/SourceCode/SourceCode.tsx +++ b/grafana-plugin/src/components/SourceCode/SourceCode.tsx @@ -6,18 +6,19 @@ import CopyToClipboard from 'react-copy-to-clipboard'; import { openNotification } from 'utils'; -import styles from './SourceCode.module.css'; +import styles from './SourceCode.module.scss'; const cx = cn.bind(styles); interface SourceCodeProps { noMaxHeight?: boolean; showCopyToClipboard?: boolean; - children?: any + isButtonTopPositioned?: boolean; + children?: any; } const SourceCode: FC = (props) => { - const { children, noMaxHeight = false, showCopyToClipboard = true } = props; + const { children, isButtonTopPositioned = false, noMaxHeight = false, showCopyToClipboard = true } = props; return (
@@ -28,14 +29,20 @@ const SourceCode: FC = (props) => { openNotification('Copied!'); }} > - )}
         {children}
diff --git a/grafana-plugin/src/containers/ApiTokenSettings/ApiTokenForm.module.css b/grafana-plugin/src/containers/ApiTokenSettings/ApiTokenForm.module.css
new file mode 100644
index 00000000..bae192e6
--- /dev/null
+++ b/grafana-plugin/src/containers/ApiTokenSettings/ApiTokenForm.module.css
@@ -0,0 +1,12 @@
+.token__inputContainer {
+  width: 100%;
+  display: flex;
+  margin-bottom: 24px;
+}
+
+.token__input {
+  flex-grow: 1;
+}
+.token__copyButton {
+  margin-left: 12px;
+}
diff --git a/grafana-plugin/src/containers/ApiTokenSettings/ApiTokenForm.tsx b/grafana-plugin/src/containers/ApiTokenSettings/ApiTokenForm.tsx
index 8de6d269..85855021 100644
--- a/grafana-plugin/src/containers/ApiTokenSettings/ApiTokenForm.tsx
+++ b/grafana-plugin/src/containers/ApiTokenSettings/ApiTokenForm.tsx
@@ -1,6 +1,7 @@
 import React, { useCallback, HTMLAttributes, useState } from 'react';
 
-import { Button, Field, HorizontalGroup, Input, Modal, VerticalGroup } from '@grafana/ui';
+import { Button, HorizontalGroup, Input, Label, Modal, VerticalGroup } from '@grafana/ui';
+import cn from 'classnames/bind';
 import { get } from 'lodash-es';
 import { observer } from 'mobx-react';
 import CopyToClipboard from 'react-copy-to-clipboard';
@@ -9,6 +10,13 @@ import { ApiToken } from 'models/api_token/api_token.types';
 import { useStore } from 'state/useStore';
 import { openErrorNotification, openNotification } from 'utils';
 
+import styles from './ApiTokenForm.module.css';
+import SourceCode from 'components/SourceCode/SourceCode';
+
+const cx = cn.bind(styles);
+
+const CURL_EXAMPLE = `curl: try 'curl --help' or 'curl --manual' for more information`;
+
 interface TokenCreationModalProps extends HTMLAttributes {
   visible: boolean;
   onHide: () => void;
@@ -16,9 +24,10 @@ interface TokenCreationModalProps extends HTMLAttributes {
 }
 
 const ApiTokenForm = observer((props: TokenCreationModalProps) => {
-  const { visible, onHide = () => {}, onUpdate = () => {} } = props;
+  const { onHide = () => {}, onUpdate = () => {} } = props;
   const [name, setName] = useState('');
   const [token, setToken] = useState('');
+  const [isModalOpen, setIsModalOpen] = useState(true);
 
   const store = useStore();
 
@@ -37,32 +46,55 @@ const ApiTokenForm = observer((props: TokenCreationModalProps) => {
   }, []);
 
   return (
-    
+    
       
-        
-        {token && (
-          <>
-            
-          
-        )}
-        
+        
+        
+ {renderTokenInput()} + {token && ( - { - openNotification('Token copied'); - }} - > - + openNotification('Token copied')}> + )} -
+ + + {CURL_EXAMPLE} + + + + {!token && ( + + )}
); + + function renderTokenInput() { + if (!token) + return ( + + ); + + return ; + } }); export default ApiTokenForm;