Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Use violation id instead of description for key #236

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions shared/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ export interface Violation {
category?: Category;
labels?: string[];
incidents: Incident[];
links?: Link[];
extras?: unknown;
effort?: number;
}

export type ViolationWithID = Violation & {
id: string;
};

export interface RuleSet {
name?: string;
description?: string;
tags?: string[];
violations?: { [key: string]: Violation };
insights?: { [key: string]: Violation };
violations?: { [key: string]: ViolationWithID };
insights?: { [key: string]: ViolationWithID };
errors?: { [key: string]: string };
unmatched?: string[];
skipped?: string[];
Expand Down
4 changes: 4 additions & 0 deletions vscode/src/analysis/__tests__/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const FOO: RuleSet = {
violations: {
"foo-01": {
description: "foo-01 description",
id: "foo-01",
category: "mandatory",
labels: ["konveyor.io/target=foo", "konveyor.io/target=bar"],
incidents: [
Expand Down Expand Up @@ -37,6 +38,7 @@ export const BAR: RuleSet = {
violations: {
"bar-01": {
description: "bar-01 description",
id: "bar-01",
category: "mandatory",
labels: ["konveyor.io/target=foo", "konveyor.io/target=bar"],
incidents: [
Expand All @@ -57,6 +59,7 @@ export const BAR: RuleSet = {
},
"bar-02": {
description: "bar-02 description",
id: "bar-02",
category: "mandatory",
labels: ["konveyor.io/target=foo", "konveyor.io/target=bar"],
incidents: [
Expand Down Expand Up @@ -86,6 +89,7 @@ export const DISCOVERY: RuleSet = {
insights: {
"discover-java-files": {
description: "Java source files",
id: "discover-java-files",
labels: [
"konveyor.io/include=always",
"konveyor.io/target=discovery",
Expand Down
4 changes: 2 additions & 2 deletions webview-ui/src/components/AnalysisPage/AnalysisPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {

import ProgressIndicator from "../ProgressIndicator";
import ViolationIncidentsList from "../ViolationIncidentsList";
import { Incident, Violation } from "@editor-extensions/shared";
import { Incident, Violation, ViolationWithID } from "@editor-extensions/shared";
import { useExtensionState } from "../../hooks/useExtensionState";
import { getSolution, openFile, startServer, runAnalysis, stopServer } from "../../hooks/actions";
import { ServerStatusToggle } from "../ServerStatusToggle/ServerStatusToggle";
Expand Down Expand Up @@ -68,7 +68,7 @@ const AnalysisPage: React.FC = () => {
dispatch(serverRunning ? stopServer() : startServer());
};

const violations = useMemo(() => {
const violations: ViolationWithID[] = useMemo(() => {
if (!analysisResults?.length) {
return [];
}
Expand Down
17 changes: 6 additions & 11 deletions webview-ui/src/components/ViolationIncidentsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import {
CardExpandableContent,
} from "@patternfly/react-core";
import { SortAmountDownIcon, TimesIcon } from "@patternfly/react-icons";
import { Incident, Violation, Severity } from "@editor-extensions/shared";
import { Incident, Violation, Severity, ViolationWithID } from "@editor-extensions/shared";
import { IncidentTableGroup } from "./IncidentTable";
import ViolationActionsDropdown from "./ViolationActionsDropdown";

type SortOption = "description" | "incidentCount" | "severity";

interface ViolationIncidentsListProps {
isRunning: boolean;
violations: Violation[];
violations: ViolationWithID[];
focusedIncident?: Incident | null;
onIncidentSelect: (incident: Incident) => void;
onGetSolution: (incidents: Incident[], violation: Violation) => void;
Expand Down Expand Up @@ -136,24 +136,19 @@ const ViolationIncidentsList: React.FC<ViolationIncidentsListProps> = ({
}, [violations, searchTerm, sortBy]);

const renderViolation = useCallback(
(violation: Violation) => {
(violation: ViolationWithID) => {
const truncateText = (text: string, maxLength: number) => {
if (text.length <= maxLength) {
return text;
}
return text.slice(0, maxLength) + "...";
};
const isExpanded = expandedViolations.has(violation.description);
const isExpanded = expandedViolations.has(violation.id);
const highestSeverity = getHighestSeverity(violation.incidents);
const truncatedDescription = truncateText(violation.description, 100);

return (
<Card
isExpanded={isExpanded}
isCompact
key={violation.description}
style={{ marginBottom: "10px" }}
>
<Card isExpanded={isExpanded} isCompact key={violation.id} style={{ marginBottom: "10px" }}>
<CardHeader
actions={{
actions: (
Expand All @@ -167,7 +162,7 @@ const ViolationIncidentsList: React.FC<ViolationIncidentsListProps> = ({
/>
),
}}
onExpand={() => toggleViolation(violation.description)}
onExpand={() => toggleViolation(violation.id)}
>
<Content style={{ marginBottom: "5px" }}>{truncatedDescription}</Content>
<Flex>
Expand Down
Loading