Skip to content

Commit 5427c16

Browse files
authored
Show model packs in Model Alerts view (#3484)
1 parent f06bc88 commit 5427c16

File tree

6 files changed

+91
-12
lines changed

6 files changed

+91
-12
lines changed

extensions/ql-vscode/src/common/interface-types.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,15 @@ interface SetModelAlertsViewStateMessage {
732732
viewState: ModelAlertsViewState;
733733
}
734734

735-
export type ToModelAlertsMessage = SetModelAlertsViewStateMessage;
735+
interface OpenModelPackMessage {
736+
t: "openModelPack";
737+
path: string;
738+
}
739+
740+
export type ToModelAlertsMessage =
741+
| SetModelAlertsViewStateMessage
742+
| SetVariantAnalysisMessage;
736743

737-
export type FromModelAlertsMessage = CommonFromViewMessages;
744+
export type FromModelAlertsMessage =
745+
| CommonFromViewMessages
746+
| OpenModelPackMessage;

extensions/ql-vscode/src/model-editor/model-alerts/model-alerts-view.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ViewColumn } from "vscode";
1+
import { Uri, ViewColumn } from "vscode";
22
import type { WebviewPanelConfig } from "../../common/vscode/abstract-webview";
33
import { AbstractWebview } from "../../common/vscode/abstract-webview";
44
import { assertNever } from "../../common/helpers-pure";
@@ -15,6 +15,7 @@ import type { ModelingEvents } from "../modeling-events";
1515
import type { ModelingStore } from "../modeling-store";
1616
import type { DatabaseItem } from "../../databases/local-databases";
1717
import type { ExtensionPack } from "../shared/extension-pack";
18+
import type { VariantAnalysis } from "../../variant-analysis/shared/variant-analysis";
1819

1920
export class ModelAlertsView extends AbstractWebview<
2021
ToModelAlertsMessage,
@@ -34,12 +35,17 @@ export class ModelAlertsView extends AbstractWebview<
3435
this.registerToModelingEvents();
3536
}
3637

37-
public async showView() {
38+
public async showView(variantAnalysis: VariantAnalysis) {
3839
const panel = await this.getPanel();
3940
panel.reveal(undefined, true);
4041

4142
await this.waitForPanelLoaded();
4243
await this.setViewState();
44+
45+
await this.postMessage({
46+
t: "setVariantAnalysis",
47+
variantAnalysis,
48+
});
4349
}
4450

4551
protected async getPanelConfig(): Promise<WebviewPanelConfig> {
@@ -73,6 +79,9 @@ export class ModelAlertsView extends AbstractWebview<
7379
)`Unhandled error in model alerts view: ${msg.error.message}`,
7480
);
7581
break;
82+
case "openModelPack":
83+
await this.app.commands.execute("revealInExplorer", Uri.file(msg.path));
84+
break;
7685
default:
7786
assertNever(msg);
7887
}

extensions/ql-vscode/src/model-editor/model-evaluator.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,26 @@ export class ModelEvaluator extends DisposableObject {
124124
this.dbItem,
125125
this.extensionPack,
126126
);
127-
await view.showView();
127+
128+
// There should be a variant analysis available at this point, as the
129+
// view can only opened when the variant analysis is complete. So we
130+
// send this to the view. This is temporary until we have logic to
131+
// listen to variant analysis updates and update the view accordingly.
132+
const evaluationRun = this.modelingStore.getModelEvaluationRun(
133+
this.dbItem,
134+
);
135+
if (!evaluationRun) {
136+
throw new Error("No evaluation run available");
137+
}
138+
139+
const variantAnalysis =
140+
await this.getVariantAnalysisForRun(evaluationRun);
141+
142+
if (!variantAnalysis) {
143+
throw new Error("No variant analysis available");
144+
}
145+
146+
await view.showView(variantAnalysis);
128147
}
129148
}
130149

