Skip to content

Commit

Permalink
Merge branch 'main' into mergeDiff
Browse files Browse the repository at this point in the history
  • Loading branch information
rszwajko authored Nov 21, 2024
2 parents 92a488b + 88daae4 commit 80ad968
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 88 deletions.
1 change: 1 addition & 0 deletions vscode/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
test_out
.vscode-test/
*.vsix
org.eclipse*
21 changes: 0 additions & 21 deletions vscode/src/KonveyorGUIWebviewViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ export class KonveyorGUIWebviewViewProvider implements WebviewViewProvider {

webview.html = this.getHtmlForWebview(webview);
this._setWebviewMessageListener(webview);

if (this._isWebviewReady) {
this._loadInitialContent(webview);
}
}

public getHtmlForWebview(webview: Webview): string {
Expand Down Expand Up @@ -191,30 +187,13 @@ export class KonveyorGUIWebviewViewProvider implements WebviewViewProvider {
const queuedMessage = this._messageQueue.shift();
webview.postMessage(queuedMessage);
}
this._loadInitialContent(webview);
}
},
undefined,
this._disposables,
);
}

private _loadInitialContent(webview: Webview) {
if (this._isWebviewReady && webview) {
const data = this._extensionState.ruleSets;
webview.postMessage({
type: "loadStoredAnalysis",
data,
});
//TODO Commenting out in favor of hardcoded solution data in webviewMessageHandler.ts
// const localChanges = this._extensionState.localChanges;
// webview.postMessage({
// type: "loadSolutions",
// solution: localChanges,
// });
}
}

