Show model packs in Model Alerts view (#3484)
This commit is contained in:
@@ -732,6 +732,15 @@ interface SetModelAlertsViewStateMessage {
|
||||
viewState: ModelAlertsViewState;
|
||||
}
|
||||
|
||||
export type ToModelAlertsMessage = SetModelAlertsViewStateMessage;
|
||||
interface OpenModelPackMessage {
|
||||
t: "openModelPack";
|
||||
path: string;
|
||||
}
|
||||
|
||||
export type FromModelAlertsMessage = CommonFromViewMessages;
|
||||
export type ToModelAlertsMessage =
|
||||
| SetModelAlertsViewStateMessage
|
||||
| SetVariantAnalysisMessage;
|
||||
|
||||
export type FromModelAlertsMessage =
|
||||
| CommonFromViewMessages
|
||||
| OpenModelPackMessage;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ViewColumn } from "vscode";
|
||||
import { Uri, ViewColumn } from "vscode";
|
||||
import type { WebviewPanelConfig } from "../../common/vscode/abstract-webview";
|
||||
import { AbstractWebview } from "../../common/vscode/abstract-webview";
|
||||
import { assertNever } from "../../common/helpers-pure";
|
||||
@@ -15,6 +15,7 @@ import type { ModelingEvents } from "../modeling-events";
|
||||
import type { ModelingStore } from "../modeling-store";
|
||||
import type { DatabaseItem } from "../../databases/local-databases";
|
||||
import type { ExtensionPack } from "../shared/extension-pack";
|
||||
import type { VariantAnalysis } from "../../variant-analysis/shared/variant-analysis";
|
||||
|
||||
export class ModelAlertsView extends AbstractWebview<
|
||||
ToModelAlertsMessage,
|
||||
@@ -34,12 +35,17 @@ export class ModelAlertsView extends AbstractWebview<
|
||||
this.registerToModelingEvents();
|
||||
}
|
||||
|
||||
public async showView() {
|
||||
public async showView(variantAnalysis: VariantAnalysis) {
|
||||
const panel = await this.getPanel();
|
||||
panel.reveal(undefined, true);
|
||||
|
||||
await this.waitForPanelLoaded();
|
||||
await this.setViewState();
|
||||
|
||||
await this.postMessage({
|
||||
t: "setVariantAnalysis",
|
||||
variantAnalysis,
|
||||
});
|
||||
}
|
||||
|
||||
protected async getPanelConfig(): Promise<WebviewPanelConfig> {
|
||||
@@ -73,6 +79,9 @@ export class ModelAlertsView extends AbstractWebview<
|
||||
)`Unhandled error in model alerts view: ${msg.error.message}`,
|
||||
);
|
||||
break;
|
||||
case "openModelPack":
|
||||
await this.app.commands.execute("revealInExplorer", Uri.file(msg.path));
|
||||
break;
|
||||
default:
|
||||
assertNever(msg);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,26 @@ export class ModelEvaluator extends DisposableObject {
|
||||
this.dbItem,
|
||||
this.extensionPack,
|
||||
);
|
||||
await view.showView();
|
||||
|
||||
// There should be a variant analysis available at this point, as the
|
||||
// view can only opened when the variant analysis is complete. So we
|
||||
// send this to the view. This is temporary until we have logic to
|
||||
// listen to variant analysis updates and update the view accordingly.
|
||||
const evaluationRun = this.modelingStore.getModelEvaluationRun(
|
||||
this.dbItem,
|
||||
);
|
||||
if (!evaluationRun) {
|
||||
throw new Error("No evaluation run available");
|
||||
}
|
||||
|
||||
const variantAnalysis =
|
||||
await this.getVariantAnalysisForRun(evaluationRun);
|
||||
|
||||
if (!variantAnalysis) {
|
||||
throw new Error("No variant analysis available");
|
||||
}
|
||||
|
||||
await view.showView(variantAnalysis);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { ModelAlertsHeader } from "./ModelAlertsHeader";
|
||||
import type { ModelAlertsViewState } from "../../model-editor/shared/view-state";
|
||||
import type { ToModelAlertsMessage } from "../../common/interface-types";
|
||||
import type { VariantAnalysis } from "../../variant-analysis/shared/variant-analysis";
|
||||
import { vscode } from "../vscode-api";
|
||||
|
||||
type Props = {
|
||||
initialViewState?: ModelAlertsViewState;
|
||||
};
|
||||
|
||||
export function ModelAlerts({ initialViewState }: Props): React.JSX.Element {
|
||||
const onOpenModelPackClick = useCallback((path: string) => {
|
||||
vscode.postMessage({
|
||||
t: "openModelPack",
|
||||
path,
|
||||
});
|
||||
}, []);
|
||||
|
||||
const [viewState, setViewState] = useState<ModelAlertsViewState | undefined>(
|
||||
initialViewState,
|
||||
);
|
||||
|
||||
const [variantAnalysis, setVariantAnalysis] = useState<
|
||||
VariantAnalysis | undefined
|
||||
>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
const listener = (evt: MessageEvent) => {
|
||||
if (evt.origin === window.origin) {
|
||||
@@ -21,6 +34,9 @@ export function ModelAlerts({ initialViewState }: Props): React.JSX.Element {
|
||||
setViewState(msg.viewState);
|
||||
break;
|
||||
}
|
||||
case "setVariantAnalysis": {
|
||||
setVariantAnalysis(msg.variantAnalysis);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// sanitize origin
|
||||
@@ -35,9 +51,15 @@ export function ModelAlerts({ initialViewState }: Props): React.JSX.Element {
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (viewState === undefined) {
|
||||
if (viewState === undefined || variantAnalysis === undefined) {
|
||||
return <></>;
|
||||
}
|
||||
|
||||
return <ModelAlertsHeader viewState={viewState}></ModelAlertsHeader>;
|
||||
return (
|
||||
<ModelAlertsHeader
|
||||
viewState={viewState}
|
||||
variantAnalysis={variantAnalysis}
|
||||
openModelPackClick={onOpenModelPackClick}
|
||||
></ModelAlertsHeader>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,26 @@
|
||||
import type { ModelAlertsViewState } from "../../model-editor/shared/view-state";
|
||||
import type { VariantAnalysis } from "../../variant-analysis/shared/variant-analysis";
|
||||
import { ViewTitle } from "../common";
|
||||
import { ModelPacks } from "./ModelPacks";
|
||||
|
||||
type Props = { viewState: ModelAlertsViewState };
|
||||
|
||||
export const ModelAlertsHeader = ({ viewState }: Props) => {
|
||||
return <ViewTitle>Model evaluation results for {viewState.title}</ViewTitle>;
|
||||
type Props = {
|
||||
viewState: ModelAlertsViewState;
|
||||
variantAnalysis: VariantAnalysis;
|
||||
openModelPackClick: (path: string) => void;
|
||||
};
|
||||
|
||||
export const ModelAlertsHeader = ({
|
||||
viewState,
|
||||
variantAnalysis,
|
||||
openModelPackClick,
|
||||
}: Props) => {
|
||||
return (
|
||||
<>
|
||||
<ViewTitle>Model evaluation results for {viewState.title}</ViewTitle>
|
||||
<ModelPacks
|
||||
modelPacks={variantAnalysis.modelPacks || []}
|
||||
openModelPackClick={openModelPackClick}
|
||||
></ModelPacks>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type {
|
||||
FromCompareViewMessage,
|
||||
FromMethodModelingMessage,
|
||||
FromModelAlertsMessage,
|
||||
FromModelEditorMessage,
|
||||
FromResultsViewMsg,
|
||||
FromVariantAnalysisMessage,
|
||||
@@ -17,7 +18,8 @@ export interface VsCodeApi {
|
||||
| FromCompareViewMessage
|
||||
| FromVariantAnalysisMessage
|
||||
| FromModelEditorMessage
|
||||
| FromMethodModelingMessage,
|
||||
| FromMethodModelingMessage
|
||||
| FromModelAlertsMessage,
|
||||
): void;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user