This is an automated email from the ASF dual-hosted git repository.

e2corporation pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new cb58da11 feat: enable rate limit per hour toggle options (#3306)
cb58da11 is described below

commit cb58da11d09bb45e4ccef661bf614db89822712f
Author: Julien Chinapen <[email protected]>
AuthorDate: Tue Oct 18 11:45:53 2022 -0400

    feat: enable rate limit per hour toggle options (#3306)
    
    * feat: enable rate limit per hour toggle options
    
    * fix: reset rateLimit to 0 on disable
    
    * fix: add effect dependency
    
    * fix: update rate limit config for new providers
    
    * fix: extract rate limit tooltip as data const
    
    * fix: use shared rate limit tooltip for bitbucket
---
 config-ui/src/data/ConnectionTooltips.js           | 49 ++++++++++++
 config-ui/src/data/Providers.js                    |  9 +++
 .../pages/configure/connections/ConnectionForm.jsx | 86 +++++++++++++++-------
 3 files changed, 117 insertions(+), 27 deletions(-)

diff --git a/config-ui/src/data/ConnectionTooltips.js 
b/config-ui/src/data/ConnectionTooltips.js
new file mode 100644
index 00000000..97a1af9d
--- /dev/null
+++ b/config-ui/src/data/ConnectionTooltips.js
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+import React from 'react'
+import { Tooltip, Icon, Intent } from '@blueprintjs/core'
+
+const RateLimitTooltip = (props) => {
+  const {
+    tooltip = (
+      <span>
+        Rate Limit requests per hour, <br />
+        Enter a numeric value &gt; 0 to enable.
+      </span>
+    )
+  } = props
+
+  return (
+    <Tooltip content={tooltip} intent={Intent.PRIMARY}>
+      <Icon
+        icon='info-sign'
+        size={12}
+        style={{
+          float: 'left',
+          display: 'inline-block',
+          alignContent: 'center',
+          marginBottom: '4px',
+          marginLeft: '8px',
+          color: '#999'
+        }}
+      />
+    </Tooltip>
+  )
+}
+
+export { RateLimitTooltip }
diff --git a/config-ui/src/data/Providers.js b/config-ui/src/data/Providers.js
index d849dac3..9a3eece8 100644
--- a/config-ui/src/data/Providers.js
+++ b/config-ui/src/data/Providers.js
@@ -25,6 +25,7 @@ import { ReactComponent as TapdProviderIcon } from 
'@/images/integrations/tapd.s
 import { ReactComponent as AzureProviderIcon } from 
'@/images/integrations/azure.svg'
 import { ReactComponent as BitbucketProviderIcon } from 
'@/images/integrations/bitbucket.svg'
 import { ReactComponent as GiteeProviderIcon } from 
'@/images/integrations/gitee.svg'
+import { RateLimitTooltip } from '@/data/ConnectionTooltips.js'
 // import GitExtractorIcon from '@/images/git.png'
 // import RefDiffIcon from '@/images/git-diff.png'
 import FeishuIcon from '@/images/feishu.png'
@@ -105,6 +106,7 @@ const ProviderFormLabels = {
     rateLimitPerHour: (
       <>
         Rate Limit <sup>(per hour)</sup>
+        <RateLimitTooltip />
       </>
     )
   },
@@ -118,6 +120,7 @@ const ProviderFormLabels = {
     rateLimitPerHour: (
       <>
         Rate Limit <sup>(per hour)</sup>
+        <RateLimitTooltip />
       </>
     )
   },
@@ -131,6 +134,7 @@ const ProviderFormLabels = {
     rateLimitPerHour: (
       <>
         Rate Limit <sup>(per hour)</sup>
+        <RateLimitTooltip />
       </>
     )
   },
@@ -170,6 +174,7 @@ const ProviderFormLabels = {
     rateLimitPerHour: (
       <>
         Rate Limit <sup>(per hour)</sup>
+        <RateLimitTooltip />
       </>
     )
   },
@@ -209,6 +214,7 @@ const ProviderFormLabels = {
     rateLimitPerHour: (
       <>
         Rate Limit <sup>(per hour)</sup>
+        <RateLimitTooltip />
       </>
     )
   },
@@ -222,6 +228,7 @@ const ProviderFormLabels = {
     rateLimitPerHour: (
       <>
         Rate Limit <sup>(per hour)</sup>
+        <RateLimitTooltip />
       </>
     )
   },
@@ -235,6 +242,7 @@ const ProviderFormLabels = {
     rateLimitPerHour: (
       <>
         Rate Limit <sup>(per hour)</sup>
+        <RateLimitTooltip />
       </>
     )
   },
@@ -248,6 +256,7 @@ const ProviderFormLabels = {
     rateLimitPerHour: (
       <>
         Rate Limit <sup>(per hour)</sup>
+        <RateLimitTooltip />
       </>
     )
   }
diff --git a/config-ui/src/pages/configure/connections/ConnectionForm.jsx 
b/config-ui/src/pages/configure/connections/ConnectionForm.jsx
index f4349ead..27141721 100644
--- a/config-ui/src/pages/configure/connections/ConnectionForm.jsx
+++ b/config-ui/src/pages/configure/connections/ConnectionForm.jsx
@@ -31,7 +31,8 @@ import {
   // PopoverInteractionKind,
   Intent,
   PopoverInteractionKind,
-  NumericInput
+  NumericInput,
+  Switch
 } from '@blueprintjs/core'
 import { Providers } from '@/data/Providers'
 import FormValidationErrors from '@/components/messages/FormValidationErrors'
@@ -100,6 +101,7 @@ export default function ConnectionForm(props) {
   const [tokenStore, setTokenStore] = useState(initialTokenStore)
   const [personalAccessTokens, setPersonalAccessTokens] = useState([])
   const [tokenTests, setTokenTests] = useState([])
+  const [enableRateLimit, setEnableRateLimit] = useState(rateLimitPerHour > 0)
 
   const patTestPayload = useMemo(
     () => ({ endpoint: endpointUrl, proxy }),
@@ -278,6 +280,10 @@ export default function ConnectionForm(props) {
     )
   }, [allTestResponses, personalAccessTokens, getValidityStatus])
 
+  useEffect(() => {
+    onRateLimitChange((rL) => (!enableRateLimit ? 0 : rL))
+  }, [enableRateLimit, onRateLimitChange])
+
   return (
     <>
       <form className='form form-add-connection'>
@@ -745,7 +751,10 @@ export default function ConnectionForm(props) {
           Providers.GITLAB,
           Providers.JIRA,
           Providers.JENKINS,
-          Providers.TAPD
+          Providers.TAPD,
+          Providers.AZURE,
+          Providers.BITBUCKET,
+          Providers.GITEE
         ].includes(activeProvider?.id) && (
           <>
             <div className='formContainer'>
@@ -789,31 +798,54 @@ export default function ConnectionForm(props) {
                 <Label>
                   {labels ? labels.rateLimitPerHour : <>Rate&nbsp;Limit</>}
                 </Label>
-                <NumericInput
-                  id='connection-ratelimit'
-                  ref={connectionRateLimitRef}
-                  disabled={isTesting || isSaving || isLocked}
-                  min={0}
-                  max={1000000000}
-                  clampValueOnBlur={true}
-                  className={`input input-ratelimit ${
-                    fieldHasError('RateLimit') ? 'invalid-field' : ''
-                  }`}
-                  fill={false}
-                  placeholder={
-                    placeholders.rateLimitPerHour
-                      ? placeholders.rateLimitPerHour
-                      : '1000'
-                  }
-                  allowNumericCharactersOnly={true}
-                  onValueChange={(rateLimitPerHour) => {
-                    onRateLimitChange(rateLimitPerHour)
-                  }}
-                  value={rateLimitPerHour}
-                  rightElement={
-                    <InputValidationError error={getFieldError('RateLimit')} />
-                  }
-                />
+                <div
+                  className='ratelimit-options'
+                  style={{ display: 'flex', float: 'left' }}
+                >
+                  {enableRateLimit && (
+                    <div style={{ marginRight: '10px' }}>
+                      <NumericInput
+                        id='connection-ratelimit'
+                        ref={connectionRateLimitRef}
+                        disabled={isTesting || isSaving || isLocked}
+                        min={0}
+                        max={1000000000}
+                        clampValueOnBlur={true}
+                        className={`input input-ratelimit ${
+                          fieldHasError('RateLimit') ? 'invalid-field' : ''
+                        }`}
+                        fill={false}
+                        placeholder={
+                          placeholders.rateLimitPerHour
+                            ? placeholders.rateLimitPerHour
+                            : '1000'
+                        }
+                        allowNumericCharactersOnly={true}
+                        onValueChange={(rateLimitPerHour) => {
+                          onRateLimitChange(rateLimitPerHour)
+                        }}
+                        value={rateLimitPerHour}
+                        rightElement={
+                          <InputValidationError
+                            error={getFieldError('RateLimit')}
+                          />
+                        }
+                      />
+                    </div>
+                  )}
+                  <Switch
+                    checked={enableRateLimit}
+                    label={
+                      enableRateLimit ? (
+                        <>Enabled &mdash; {rateLimitPerHour} Requests/hr</>
+                      ) : (
+                        'Disabled'
+                      )
+                    }
+                    onChange={() => setEnableRateLimit(!enableRateLimit)}
+                    style={{ marginBottom: '0' }}
+                  />
+                </div>
               </FormGroup>
             </div>
           </>

Reply via email to