extensions/ql-vscode/src/view/model-alerts/ModelAlerts.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
import { useEffect, useState } from "react";
1+
import { useCallback, useEffect, useState } from "react";
22
import { ModelAlertsHeader } from "./ModelAlertsHeader";
33
import type { ModelAlertsViewState } from "../../model-editor/shared/view-state";
44
import type { ToModelAlertsMessage } from "../../common/interface-types";
5+
import type { VariantAnalysis } from "../../variant-analysis/shared/variant-analysis";
6+
import { vscode } from "../vscode-api";
57

68
type Props = {
79
initialViewState?: ModelAlertsViewState;
810
};
911

1012
export function ModelAlerts({ initialViewState }: Props): React.JSX.Element {
13+
const onOpenModelPackClick = useCallback((path: string) => {
14+
vscode.postMessage({
15+
t: "openModelPack",
16+
path,
17+
});
18+
}, []);
19+
1120
const [viewState, setViewState] = useState<ModelAlertsViewState | undefined>(
1221
initialViewState,
1322
);
1423

24+
const [variantAnalysis, setVariantAnalysis] = useState<
25+
VariantAnalysis | undefined
26+
>(undefined);
27+
1528
useEffect(() => {
1629
const listener = (evt: MessageEvent) => {
1730
if (evt.origin === window.origin) {
@@ -21,6 +34,9 @@ export function ModelAlerts({ initialViewState }: Props): React.JSX.Element {
2134
setViewState(msg.viewState);
2235
break;
2336
}
37+
case "setVariantAnalysis": {
38+
setVariantAnalysis(msg.variantAnalysis);
39+
}
2440
}
2541
} else {
2642
// sanitize origin
@@ -35,9 +51,15 @@ export function ModelAlerts({ initialViewState }: Props): React.JSX.Element {
3551
};
3652
}, []);
3753

38-
if (viewState === undefined) {
54+
if (viewState === undefined || variantAnalysis === undefined) {
3955
return <></>;
4056
}
4157

42-
return <ModelAlertsHeader viewState={viewState}></ModelAlertsHeader>;
58+
return (
59+
<ModelAlertsHeader
60+
viewState={viewState}
61+
variantAnalysis={variantAnalysis}
62+
openModelPackClick={onOpenModelPackClick}
63+
></ModelAlertsHeader>
64+
);
4365
}
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
import type { ModelAlertsViewState } from "../../model-editor/shared/view-state";
2+
import type { VariantAnalysis } from "../../variant-analysis/shared/variant-analysis";
23
import { ViewTitle } from "../common";
4+
import { ModelPacks } from "./ModelPacks";
35

4-
type Props = { viewState: ModelAlertsViewState };
6+
type Props = {
7+
viewState: ModelAlertsViewState;
8+
variantAnalysis: VariantAnalysis;
9+
openModelPackClick: (path: string) => void;
10+
};
511

6-
export const ModelAlertsHeader = ({ viewState }: Props) => {
7-
return <ViewTitle>Model evaluation results for {viewState.title}</ViewTitle>;
12+
export const ModelAlertsHeader = ({
13+
viewState,
14+
variantAnalysis,
15+
openModelPackClick,
16+
}: Props) => {
17+
return (
18+
<>
19+
<ViewTitle>Model evaluation results for {viewState.title}</ViewTitle>
20+
<ModelPacks
21+
modelPacks={variantAnalysis.modelPacks || []}
22+
openModelPackClick={openModelPackClick}
23+
></ModelPacks>
24+
</>
25+
);
826
};

extensions/ql-vscode/src/view/vscode-api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {
22
FromCompareViewMessage,
33
FromMethodModelingMessage,
4+
FromModelAlertsMessage,
45
FromModelEditorMessage,
56
FromResultsViewMsg,
67
FromVariantAnalysisMessage,
@@ -17,7 +18,8 @@ export interface VsCodeApi {
1718
| FromCompareViewMessage
1819
| FromVariantAnalysisMessage
1920
| FromModelEditorMessage
20-
| FromMethodModelingMessage,
21+
| FromMethodModelingMessage
22+
| FromModelAlertsMessage,
2123
): void;
2224

2325
/**

0 commit comments

Comments
 (0)