Skip to content

Commit 2410d2b

Browse files
authored
Merge pull request #2918 from github/koesie10/modeling-panel-view-state
Add view state to method modeling panel
2 parents 0e5551b + cf0057e commit 2410d2b

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import { ErrorLike } from "../common/errors";
1919
import { DataFlowPaths } from "../variant-analysis/shared/data-flow-paths";
2020
import { Method, Usage } from "../model-editor/method";
2121
import { ModeledMethod } from "../model-editor/modeled-method";
22-
import { ModelEditorViewState } from "../model-editor/shared/view-state";
22+
import {
23+
MethodModelingPanelViewState,
24+
ModelEditorViewState,
25+
} from "../model-editor/shared/view-state";
2326
import { Mode } from "../model-editor/shared/mode";
2427
import { QueryLanguage } from "./query-language";
2528

@@ -625,6 +628,11 @@ export type FromMethodModelingMessage =
625628
| RevealInEditorMessage
626629
| StartModelingMessage;
627630

631+
interface SetMethodModelingPanelViewStateMessage {
632+
t: "setMethodModelingPanelViewState";
633+
viewState: MethodModelingPanelViewState;
634+
}
635+
628636
interface SetMethodMessage {
629637
t: "setMethod";
630638
method: Method;
@@ -643,6 +651,7 @@ interface SetSelectedMethodMessage {
643651
}
644652

645653
export type ToMethodModelingMessage =
654+
| SetMethodModelingPanelViewStateMessage
646655
| SetMethodMessage
647656
| SetModeledMethodMessage
648657
| SetMethodModifiedMessage

extensions/ql-vscode/src/model-editor/method-modeling/method-modeling-view-provider.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { DbModelingState, ModelingStore } from "../modeling-store";
1212
import { AbstractWebviewViewProvider } from "../../common/vscode/abstract-webview-view-provider";
1313
import { assertNever } from "../../common/helpers-pure";
1414
import { ModelEditorViewTracker } from "../model-editor-view-tracker";
15+
import { showMultipleModels } from "../../config";
1516

1617
export class MethodModelingViewProvider extends AbstractWebviewViewProvider<
1718
ToMethodModelingMessage,
@@ -29,11 +30,20 @@ export class MethodModelingViewProvider extends AbstractWebviewViewProvider<
2930
super(app, "method-modeling");
3031
}
3132

32-
protected override onWebViewLoaded(): void {
33-
this.setInitialState();
33+
protected override async onWebViewLoaded(): Promise<void> {
34+
await Promise.all([this.setViewState(), this.setInitialState()]);
3435
this.registerToModelingStoreEvents();
3536
}
3637

38+
private async setViewState(): Promise<void> {
39+
await this.postMessage({
40+
t: "setMethodModelingPanelViewState",
41+
viewState: {
42+
showMultipleModels: showMultipleModels(),
43+
},
44+
});
45+
}
46+
3747
public async setMethod(method: Method): Promise<void> {
3848
this.method = method;
3949

@@ -45,11 +55,11 @@ export class MethodModelingViewProvider extends AbstractWebviewViewProvider<
4555
}
4656
}
4757

48-
private setInitialState(): void {
58+
private async setInitialState(): Promise<void> {
4959
if (this.modelingStore.hasStateForActiveDb()) {
5060
const selectedMethod = this.modelingStore.getSelectedMethodDetails();
5161
if (selectedMethod) {
52-
void this.postMessage({
62+
await this.postMessage({
5363
t: "setSelectedMethod",
5464
method: selectedMethod.method,
5565
modeledMethod: selectedMethod.modeledMethod,
@@ -64,7 +74,7 @@ export class MethodModelingViewProvider extends AbstractWebviewViewProvider<
6474
): Promise<void> {
6575
switch (msg.t) {
6676
case "viewLoaded":
67-
this.onWebViewLoaded();
77+
await this.onWebViewLoaded();
6878
break;
6979

7080
case "telemetry":

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

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ export interface ModelEditorViewState {
88
showMultipleModels: boolean;
99
mode: Mode;
1010
}
11+
12+
export interface MethodModelingPanelViewState {
13+
showMultipleModels: boolean;
14+
}

extensions/ql-vscode/src/view/method-modeling/MethodModeling.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export type MethodModelingProps = {
5656
modelingStatus: ModelingStatus;
5757
method: Method;
5858
modeledMethod: ModeledMethod | undefined;
59+
showMultipleModels?: boolean;
5960
onChange: (modeledMethod: ModeledMethod) => void;
6061
};
6162

extensions/ql-vscode/src/view/method-modeling/MethodModelingView.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ import { ModeledMethod } from "../../model-editor/modeled-method";
99
import { vscode } from "../vscode-api";
1010
import { NotInModelingMode } from "./NotInModelingMode";
1111
import { NoMethodSelected } from "./NoMethodSelected";
12+
import { MethodModelingPanelViewState } from "../../model-editor/shared/view-state";
1213

13-
export function MethodModelingView(): JSX.Element {
14+
type Props = {
15+
initialViewState?: MethodModelingPanelViewState;
16+
};
17+
18+
export function MethodModelingView({ initialViewState }: Props): JSX.Element {
19+
const [viewState, setViewState] = useState<
20+
MethodModelingPanelViewState | undefined
21+
>(initialViewState);
1422
const [inModelingMode, setInModelingMode] = useState<boolean>(false);
1523

1624
const [method, setMethod] = useState<Method | undefined>(undefined);
@@ -31,6 +39,9 @@ export function MethodModelingView(): JSX.Element {
3139
if (evt.origin === window.origin) {
3240
const msg: ToMethodModelingMessage = evt.data;
3341
switch (msg.t) {
42+
case "setMethodModelingPanelViewState":
43+
setViewState(msg.viewState);
44+
break;
3445
case "setInModelingMode":
3546
setInModelingMode(msg.inModelingMode);
3647
break;
@@ -84,6 +95,7 @@ export function MethodModelingView(): JSX.Element {
8495
modelingStatus={modelingStatus}
8596
method={method}
8697
modeledMethod={modeledMethod}
98+
showMultipleModels={viewState?.showMultipleModels}
8799
onChange={onChange}
88100
/>
89101
);

0 commit comments

Comments
 (0)