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

✨ Resolution page v2 #204

Merged
merged 8 commits into from
Jan 21, 2025
Merged
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
1,317 changes: 1,238 additions & 79 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions shared/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ export interface ExtensionData {
isFetchingSolution: boolean;
isStartingServer: boolean;
serverState: ServerState;
solutionState: SolutionState;
solutionData?: Solution;
solutionScope?: Scope;
solutionMessages: string[];
}

export type ServerState =
Expand All @@ -110,3 +112,11 @@ export type ServerState =
| "running"
| "stopping"
| "stopped";

export type SolutionState =
| "none"
| "started"
| "sent"
| "received"
| "failedOnStart"
| "failedOnSending";
13 changes: 12 additions & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
"category": "Konveyor",
"icon": "$(book)"
},
{
"command": "konveyor.showResolutionPanel",
"title": "Open Konveyor Resolution View",
"category": "Konveyor",
"icon": "$(beaker)"
},
{
"command": "konveyor.expandAllIssues",
"title": "Expand All",
Expand Down Expand Up @@ -276,10 +282,15 @@
"when": "view == konveyor.issueView"
},
{
"command": "konveyor.expandAllIssues",
"command": "konveyor.showResolutionPanel",
"group": "navigation@2",
"when": "view == konveyor.issueView"
},
{
"command": "konveyor.expandAllIssues",
"group": "navigation@3",
"when": "view == konveyor.issueView"
},
{
"command": "konveyor.applyAll",
"group": "navigation@1",
Expand Down
3 changes: 2 additions & 1 deletion vscode/src/KonveyorGUIWebviewViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
WebviewViewResolveContext,
ViewColumn,
window,
ColorThemeKind,
} from "vscode";
import { getNonce } from "./utilities/getNonce";
import { ExtensionData, WebviewType } from "@editor-extensions/shared";
Expand Down Expand Up @@ -121,7 +122,7 @@ export class KonveyorGUIWebviewViewProvider implements WebviewViewProvider {
const nonce = getNonce();

return `<!DOCTYPE html>
<html lang="en" class="pf-v6-theme-dark">
<html lang="en" class="${window.activeColorTheme.kind === ColorThemeKind.Dark ? "pf-v6-theme-dark" : ""}">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand Down
37 changes: 27 additions & 10 deletions vscode/src/client/analyzerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import * as fs from "fs-extra";
import * as vscode from "vscode";
import * as rpc from "vscode-jsonrpc/node";
import {
ExtensionData,
Incident,
RuleSet,
Scope,
ServerState,
SolutionResponse,
SolutionState,
Violation,
ExtensionData,
ServerState,
} from "@editor-extensions/shared";
import { paths, fsPaths } from "../paths";
import { Extension } from "../helpers/Extension";
Expand Down Expand Up @@ -43,7 +45,7 @@ export class AnalyzerClient {
private assetPaths: AssetPaths;
private fireStateChange: (state: ServerState) => void;
private fireAnalysisStateChange: (flag: boolean) => void;
private fireSolutionStateChange: (flag: boolean) => void;
private fireSolutionStateChange: (state: SolutionState, message?: string, scope?: Scope) => void;

private modelProvider: ModelProvider | null = null;

Expand All @@ -61,9 +63,17 @@ export class AnalyzerClient {
mutateExtensionData((draft) => {
draft.isAnalyzing = flag;
});
this.fireSolutionStateChange = (flag: boolean) =>
this.fireSolutionStateChange = (state: SolutionState, message?: string, scope?: Scope) =>
mutateExtensionData((draft) => {
draft.isFetchingSolution = flag;
draft.isFetchingSolution = state === "sent";
draft.solutionState = state;
if (state === "started") {
draft.solutionMessages = [];
draft.solutionScope = scope;
}
if (message) {
draft.solutionMessages.push(message);
}
});

this.outputChannel = vscode.window.createOutputChannel("Konveyor-Analyzer");
Expand Down Expand Up @@ -482,13 +492,14 @@ export class AnalyzerClient {
): Promise<void> {
// TODO: Ensure serverState is running

this.fireSolutionStateChange("started", "Checking server state...", { incidents, violation });

if (!this.rpcConnection) {
vscode.window.showErrorMessage("RPC connection is not established.");
this.fireSolutionStateChange("failedOnStart", "RPC connection is not established.");
return;
}

this.fireSolutionStateChange(true);

const enhancedIncidents = incidents.map((incident) => ({
...incident,
ruleset_name: violation?.category ?? "default_ruleset",
Expand All @@ -512,21 +523,27 @@ export class AnalyzerClient {
`getCodeplanAgentSolution request: ${JSON.stringify(request, null, 2)}`,
);

this.fireSolutionStateChange("sent", "Waiting for the resolution...");
const response: SolutionResponse = await this.rpcConnection!.sendRequest(
"getCodeplanAgentSolution",
request,
);

this.fireSolutionStateChange("received", "Received response...");
vscode.commands.executeCommand("konveyor.loadSolution", response, {
incidents,
violation,
});
} catch (err: any) {
this.outputChannel.appendLine(`Error during getSolution: ${err.message}`);
vscode.window.showErrorMessage("Get solution failed. See the output channel for details.");
vscode.window.showErrorMessage(
"Failed to provide resolutions. See the output channel for details.",
);
this.fireSolutionStateChange(
"failedOnSending",
`Failed to provide resolutions. Encountered error: ${err.message}. See the output channel for details.`,
);
}

this.fireSolutionStateChange(false);
}

public canAnalyze(): boolean {
Expand Down
2 changes: 2 additions & 0 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class VsCodeExtension {
serverState: "initial",
solutionScope: undefined,
workspaceRoot: paths.workspaceRepo.fsPath,
solutionMessages: [],
solutionState: "none",
},
() => {},
);
Expand Down
3 changes: 2 additions & 1 deletion webview-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"@patternfly/react-icons": "^5.4.0",
"@patternfly/react-table": "^5.4.1",
"path-browserify": "^1.0.1",
"vscode-webview": "^1.0.1-beta.1"
"vscode-webview": "^1.0.1-beta.1",
"react-markdown": "^9.0.3"
},
"devDependencies": {
"@types/vscode-webview": "^1.57.5",
Expand Down
7 changes: 0 additions & 7 deletions webview-ui/src/App.css

This file was deleted.

113 changes: 52 additions & 61 deletions webview-ui/src/components/AnalysisPage/AnalysisPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
CardBody,
CardHeader,
CardTitle,
Content,
EmptyState,
EmptyStateBody,
Title,
Expand All @@ -22,21 +21,23 @@ import {
StackItem,
Flex,
FlexItem,
PageSidebar,
PageSidebarBody,
Masthead,
MastheadMain,
MastheadToggle,
MastheadContent,
Toolbar,
ToolbarContent,
ToolbarGroup,
ToolbarItem,
} from "@patternfly/react-core";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";

import ProgressIndicator from "../ProgressIndicator";
import ViolationIncidentsList from "../ViolationIncidentsList";
import { Incident } from "@editor-extensions/shared";
import { Incident, Violation } from "@editor-extensions/shared";
import { useExtensionState } from "../../hooks/useExtensionState";
import {
cancelSolution,
getSolution,
openFile,
startServer,
runAnalysis,
stopServer,
} from "../../hooks/actions";
import { getSolution, openFile, startServer, runAnalysis, stopServer } from "../../hooks/actions";
import { ServerStatusToggle } from "../ServerStatusToggle/ServerStatusToggle";
import { ViolationsCount } from "../ViolationsCount/ViolationsCount";

Expand All @@ -62,8 +63,6 @@ const AnalysisPage: React.FC = () => {

const runAnalysisRequest = () => dispatch(runAnalysis());

const cancelSolutionRequest = () => dispatch(cancelSolution());

const handleServerToggle = () => {
dispatch(serverRunning ? stopServer() : startServer());
};
Expand All @@ -73,7 +72,7 @@ const AnalysisPage: React.FC = () => {
return [];
}
return analysisResults.flatMap((ruleSet) =>
Object.entries(ruleSet.violations || {}).map(([id, violation]) => ({
Object.entries<Violation>(ruleSet.violations || {}).map(([id, violation]) => ({
id,
...violation,
})),
Expand All @@ -84,13 +83,45 @@ const AnalysisPage: React.FC = () => {
const hasAnalysisResults = analysisResults !== undefined;

return (
<Page>
<ServerStatusToggle
isRunning={serverRunning}
isStarting={isStartingServer}
onToggle={handleServerToggle}
/>

<Page
sidebar={
<PageSidebar isSidebarOpen={false}>
<PageSidebarBody />
</PageSidebar>
}
masthead={
<Masthead>
<MastheadMain>
<MastheadToggle>
<Button
variant={ButtonVariant.primary}
onClick={runAnalysisRequest}
isLoading={isAnalyzing}
isDisabled={isAnalyzing || isStartingServer || !serverRunning}
>
{isAnalyzing ? "Analyzing..." : "Run Analysis"}
</Button>
</MastheadToggle>
</MastheadMain>

<MastheadContent>
<Toolbar>
<ToolbarContent>
<ToolbarGroup variant="action-group-plain" align={{ default: "alignEnd" }}>
<ToolbarItem>
<ServerStatusToggle
isRunning={serverRunning}
isStarting={isStartingServer}
onToggle={handleServerToggle}
/>
</ToolbarItem>
</ToolbarGroup>
</ToolbarContent>
</Toolbar>
</MastheadContent>
</Masthead>
}
>
{errorMessage && (
<PageSection padding={{ default: "noPadding" }}>
<AlertGroup isToast>
Expand All @@ -110,39 +141,6 @@ const AnalysisPage: React.FC = () => {

<PageSection>
<Stack hasGutter>
<StackItem>
<Card>
<CardHeader>
<Flex>
<FlexItem>
<CardTitle>Analysis Actions</CardTitle>
</FlexItem>
</Flex>
</CardHeader>
<CardBody>
<Stack hasGutter>
<StackItem>
<Content>
{hasAnalysisResults
? "Previous analysis results are available. You can run a new analysis at any time."
: "No previous analysis results found. Run an analysis to get started."}
</Content>
</StackItem>
<StackItem>
<Button
variant={ButtonVariant.primary}
onClick={runAnalysisRequest}
isLoading={isAnalyzing}
isDisabled={isAnalyzing || isStartingServer || !serverRunning}
>
{isAnalyzing ? "Analyzing..." : "Run Analysis"}
</Button>
</StackItem>
</Stack>
</CardBody>
</Card>
</StackItem>

<StackItem>
<Card>
<CardHeader>
Expand Down Expand Up @@ -207,13 +205,6 @@ const AnalysisPage: React.FC = () => {
<Title headingLevel="h2" size="lg">
Waiting for solution confirmation...
</Title>
<Button
variant={ButtonVariant.link}
onClick={cancelSolutionRequest}
className={spacing.mtMd}
>
Cancel
</Button>
</div>
</Backdrop>
)}
Expand Down
Loading
Loading