Skip to content

Commit c84fa53

Browse files
authored
Fire an event when clicking the "model alerts indicator" button (#3516)
1 parent 317d3b3 commit c84fa53

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,11 @@ interface OpenModelAlertsViewMessage {
605605
t: "openModelAlertsView";
606606
}
607607

608+
interface RevealInModelAlertsViewMessage {
609+
t: "revealInModelAlertsView";
610+
modeledMethod: ModeledMethod;
611+
}
612+
608613
interface ModelDependencyMessage {
609614
t: "modelDependency";
610615
}
@@ -677,7 +682,8 @@ export type FromModelEditorMessage =
677682
| SetMultipleModeledMethodsMessage
678683
| StartModelEvaluationMessage
679684
| StopModelEvaluationMessage
680-
| OpenModelAlertsViewMessage;
685+
| OpenModelAlertsViewMessage
686+
| RevealInModelAlertsViewMessage;
681687

682688
interface RevealInEditorMessage {
683689
t: "revealInModelEditor";

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ export class ModelEditorView extends AbstractWebview<
384384
case "openModelAlertsView":
385385
await this.modelEvaluator.openModelAlertsView();
386386
break;
387+
case "revealInModelAlertsView":
388+
await this.modelEvaluator.revealInModelAlertsView(msg.modeledMethod);
389+
break;
387390
case "telemetry":
388391
telemetryListener?.sendUIInteraction(msg.action);
389392
break;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type { QlPackDetails } from "../variant-analysis/ql-pack-details";
2121
import type { App } from "../common/app";
2222
import { ModelAlertsView } from "./model-alerts/model-alerts-view";
2323
import type { ExtensionPack } from "./shared/extension-pack";
24+
import type { ModeledMethod } from "./modeled-method";
2425

2526
export class ModelEvaluator extends DisposableObject {
2627
// Cancellation token source to allow cancelling of the current run
@@ -158,6 +159,16 @@ export class ModelEvaluator extends DisposableObject {
158159
}
159160
}
160161

162+
public async revealInModelAlertsView(modeledMethod: ModeledMethod) {
163+
if (!this.modelingStore.isModelAlertsViewOpen(this.dbItem)) {
164+
await this.openModelAlertsView();
165+
}
166+
this.modelingEvents.fireRevealInModelAlertsViewEvent(
167+
this.dbItem.databaseUri.toString(),
168+
modeledMethod,
169+
);
170+
}
171+
161172
private registerToModelingEvents() {
162173
this.push(
163174
this.modelingEvents.onModelEvaluationRunChanged(async (event) => {

extensions/ql-vscode/src/model-editor/modeling-events.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ interface FocusModelAlertsViewEvent {
6969
dbUri: string;
7070
}
7171

72+
interface RevealInModelAlertsViewEvent {
73+
dbUri: string;
74+
modeledMethod: ModeledMethod;
75+
}
76+
7277
export class ModelingEvents extends DisposableObject {
7378
public readonly onActiveDbChanged: AppEvent<void>;
7479
public readonly onDbOpened: AppEvent<DatabaseItem>;
@@ -84,6 +89,7 @@ export class ModelingEvents extends DisposableObject {
8489
public readonly onRevealInModelEditor: AppEvent<RevealInModelEditorEvent>;
8590
public readonly onFocusModelEditor: AppEvent<FocusModelEditorEvent>;
8691
public readonly onFocusModelAlertsView: AppEvent<FocusModelAlertsViewEvent>;
92+
public readonly onRevealInModelAlertsView: AppEvent<RevealInModelAlertsViewEvent>;
8793

8894
private readonly onActiveDbChangedEventEmitter: AppEventEmitter<void>;
8995
private readonly onDbOpenedEventEmitter: AppEventEmitter<DatabaseItem>;
@@ -99,6 +105,7 @@ export class ModelingEvents extends DisposableObject {
99105
private readonly onRevealInModelEditorEventEmitter: AppEventEmitter<RevealInModelEditorEvent>;
100106
private readonly onFocusModelEditorEventEmitter: AppEventEmitter<FocusModelEditorEvent>;
101107
private readonly onFocusModelAlertsViewEventEmitter: AppEventEmitter<FocusModelAlertsViewEvent>;
108+
private readonly onRevealInModelAlertsViewEventEmitter: AppEventEmitter<RevealInModelAlertsViewEvent>;
102109

103110
constructor(app: App) {
104111
super();
@@ -176,6 +183,12 @@ export class ModelingEvents extends DisposableObject {
176183
app.createEventEmitter<FocusModelAlertsViewEvent>(),
177184
);
178185
this.onFocusModelAlertsView = this.onFocusModelAlertsViewEventEmitter.event;
186+
187+
this.onRevealInModelAlertsViewEventEmitter = this.push(
188+
app.createEventEmitter<RevealInModelAlertsViewEvent>(),
189+
);
190+
this.onRevealInModelAlertsView =
191+
this.onRevealInModelAlertsViewEventEmitter.event;
179192
}
180193

181194
public fireActiveDbChangedEvent() {
@@ -301,4 +314,11 @@ export class ModelingEvents extends DisposableObject {
301314
public fireFocusModelAlertsViewEvent(dbUri: string) {
302315
this.onFocusModelAlertsViewEventEmitter.fire({ dbUri });
303316
}
317+
318+
public fireRevealInModelAlertsViewEvent(
319+
dbUri: string,
320+
modeledMethod: ModeledMethod,
321+
) {
322+
this.onRevealInModelAlertsViewEventEmitter.fire({ dbUri, modeledMethod });
323+
}
304324
}

extensions/ql-vscode/src/view/model-editor/ModelAlertsIndicator.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ModeledMethod } from "../../model-editor/modeled-method";
33
import type { ModelEvaluationRunState } from "../../model-editor/shared/model-evaluation-run-state";
44
import type { ModelEditorViewState } from "../../model-editor/shared/view-state";
55
import { VSCodeBadge } from "@vscode/webview-ui-toolkit/react";
6+
import { vscode } from "../vscode-api";
67

78
const ModelAlertsButton = styled(VSCodeBadge)`
89
cursor: pointer;
@@ -27,6 +28,13 @@ export const ModelAlertsIndicator = ({
2728
return null;
2829
}
2930

31+
const revealInModelAlertsView = () => {
32+
vscode.postMessage({
33+
t: "revealInModelAlertsView",
34+
modeledMethod,
35+
});
36+
};
37+
3038
// TODO: Once we have alert provenance, we can show actual alert counts here.
3139
// For now, we show a random number.
3240
const number = Math.floor(Math.random() * 10);
@@ -37,6 +45,7 @@ export const ModelAlertsIndicator = ({
3745
aria-label="Model alerts"
3846
onClick={(event: React.MouseEvent) => {
3947
event.stopPropagation();
48+
revealInModelAlertsView();
4049
}}
4150
>
4251
{number}

0 commit comments

Comments
 (0)