]> source.dussan.org Git - sonarqube.git/commitdiff
CODEFIX-189 Simplify accepting the terms and conditions
authorDamien Urruty <damien.urruty@sonarsource.com>
Fri, 8 Nov 2024 17:35:05 +0000 (18:35 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 19 Nov 2024 20:02:54 +0000 (20:02 +0000)
The T&C are automatically accepted when enabling the feature

server/sonar-web/src/main/js/apps/settings/components/CodeFixAdmin.tsx
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index e111ed87715d807ff451f02c52c8820fb1955fcd..486aeebeeb56df126fae21407fc42d8bb2d41267 100644 (file)
@@ -26,9 +26,9 @@ import {
   Heading,
   IconCheckCircle,
   IconError,
-  LinkStandalone,
+  Link,
   Spinner,
-  Text,
+  Text
 } from '@sonarsource/echoes-react';
 import { MutationStatus } from '@tanstack/react-query';
 import { AxiosError } from 'axios';
@@ -37,16 +37,13 @@ import { FormattedMessage } from 'react-intl';
 import { BasicSeparator, HighlightedSection, themeColor, UnorderedList } from '~design-system';
 import { SuggestionServiceStatusCheckResponse } from '../../../api/fix-suggestions';
 import withAvailableFeatures, {
-  WithAvailableFeaturesProps,
+  WithAvailableFeaturesProps
 } from '../../../app/components/available-features/withAvailableFeatures';
 import DocumentationLink from '../../../components/common/DocumentationLink';
 import { DocLink } from '../../../helpers/doc-links';
 import { translate } from '../../../helpers/l10n';
 import { getAiCodeFixTermsOfServiceUrl } from '../../../helpers/urls';
-import {
-  useCheckServiceMutation,
-  useRemoveCodeSuggestionsCache,
-} from '../../../queries/fix-suggestions';
+import { useCheckServiceMutation, useRemoveCodeSuggestionsCache } from '../../../queries/fix-suggestions';
 import { useGetValueQuery, useSaveSimpleValueMutation } from '../../../queries/settings';
 import { Feature } from '../../../types/features';
 import { SettingsKey } from '../../../types/settings';
@@ -68,7 +65,6 @@ function CodeFixAdmin({ hasFeature }: Readonly<Props>) {
   const isCodeFixEnabled = codeFixSetting?.value === 'true';
 
   const [enableCodeFix, setEnableCodeFix] = React.useState(isCodeFixEnabled);
-  const [acceptedTerms, setAcceptedTerms] = React.useState(false);
   const {
     mutate: checkService,
     isIdle,
@@ -94,7 +90,6 @@ function CodeFixAdmin({ hasFeature }: Readonly<Props>) {
 
   const handleCancel = () => {
     setEnableCodeFix(isCodeFixEnabled);
-    setAcceptedTerms(false);
   };
 
   if (!hasFeature(Feature.FixSuggestions)) {
@@ -124,46 +119,37 @@ function CodeFixAdmin({ hasFeature }: Readonly<Props>) {
           label={translate('property.codefix.admin.checkbox.label')}
           checked={Boolean(enableCodeFix)}
           onCheck={() => setEnableCodeFix(!enableCodeFix)}
+          helpText={
+            <FormattedMessage
+              id="property.codefix.admin.terms"
+              defaultMessage={translate('property.codefix.admin.acceptTerm.label')}
+              values={{
+                terms: (
+                  <Link shouldOpenInNewTab to={getAiCodeFixTermsOfServiceUrl()}>
+                    {translate('property.codefix.admin.acceptTerm.terms')}
+                  </Link>
+                ),
+              }}
+            />
+          }
         />
-        {isValueChanged && (
-          <div>
-            <BasicSeparator className="sw-mt-6" />
-            {enableCodeFix && (
-              <Checkbox
-                className="sw-mt-6"
-                label={
-                  <FormattedMessage
-                    id="property.codefix.admin.terms"
-                    defaultMessage={translate('property.codefix.admin.acceptTerm.label')}
-                    values={{
-                      terms: (
-                        <LinkStandalone to={getAiCodeFixTermsOfServiceUrl()}>
-                          {translate('property.codefix.admin.acceptTerm.terms')}
-                        </LinkStandalone>
-                      ),
-                    }}
-                  />
-                }
-                checked={acceptedTerms}
-                onCheck={() => setAcceptedTerms(!acceptedTerms)}
-              />
-            )}
-            <div className="sw-mt-6">
-              <Button
-                variety={ButtonVariety.Primary}
-                isDisabled={!acceptedTerms && enableCodeFix}
-                onClick={() => {
-                  handleSave();
-                }}
-              >
-                {translate('save')}
-              </Button>
-              <Button className="sw-ml-3" variety={ButtonVariety.Default} onClick={handleCancel}>
-                {translate('cancel')}
-              </Button>
-            </div>
+        <div>
+          <BasicSeparator className="sw-mt-6" />
+          <div className="sw-mt-6">
+            <Button
+              variety={ButtonVariety.Primary}
+              isDisabled={!isValueChanged}
+              onClick={() => {
+                handleSave();
+              }}
+            >
+              {translate('save')}
+            </Button>
+            <Button className="sw-ml-3" variety={ButtonVariety.Default} onClick={handleCancel}>
+              {translate('cancel')}
+            </Button>
           </div>
-        )}
+        </div>
       </div>
       <div className="sw-flex-col sw-w-abs-600 sw-p-6">
         <HighlightedSection className="sw-items-start">
index 77db33e8c0d31958a2946bcf507e4914c462fc31..fbe809bd8df89c0bf352b54b446fe60096b47872 100644 (file)
@@ -1925,7 +1925,7 @@ property.category.housekeeping.auditLogs=Audit Logs
 property.codefix.admin.title=Enable AI-generated fix suggestions
 property.codefix.admin.description=Activate this option to enable any user in your organization to generate an AI-suggested code fix for an issue using the Sonar AI CodeFix service.
 property.codefix.admin.checkbox.label=Enable AI CodeFix
-property.codefix.admin.acceptTerm.label=I have read and I accept the {terms}
+property.codefix.admin.acceptTerm.label=By activating this option, you agree to the {terms}
 property.codefix.admin.acceptTerm.terms=AI CodeFix Terms
 property.codefix.admin.promoted_section.title=Free - early access feature
 property.codefix.admin.promoted_section.content1=This no cost trial is offered to you at Sonar’s discretion. Sonar can decide to stop this trial anytime.