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

✨ Filter violations and auto open files in wizard #55

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 20 additions & 2 deletions vscode/src/webview/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from "@patternfly/react-core";
import { SearchIcon } from "@patternfly/react-icons";
import { vscode } from "../globals";
import { RuleSet } from "../types";
import { Incident, RuleSet } from "../types";
import { mockResults } from "../mockResults";
import GuidedApproachWizard from "./GuidedApproachWizard";
import ProgressIndicator from "./ProgressIndicator";
Expand All @@ -33,6 +33,17 @@ const App: React.FC = () => {
const [analysisMessage, setAnalysisMessage] = useState("");
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [isWizardOpen, setIsWizardOpen] = useState(false);
const [focusedIncident, setFocusedIncident] = useState<Incident | null>(null);
const [expandedViolations, setExpandedViolations] = useState<Set<string>>(new Set());

const handleIncidentSelect = (incident: Incident) => {
setFocusedIncident(incident);
vscode.postMessage({
command: "openFile",
file: incident.uri,
line: incident.lineNumber,
});
};

useEffect(() => {
setAnalysisResults(mockResults as RuleSet[]);
Expand Down Expand Up @@ -152,7 +163,14 @@ const App: React.FC = () => {
{isAnalyzing ? (
<ProgressIndicator progress={50} />
) : hasViolations ? (
<ViolationIncidentsList violations={violations} />
<ViolationIncidentsList
violations={violations}
focusedIncident={focusedIncident}
onIncidentSelect={handleIncidentSelect}
compact={false}
expandedViolations={expandedViolations}
setExpandedViolations={setExpandedViolations}
/>
) : (
<EmptyState>
<EmptyStateIcon icon={SearchIcon} />
Expand Down
34 changes: 28 additions & 6 deletions vscode/src/webview/components/GuidedApproachWizard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, useState } from "react";
import React, { useMemo, useState, useEffect } from "react";
import {
Wizard,
WizardNav,
Expand Down Expand Up @@ -28,6 +28,7 @@ const GuidedApproachWizard: React.FC<GuidedApproachWizardProps> = ({ violations,
const [activeStepIndex, setActiveStepIndex] = useState(0);
const [selectedIncident, setSelectedIncident] = useState<Incident | null>(null);
const [quickFix, setQuickFix] = useState<string | null>(null);
const [expandedViolations, setExpandedViolations] = useState<Set<string>>(new Set());

const generateQuickFix = (violation: Violation, incident: Incident) => {
vscode.postMessage({
Expand All @@ -39,6 +40,28 @@ const GuidedApproachWizard: React.FC<GuidedApproachWizardProps> = ({ violations,
});
};

const handleIncidentClick = (incident: Incident) => {
setSelectedIncident(incident);
vscode.postMessage({
command: "openFile",
file: incident.uri,
line: incident.lineNumber,
});
};

// Auto-select the first incident when the wizard opens or when navigating to a new step
useEffect(() => {
if (violations[activeStepIndex] && violations[activeStepIndex].incidents.length > 0) {
const firstIncident = violations[activeStepIndex].incidents[0];
setSelectedIncident(firstIncident);
handleIncidentClick(firstIncident);
setExpandedViolations(new Set([violations[activeStepIndex].description]));
} else {
setSelectedIncident(null);
}
setQuickFix(null);
}, [activeStepIndex, violations]);

// Define the wizard steps
const steps: WizardBasicStep[] = useMemo(() => {
return violations.map((violation, index) => ({
Expand All @@ -50,8 +73,10 @@ const GuidedApproachWizard: React.FC<GuidedApproachWizardProps> = ({ violations,
<ViolationIncidentsList
violations={[violation]}
focusedIncident={selectedIncident}
onIncidentSelect={setSelectedIncident}
onIncidentSelect={handleIncidentClick}
compact={true}
expandedViolations={expandedViolations}
setExpandedViolations={setExpandedViolations}
/>
</StackItem>
<StackItem>
Expand All @@ -73,15 +98,12 @@ const GuidedApproachWizard: React.FC<GuidedApproachWizardProps> = ({ violations,
<Button
variant="primary"
onClick={() => generateQuickFix(violation, selectedIncident)}
isDisabled={!selectedIncident}
>
Generate QuickFix
</Button>
</>
) : (
<Text component={TextVariants.p}>
Select an incident to see details and generate a QuickFix.
</Text>
<Text component={TextVariants.p}>No incidents found for this violation.</Text>
)}
</TextContent>
{quickFix && (
Expand Down
Loading
Loading