Skip to content

Commit

Permalink
add application insights tab to display insights
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Gaikwad <pgaikwad@redhat.com>
  • Loading branch information
pranavgaikwad committed Jun 12, 2024
1 parent 92aea03 commit b9641f8
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 138 deletions.
7 changes: 7 additions & 0 deletions src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const AppEditDependencies = lazy(
const AppTechnologies = lazy(
() => import("./pages/application-details/pages/technologies")
);
const AppInsights = lazy(
() => import("./pages/application-details/pages/insights")
)

export type ApplicationRoute = {
applicationId: string;
Expand Down Expand Up @@ -81,6 +84,10 @@ export const AppRoutes = () => {
Component: AppEditIssues,
path: "issues",
},
{
Component: AppInsights,
path: "insights",
},
{
Component: AppEditDependencies,
path: "dependencies",
Expand Down
7 changes: 5 additions & 2 deletions src/api/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ export interface RulesetDto {
violations: {
[key: string]: IssueDto;
}
insights?: {
[key: string]: IssueDto;
}
}

export interface IssueDto {
ruleset?: string;
rule?: string;
name?: string;
description: string;
category: string;
category?: string;
labels: string[];
incidents: IncidentDto[];
links: LinkDto[];
effort: number;
effort?: number;
}

export interface IncidentDto {
Expand Down
1 change: 1 addition & 0 deletions src/models/api-enriched.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ApplicationProcessed {
id: string;
name: string;
issues: IssueProcessed[];
insights: IssueProcessed[];
dependencies: DependencyProcessed[];
tags: TagDto[];
tagsFlat: string[];
Expand Down
6 changes: 6 additions & 0 deletions src/pages/application-details/application-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export const ApplicationEdit: React.FC = () => {
path: `/applications/${application?.id}/technologies`,
},
];
if (application?.insights && application?.insights?.length > 0) {
result.push({
title: "Insights",
path: `/applications/${application?.id}/insights`,
})
}
return result;
}, [
application,
Expand Down
1 change: 1 addition & 0 deletions src/pages/application-details/pages/insights/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Insights as default } from "./insights";
17 changes: 17 additions & 0 deletions src/pages/application-details/pages/insights/insights.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import { useOutletContext } from "react-router-dom";

import { PageSection } from "@patternfly/react-core";

import { ApplicationProcessed } from "@app/models/api-enriched";
import { ViolationsTable } from "@app/shared/components";

export const Insights: React.FC = () => {
const application = useOutletContext<ApplicationProcessed | null>();

return (
<PageSection>
<ViolationsTable applicationId={application?.id} insightsMode={true}/>
</PageSection>
);
};
38 changes: 38 additions & 0 deletions src/queries/mocks/report.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,44 @@ if (
"tag2",
"Category1=tag3,tag4"
],
insights: {
"rule-002": {
description: "Test Rule 001\nTest description",
category: ISSUE_CATEGORIES[0],
labels: [
"konveyor.io/source=src-1",
"konveyor.io/target=tgt-1",
],
links: [
{
title: "Test Link 1",
url: "https://konveyor.io",
},
],
incidents: [
{
uri: "konveyor-jdt://contents/home/pranav/.m2/repository/io/konveyor/demo/config-utils/1.0.0/config-utils-1.0.0.jar?packageName=io.konveyor.demo.config.ApplicationConfiguration.class\u0026source-range=true",
message: "Test message",
lineNumber: 1,
codeSnip: "1 First Line\n2 Second Line\n",
variables: {},
},
{
uri: "file://test-files/file2.java",
message: "Test message",
lineNumber: 1,
codeSnip: "1 First Line\n2 Second Line\n",
variables: {},
},
{
uri: "file://test-files/file3.java",
message: "Test message",
lineNumber: 1,
variables: {},
},
],
}
},
violations: {
"rule-001": {
description: "Test Rule 001\nTest description",
Expand Down
12 changes: 9 additions & 3 deletions src/queries/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ const filterLabelsWithPrefix = (labels: string[], prefix: string): string[] => {
}

// converts violations from analyzer output to IssueProcessed[]
const issuesFromRulesetsDto = (appID: string, filesRaw: FileDto, rulesets: RulesetDto[]): IssueProcessed[] => {
// when insightsMode is set, incidents will be generated from ruleset.insights
const issuesFromRulesetsDto = (appID: string, filesRaw: FileDto, rulesets: RulesetDto[], insightsMode: boolean): IssueProcessed[] => {
return rulesets.flatMap((rs) => {
return Object.keys(rs.violations || {}).map((ruleID) => {
const keys = Object.keys((insightsMode ? rs.insights : rs.violations) || {})
return keys.map((ruleID) => {
const violation: IssueDto = rs.violations[ruleID];
const totalIncidents: number = violation.incidents.length;
const totalEffort: number = (violation.effort ? violation.effort : 0) * totalIncidents;
Expand Down Expand Up @@ -177,9 +179,12 @@ export const useAllApplications = () => {
(data: ReportDto[]): ApplicationProcessed[] =>
data.map((a) => {
const issues: IssueProcessed[] = a.rulesets ?
issuesFromRulesetsDto(a.id, a.files, a.rulesets) :
issuesFromRulesetsDto(a.id, a.files, a.rulesets, false) :
(a.issues ? issuesFromIssuesDto(a.id, a.issues) : [] as IssueProcessed[]);

const insights: IssueProcessed[] = a.rulesets ?
issuesFromRulesetsDto(a.id, a.files, a.rulesets, true) : [] as IssueProcessed[];

const tags: TagDto[] = a.rulesets ?
tagsFromRulesetsDto(a.rulesets) :
(a.tags || [] as TagDto[]);
Expand All @@ -203,6 +208,7 @@ export const useAllApplications = () => {
...a,
id: String(a.id),
issues,
insights,
tags,
tagsFlat,
dependencies,
Expand Down
Loading

0 comments on commit b9641f8

Please sign in to comment.