]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23064 Display a badge on the projects list when the project has the isAiCodeAss...
authorRevanshu Paliwal <revanshu.paliwal@sonarsource.com>
Thu, 19 Sep 2024 13:42:35 +0000 (15:42 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 25 Sep 2024 20:02:53 +0000 (20:02 +0000)
server/sonar-web/src/main/js/api/components.ts
server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCard.tsx
server/sonar-web/src/main/js/apps/projects/components/project-card/__tests__/ProjectCard-test.tsx
server/sonar-web/src/main/js/apps/projects/types.ts
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 7c3d752adda5d283a57adaf46178f87fa229c21a..21375f6bd90726de4792f743e01a45b8f2a397b2 100644 (file)
@@ -53,6 +53,7 @@ export interface ProjectBase {
 
 export interface ComponentRaw {
   analysisDate?: string;
+  isAiCodeAssured?: boolean;
   isFavorite?: boolean;
   key: string;
   leakPeriodDate?: string;
index 36d965f4b0b10c35f4bd8fd8a282373ff2aed35e..8d28bd2d91170ebc1d22e6051067817aaadbd436 100644 (file)
@@ -85,6 +85,7 @@ function renderFirstLine(
     measures.ncloc !== undefined;
   const formatted = formatMeasure(measures[MetricKey.alert_status], MetricType.Level);
   const qualityGateLabel = translateWithParameters('overview.quality_gate_x', formatted);
+
   return (
     <>
       <div className="sw-flex sw-justify-between sw-items-center ">
@@ -130,6 +131,16 @@ function renderFirstLine(
             </span>
           </Tooltip>
 
+          {project.isAiCodeAssured && (
+            <Tooltip content={translate('projects.ai_code.content')}>
+              <span>
+                <Badge variant="new" className="sw-ml-2">
+                  {translate('ai_code')}
+                </Badge>
+              </span>
+            </Tooltip>
+          )}
+
           {awaitingScan && !isNewCode && !isEmpty(analysisDate) && measures.ncloc !== undefined && (
             <ChangeInCalculation qualifier={qualifier} />
           )}
index 56d5e491bb5661eb7a9c91f0c9f2203d8ffd6b41..768fe93f2952abbf3f74357ac29b93dedf1f798f 100644 (file)
@@ -51,6 +51,19 @@ const PROJECT: Project = {
   tags: [],
   visibility: Visibility.Public,
   isScannable: false,
+  isAiCodeAssured: true,
+};
+
+const PROJECT_WITH_AI_CODE_DISABLED: Project = {
+  analysisDate: '2017-01-01',
+  key: 'foo',
+  measures: MEASURES,
+  name: 'Foo',
+  qualifier: ComponentQualifier.Project,
+  tags: [],
+  visibility: Visibility.Public,
+  isScannable: false,
+  isAiCodeAssured: false,
 };
 
 const USER_LOGGED_OUT = mockCurrentUser();
@@ -82,6 +95,18 @@ it('should display private badge', () => {
   expect(screen.getByText('visibility.private')).toBeInTheDocument();
 });
 
+it('should display ai code assurance badge when isAiCodeAssured is true', () => {
+  const project: Project = { ...PROJECT, visibility: Visibility.Private };
+  renderProjectCard(project);
+  expect(screen.getByText('ai_code')).toBeInTheDocument();
+});
+
+it('should display ai code assurance badge when isAiCodeAssured is false', () => {
+  const project: Project = { ...PROJECT_WITH_AI_CODE_DISABLED, visibility: Visibility.Private };
+  renderProjectCard(project);
+  expect(screen.queryByText('ai_code')).not.toBeInTheDocument();
+});
+
 it('should display configure analysis button for logged in user and scan rights', () => {
   const user = mockLoggedInUser();
   renderProjectCard({ ...PROJECT, isScannable: true, analysisDate: undefined }, user);
index 8d6b00a6f0120acb375153cc4c524dd3ec76f3ae..5287a14da2c07b42e7e8be06cd825ac5eb545dd9 100644 (file)
@@ -22,6 +22,7 @@ import { Dict } from '../../types/types';
 
 export interface Project {
   analysisDate?: string;
+  isAiCodeAssured?: boolean;
   isFavorite?: boolean;
   isScannable: boolean;
   key: string;
index 365dd5d9c028786dcea7147a2ecd48d3c36cb061..9ad8ea5cfdab8e36423c6d5833a228b6623f613e 100644 (file)
@@ -12,6 +12,7 @@ activate=Activate
 add_verb=Add
 admin=Admin
 after=After
+ai_code=AI Code
 apply=Apply
 all=All
 and=And
@@ -1414,7 +1415,7 @@ projects.awaiting_scan.title=Values will change after the next analysis
 projects.awaiting_scan.description.TRK=The way in which security, reliability, maintainability, and security review counts and ratings are calculated has changed. The values currently displayed will change after the next analysis.
 projects.awaiting_scan.description.APP=The way in which security, reliability, maintainability, and security review counts and ratings are calculated has changed. The values currently displayed will change after all projects in this application have been analyzed.
 projects.awaiting_scan.description.VW=The way in which security, reliability, maintainability, and security review counts and ratings are calculated has changed. The values currently displayed will change after all projects in this portfolio have been analyzed.
-
+projects.ai_code.content=This project contains AI-generated code and benefits from Sonar’s AI Code Assurance.
 
 #------------------------------------------------------------------------------
 #