public dispose() {
while (this._disposables.length) {
const disposable = this._disposables.pop();
Expand Down
4 changes: 4 additions & 0 deletions vscode/src/client/analyzerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,8 @@ export class AnalyzerClient {
}
return null;
}

public isServerRunning(): boolean {
return !!this.analyzerServer && !this.analyzerServer.killed;
}
}
10 changes: 10 additions & 0 deletions vscode/src/webviewMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ export function setupWebviewMessageListener(webview: vscode.Webview, state: Exte
}
break;
}
case "checkServerStatus": {
const isRunning = state.analyzerClient.isServerRunning();
webview.postMessage({ type: "serverStatus", isRunning });
console.log("checkServerStatus", isRunning);
break;
}
case "startServer": {
vscode.commands.executeCommand("konveyor.startAnalyzer");
break;
}
case "solutionResolved": {
console.log("solutionResolved");
const sidebarProvider = state.webviewProviders.get("sidebar");
Expand Down
77 changes: 54 additions & 23 deletions webview-ui/src/components/AnalysisPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// AnalysisPage.tsx
import React, { useState, useMemo } from "react";
import React, { useState, useMemo, useEffect } from "react";
import {
Button,
ButtonVariant,
Expand All @@ -19,17 +19,17 @@ import ProgressIndicator from "./ProgressIndicator";
import ViolationIncidentsList from "./ViolationIncidentsList";
import { Incident, RuleSet } from "@editor-extensions/shared";
import { useVscodeMessages } from "../hooks/useVscodeMessages";
import { sendVscodeMessage } from "../utils/vscodeMessaging";

const AnalysisPage: React.FC = () => {
const [analysisResults, setAnalysisResults] = useState<RuleSet[] | null>();
const [isAnalyzing, setIsAnalyzing] = useState(false);
const [analysisMessage, setAnalysisMessage] = useState("");
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [focusedIncident, setFocusedIncident] = useState<Incident | null>(null);
const [expandedViolations, setExpandedViolations] = useState<Set<string>>(
new Set(),
);
const [expandedViolations, setExpandedViolations] = useState<Set<string>>(new Set());
const [isWaitingForSolution, setIsWaitingForSolution] = useState(false);
const [serverRunning, setServerRunning] = useState(false);

const handleIncidentSelect = (incident: Incident) => {
setFocusedIncident(incident);
Expand All @@ -40,14 +40,28 @@ const AnalysisPage: React.FC = () => {
});
};

// Function to fetch server status
const fetchServerStatus = () => {
vscode.postMessage({ command: "checkServerStatus" });
};

// Effect hook to check server status on component mount and periodically
useEffect(() => {
fetchServerStatus();
const interval = setInterval(fetchServerStatus, 5000); // Check every 5 seconds
return () => clearInterval(interval);
}, []);

const messageHandler = (message: any) => {
switch (message.type) {
case "serverStatus":
setServerRunning(message.isRunning);
break;

case "loadStoredAnalysis": {
const storedAnalysisResults = message.data;
setAnalysisResults(
storedAnalysisResults && storedAnalysisResults.length
? storedAnalysisResults
: null,
storedAnalysisResults && storedAnalysisResults.length ? storedAnalysisResults : null,
);
break;
}
Expand Down Expand Up @@ -102,26 +116,29 @@ const AnalysisPage: React.FC = () => {

return (
<>
<Button
variant={ButtonVariant.primary}
onClick={startAnalysis}
isLoading={isAnalyzing}
isDisabled={isAnalyzing}
className={spacing.mbSm}
>
{isAnalyzing ? "Analyzing..." : "Run Analysis"}
</Button>
{serverRunning && (
<div style={{ display: "flex", justifyContent: "center" }}>
{" "}
{/* Add this line */}
<Button
variant={ButtonVariant.primary}
onClick={startAnalysis}
isLoading={isAnalyzing}
isDisabled={!serverRunning || isAnalyzing}
className={spacing.mtXl}
>
{isAnalyzing ? "Analyzing..." : "Run Analysis"}
</Button>
</div>
)}

{errorMessage && (
<AlertGroup isToast>
<Alert
variant="danger"
title={errorMessage}
actionClose={
<AlertActionCloseButton
title={errorMessage}
onClose={() => setErrorMessage(null)}
/>
<AlertActionCloseButton title={errorMessage} onClose={() => setErrorMessage(null)} />
}
/>
</AlertGroup>
Expand Down Expand Up @@ -154,12 +171,26 @@ const AnalysisPage: React.FC = () => {
expandedViolations={expandedViolations}
setExpandedViolations={setExpandedViolations}
/>
) : !serverRunning ? (
<EmptyState>
<Title headingLevel="h2" size="lg">
Server Not Running
</Title>
<EmptyStateBody>
The server is not running. Please start the server to run an analysis.
</EmptyStateBody>
<Button
className={spacing.mtMd}
variant={ButtonVariant.primary}
onClick={() => sendVscodeMessage("startServer", {})}
>
Start Server
</Button>
</EmptyState>
) : (
<EmptyState>
<Title headingLevel="h2" size="lg">
{analysisResults?.length
? "No Violations Found"
: "No Analysis Results"}
{analysisResults?.length ? "No Violations Found" : "No Analysis Results"}
</Title>
<EmptyStateBody>
{analysisResults?.length
Expand Down
55 changes: 11 additions & 44 deletions webview-ui/src/components/ResolutionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import { sendVscodeMessage } from "../utils/vscodeMessaging";
const ResolutionPage: React.FC = () => {
const [resolution, setResolution] = useState<ResolutionMessage | null>(null);
const [isResolved, setIsResolved] = useState(false);
const [processedChanges, setProcessedChanges] = useState<Set<string>>(
new Set(),
);
const [processedChanges, setProcessedChanges] = useState<Set<string>>(new Set());

const messageHandler = (message: any) => {
if (message.type === "loadResolution") {
Expand All @@ -41,11 +39,6 @@ const ResolutionPage: React.FC = () => {
setIsResolved(false);
setProcessedChanges(new Set());
}

sendVscodeMessage("setSharedState", {
key: "resolutionPanelData",
value: message,
});
}
};

Expand All @@ -55,10 +48,7 @@ const ResolutionPage: React.FC = () => {
const handleSolutionResult = (resolutionMessage: ResolutionMessage) => {
if (resolutionMessage?.isRelevantSolution) {
// Relevant solution found, process or display it
console.log(
"Relevant solution found for this incident:",
resolutionMessage,
);
console.log("Relevant solution found for this incident:", resolutionMessage);
setResolution(resolutionMessage);
setIsResolved(false);
setProcessedChanges(new Set());
Expand All @@ -69,10 +59,6 @@ const ResolutionPage: React.FC = () => {
setIsResolved(false);
setProcessedChanges(new Set());

sendVscodeMessage("setSharedState", {
key: "resolutionPanelData",
value: null,
});
sendVscodeMessage("solutionResolved", {});
}
};
Expand Down Expand Up @@ -105,9 +91,7 @@ const ResolutionPage: React.FC = () => {
const handleRejectClick = (change: Change) => {
sendVscodeMessage("revertFile", {
change, // Send the Change data for the file to be opened
incident: resolution
? resolution.incident
: { uri: "", lineNumber: 0, message: "" },
incident: resolution ? resolution.incident : { uri: "", lineNumber: 0, message: "" },
});

const newProcessedChanges = new Set(processedChanges);
Expand All @@ -126,27 +110,18 @@ const ResolutionPage: React.FC = () => {
if (!resolution?.solution.changes) {
return [];
}
return resolution.solution.changes.filter(
(change) => !processedChanges.has(change.modified),
);
return resolution.solution.changes.filter((change) => !processedChanges.has(change.modified));
};

// Display "Changes Applied" when the solution is accepted
if (isResolved) {
return (
<Page>
<PageSection
className="pf-v6-u-px-xl pf-v6-u-py-md"
title="Changes Applied"
>
<EmptyState
variant="lg"
icon={CheckCircleIcon}
titleText="Changes Applied"
>
<PageSection className="pf-v6-u-px-xl pf-v6-u-py-md" title="Changes Applied">
<EmptyState variant="lg" icon={CheckCircleIcon} titleText="Changes Applied">
<EmptyStateBody>
The changes have been processed. You can close this panel or wait
for the next incident.
The changes have been processed. You can close this panel or wait for the next
incident.
</EmptyStateBody>
</EmptyState>
</PageSection>
Expand All @@ -159,14 +134,8 @@ const ResolutionPage: React.FC = () => {
return (
<Page>
<PageSection className="pf-v5-u-px-xl pf-v5-u-py-md">
<EmptyState
variant="lg"
icon={WarningTriangleIcon}
titleText="No Active Solutions"
>
<EmptyStateBody>
There are no solutions to review at this time.
</EmptyStateBody>
<EmptyState variant="lg" icon={WarningTriangleIcon} titleText="No Active Solutions">
<EmptyStateBody>There are no solutions to review at this time.</EmptyStateBody>
</EmptyState>
</PageSection>
</Page>
Expand Down Expand Up @@ -196,9 +165,7 @@ const ResolutionPage: React.FC = () => {
<Card isFullHeight className="incident-list-card">
<CardTitle>
{resolution?.violation.description || "No Violation Data"}
<Badge className={spacing.mSm}>
{resolution?.violation.category}
</Badge>
<Badge className={spacing.mSm}>{resolution?.violation.category}</Badge>
</CardTitle>
<CardBody>
<IncidentList
Expand Down

0 comments on commit 80ad968

Please sign in to comment.