Skip to content

Commit 75140e3

Browse files
committed
Add Insights (zero-effort issues)
Signed-off-by: Marek Aufart <[email protected]>
1 parent 3482b3f commit 75140e3

File tree

8 files changed

+110
-8
lines changed

8 files changed

+110
-8
lines changed

src/Routes.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Bullseye, Spinner } from "@patternfly/react-core";
66
// At least one page should not have lazy() for not having "[mini-css-extract-plugin] Conflicting order." error
77
const ApplicationList = lazy(() => import("./pages/application-list"));
88
const IssuesList = lazy(() => import("./pages/issues-list"));
9+
const InsightsList = lazy(() => import("./pages/insights-list"));
910
const DependenciesList = lazy(() => import("./pages/dependencies-list"));
1011
const AppEdit = lazy(() => import("./pages/application-details"));
1112
const AppEditDashboard = lazy(
@@ -51,6 +52,22 @@ export const AppRoutes = () => {
5152
path: "/issues/applications/:applicationId",
5253
hasDescendant: false,
5354
},
55+
// Insights
56+
{
57+
Component: InsightsList,
58+
path: "/insights",
59+
hasDescendant: false,
60+
},
61+
{
62+
Component: InsightsList,
63+
path: "/insights/applications",
64+
hasDescendant: false,
65+
},
66+
{
67+
Component: InsightsList,
68+
path: "/insights/applications/:applicationId",
69+
hasDescendant: false,
70+
},
5471
// Dependencies
5572
{
5673
Component: DependenciesList,

src/api/report.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface ReportDto {
55
rulesets?: RulesetDto[];
66
depItems?: DependencyItemDto[];
77
issues?: IssueDto[];
8+
insights?: IssueDto[];
89
dependencies?: DependencyDto[];
910
tags?: TagDto[];
1011
}

src/layout/sidebar.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ export const SidebarApp: React.FC = () => {
3838
Issues
3939
</NavLink>
4040
</NavList>
41+
<NavList>
42+
<NavLink
43+
to={
44+
!currentContext
45+
? "/insights/applications"
46+
: "/insights/applications/" + currentContext.key
47+
}
48+
className={({ isActive }) =>
49+
css("pf-v5-c-nav__link", isActive ? "pf-m-current" : "")
50+
}
51+
>
52+
Insights
53+
</NavLink>
54+
</NavList>
4155
<NavList>
4256
<NavLink
4357
to={

src/pages/application-details/application-details.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export const ApplicationEdit: React.FC = () => {
4444
title: "Issues",
4545
path: `/applications/${application?.id}/issues`,
4646
},
47+
{
48+
title: "Insights",
49+
path: `/applications/${application?.id}/insights`,
50+
},
4751
{
4852
title: "Dependencies",
4953
path: `/applications/${application?.id}/dependencies`,
@@ -53,12 +57,6 @@ export const ApplicationEdit: React.FC = () => {
5357
path: `/applications/${application?.id}/technologies`,
5458
},
5559
];
56-
if (application?.insights && application?.insights?.length > 0) {
57-
result.push({
58-
title: "Insights",
59-
path: `/applications/${application?.id}/insights`,
60-
})
61-
}
6260
return result;
6361
}, [
6462
application,

src/pages/application-details/pages/insights/insights.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import { useOutletContext } from "react-router-dom";
33

4-
import { PageSection } from "@patternfly/react-core";
4+
import { PageSection, Title } from "@patternfly/react-core";
55

66
import { ApplicationProcessed } from "@app/models/api-enriched";
77
import { ViolationsTable } from "@app/shared/components";
@@ -11,6 +11,9 @@ export const Insights: React.FC = () => {
1111

1212
return (
1313
<PageSection>
14+
<Title headingLevel="h1" size="lg" className="pf-v5-u-mb-md">
15+
Insights (Zero Effort Issues)
16+
</Title>
1417
<ViolationsTable applicationId={application?.id} insightsMode={true}/>
1518
</PageSection>
1619
);

src/pages/insights-list/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { InsightsList as default } from "./insights-list";
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from "react";
2+
import { useMatch, useNavigate } from "react-router-dom";
3+
4+
import {
5+
Divider,
6+
PageSection,
7+
PageSectionVariants,
8+
Text,
9+
TextContent,
10+
Toolbar,
11+
ToolbarContent,
12+
ToolbarItem,
13+
} from "@patternfly/react-core";
14+
15+
import { ALL_APPLICATIONS_ID } from "@app/Constants";
16+
import { Context, SimpleContextSelector } from "@app/context/simple-context";
17+
import { ViolationsTable } from "@app/shared/components/violations-table";
18+
19+
export const InsightsList: React.FC = () => {
20+
const matchInsightsPage = useMatch("/insights");
21+
const matchAllApplicationsPage = useMatch("/insights/applications");
22+
const matchSingleApplicationPage = useMatch(
23+
"/insights/applications/:applicationId"
24+
);
25+
26+
const applicationId = matchInsightsPage
27+
? undefined
28+
: matchAllApplicationsPage
29+
? ALL_APPLICATIONS_ID
30+
: matchSingleApplicationPage?.params.applicationId;
31+
32+
const navigate = useNavigate();
33+
34+
const onContextChange = (context: Context) => {
35+
navigate("/insights/applications/" + context.key);
36+
};
37+
38+
return (
39+
<>
40+
<PageSection padding={{ default: "noPadding" }}>
41+
<Toolbar>
42+
<ToolbarContent>
43+
<ToolbarItem>Application:</ToolbarItem>
44+
<ToolbarItem>
45+
<SimpleContextSelector
46+
contextKeyFromURL={applicationId}
47+
onChange={onContextChange}
48+
/>
49+
</ToolbarItem>
50+
</ToolbarContent>
51+
</Toolbar>
52+
</PageSection>
53+
<Divider />
54+
<PageSection variant={PageSectionVariants.light}>
55+
<TextContent>
56+
<Text component="h1">Insights</Text>
57+
<Text component="small">
58+
This report provides a concise summary of all insights identified - issues with zero effort.
59+
</Text>
60+
</TextContent>
61+
</PageSection>
62+
<PageSection variant={PageSectionVariants.default}>
63+
<ViolationsTable applicationId={applicationId} insightsMode={true} />
64+
</PageSection>
65+
</>
66+
);
67+
};

src/queries/report.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ export const useAllApplications = () => {
183183
(a.issues ? issuesFromIssuesDto(a.id, a.issues) : [] as IssueProcessed[]);
184184

185185
const insights: IssueProcessed[] = a.rulesets ?
186-
issuesFromRulesetsDto(a.id, a.files, a.rulesets, true) : [] as IssueProcessed[];
186+
issuesFromRulesetsDto(a.id, a.files, a.rulesets, true).filter(insight => insight.effort === 0) :
187+
(a.insights ? issuesFromIssuesDto(a.id, a.insights) : [] as IssueProcessed[]);
187188

188189
const tags: TagDto[] = a.rulesets ?
189190
tagsFromRulesetsDto(a.rulesets) :

0 commit comments

Comments
 (0)