Skip to content

Commit

Permalink
✨ add application insights tab to display insights (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavgaikwad authored Jun 21, 2024
1 parent 3f393f8 commit b9b8e64
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 142 deletions.
2 changes: 1 addition & 1 deletion analyzer-output-parser/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/konveyor/static-report
go 1.20

require (
github.com/konveyor/analyzer-lsp v0.3.0-rc.3.0.20240417133314-1e8c3cfb1112
github.com/konveyor/analyzer-lsp v0.4.0-alpha.1.0.20240612175452-e2284ce673fb
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
4 changes: 2 additions & 2 deletions analyzer-output-parser/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/konveyor/analyzer-lsp v0.3.0-rc.3.0.20240417133314-1e8c3cfb1112 h1:9/swccmunehLP99yWi6rGZBuuWp5fNoh8AOoW85XjWU=
github.com/konveyor/analyzer-lsp v0.3.0-rc.3.0.20240417133314-1e8c3cfb1112/go.mod h1:Cxdhi1mAoz+rjUQmBiRjRyBy1oADavx4BbAZ9BkSwjk=
github.com/konveyor/analyzer-lsp v0.4.0-alpha.1.0.20240612175452-e2284ce673fb h1:WuI2J9Ws03ri3xl45UklmShkIPSMPmgkScBikykS1gU=
github.com/konveyor/analyzer-lsp v0.4.0-alpha.1.0.20240612175452-e2284ce673fb/go.mod h1:GXkSykQ84oE1SyMvFko9s9wRn/FMdl4efLLWSjMX2nU=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand Down
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>
);
};
39 changes: 39 additions & 0 deletions src/queries/mocks/report.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,45 @@ 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: {},
codeSnip: "1 First Line\n2 Second Line"
},
],
}
},
violations: {
"rule-001": {
description: "Test Rule 001\nTest description",
Expand Down
14 changes: 10 additions & 4 deletions src/queries/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ 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 violation: IssueDto = rs.violations[ruleID];
const keys = Object.keys((insightsMode ? rs.insights : rs.violations) || {})
return keys.map((ruleID) => {
const violation: IssueDto = insightsMode ? (rs.insights ? rs.insights[ruleID] : {} as IssueDto): rs.violations[ruleID];
const totalIncidents: number = violation.incidents.length;
const totalEffort: number = (violation.effort ? violation.effort : 0) * totalIncidents;
const name: string = violation.description?.split("\n")[0];
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 b9b8e64

Please sign in to comment.