From d93ce69d94d38cfb3305b376162f3b133942903b Mon Sep 17 00:00:00 2001 From: Revanshu Paliwal Date: Thu, 19 Sep 2024 15:42:35 +0200 Subject: [PATCH] SONAR-23064 Display a badge on the projects list when the project has the isAiCodeAssured true --- .../sonar-web/src/main/js/api/components.ts | 1 + .../components/project-card/ProjectCard.tsx | 11 ++++++++ .../__tests__/ProjectCard-test.tsx | 25 +++++++++++++++++++ .../src/main/js/apps/projects/types.ts | 1 + .../resources/org/sonar/l10n/core.properties | 3 ++- 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/server/sonar-web/src/main/js/api/components.ts b/server/sonar-web/src/main/js/api/components.ts index 7c3d752adda..21375f6bd90 100644 --- a/server/sonar-web/src/main/js/api/components.ts +++ b/server/sonar-web/src/main/js/api/components.ts @@ -53,6 +53,7 @@ export interface ProjectBase { export interface ComponentRaw { analysisDate?: string; + isAiCodeAssured?: boolean; isFavorite?: boolean; key: string; leakPeriodDate?: string; diff --git a/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCard.tsx b/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCard.tsx index 36d965f4b0b..8d28bd2d911 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCard.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/project-card/ProjectCard.tsx @@ -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 ( <>
@@ -130,6 +131,16 @@ function renderFirstLine( + {project.isAiCodeAssured && ( + + + + {translate('ai_code')} + + + + )} + {awaitingScan && !isNewCode && !isEmpty(analysisDate) && measures.ncloc !== undefined && ( )} diff --git a/server/sonar-web/src/main/js/apps/projects/components/project-card/__tests__/ProjectCard-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/project-card/__tests__/ProjectCard-test.tsx index 56d5e491bb5..768fe93f295 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/project-card/__tests__/ProjectCard-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/project-card/__tests__/ProjectCard-test.tsx @@ -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); diff --git a/server/sonar-web/src/main/js/apps/projects/types.ts b/server/sonar-web/src/main/js/apps/projects/types.ts index 8d6b00a6f01..5287a14da2c 100644 --- a/server/sonar-web/src/main/js/apps/projects/types.ts +++ b/server/sonar-web/src/main/js/apps/projects/types.ts @@ -22,6 +22,7 @@ import { Dict } from '../../types/types'; export interface Project { analysisDate?: string; + isAiCodeAssured?: boolean; isFavorite?: boolean; isScannable: boolean; key: string; diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 365dd5d9c02..9ad8ea5cfda 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -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. #------------------------------------------------------------------------------ # -- 2.39.5