Skip to content

Commit df78259

Browse files
authored
Extract "ModelEvaluation" component (#3432)
1 parent 30fd122 commit df78259

3 files changed

Lines changed: 62 additions & 53 deletions

File tree

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

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { ToModelEditorMessage } from "../../common/interface-types";
33
import {
44
VSCodeButton,
55
VSCodeCheckbox,
6-
VSCodeProgressRing,
76
VSCodeTag,
87
} from "@vscode/webview-ui-toolkit/react";
98
import { styled } from "styled-components";
@@ -21,7 +20,7 @@ import { getLanguageDisplayName } from "../../common/query-language";
2120
import { INITIAL_HIDE_MODELED_METHODS_VALUE } from "../../model-editor/shared/hide-modeled-methods";
2221
import type { AccessPathSuggestionOptions } from "../../model-editor/suggestions";
2322
import type { ModelEvaluationRunState } from "../../model-editor/shared/model-evaluation-run-state";
24-
import { modelEvaluationRunIsRunning } from "../../model-editor/shared/model-evaluation-run-state";
23+
import { ModelEvaluation } from "./ModelEvaluation";
2524

2625
const LoadingContainer = styled.div`
2726
text-align: center;
@@ -77,57 +76,6 @@ const ButtonsContainer = styled.div`
7776
margin-top: 1rem;
7877
`;
7978

80-
const ProgressRing = styled(VSCodeProgressRing)`
81-
width: 16px;
82-
height: 16px;
83-
margin-right: 5px;
84-
`;
85-
86-
const ModelEvaluation = ({
87-
viewState,
88-
modeledMethods,
89-
modifiedSignatures,
90-
onStartEvaluation,
91-
onStopEvaluation,
92-
evaluationRun,
93-
}: {
94-
viewState: ModelEditorViewState;
95-
modeledMethods: Record<string, ModeledMethod[]>;
96-
modifiedSignatures: Set<string>;
97-
onStartEvaluation: () => void;
98-
onStopEvaluation: () => void;
99-
evaluationRun: ModelEvaluationRunState | undefined;
100-
}) => {
101-
if (!viewState.showEvaluationUi) {
102-
return null;
103-
}
104-
105-
if (!evaluationRun || !modelEvaluationRunIsRunning(evaluationRun)) {
106-
const customModelsExist = Object.values(modeledMethods).some(
107-
(methods) => methods.filter((m) => m.type !== "none").length > 0,
108-
);
109-
110-
const unsavedChanges = modifiedSignatures.size > 0;
111-
112-
return (
113-
<VSCodeButton
114-
onClick={onStartEvaluation}
115-
appearance="secondary"
116-
disabled={!customModelsExist || unsavedChanges}
117-
>
118-
Evaluate
119-
</VSCodeButton>
120-
);
121-
} else {
122-
return (
123-
<VSCodeButton onClick={onStopEvaluation} appearance="secondary">
124-
<ProgressRing />
125-
Stop evaluation
126-
</VSCodeButton>
127-
);
128-
}
129-
};
130-
13179
type Props = {
13280
initialViewState?: ModelEditorViewState;
13381
initialMethods?: Method[];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { VSCodeProgressRing } from "@vscode/webview-ui-toolkit/react";
2+
import { styled } from "styled-components";
3+
4+
export const ModelEditorProgressRing = styled(VSCodeProgressRing)`
5+
width: 16px;
6+
height: 16px;
7+
margin-right: 5px;
8+
`;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react";
2+
import type { ModeledMethod } from "../../model-editor/modeled-method";
3+
import type { ModelEditorViewState } from "../../model-editor/shared/view-state";
4+
import type { ModelEvaluationRunState } from "../../model-editor/shared/model-evaluation-run-state";
5+
import { modelEvaluationRunIsRunning } from "../../model-editor/shared/model-evaluation-run-state";
6+
import { ModelEditorProgressRing } from "./ModelEditorProgressRing";
7+
8+
type Props = {
9+
viewState: ModelEditorViewState;
10+
modeledMethods: Record<string, ModeledMethod[]>;
11+
modifiedSignatures: Set<string>;
12+
onStartEvaluation: () => void;
13+
onStopEvaluation: () => void;
14+
evaluationRun: ModelEvaluationRunState | undefined;
15+
};
16+
17+
export const ModelEvaluation = ({
18+
viewState,
19+
modeledMethods,
20+
modifiedSignatures,
21+
onStartEvaluation,
22+
onStopEvaluation,
23+
evaluationRun,
24+
}: Props) => {
25+
if (!viewState.showEvaluationUi) {
26+
return null;
27+
}
28+
29+
if (!evaluationRun || !modelEvaluationRunIsRunning(evaluationRun)) {
30+
const customModelsExist = Object.values(modeledMethods).some(
31+
(methods) => methods.filter((m) => m.type !== "none").length > 0,
32+
);
33+
34+
const unsavedChanges = modifiedSignatures.size > 0;
35+
36+
return (
37+
<VSCodeButton
38+
onClick={onStartEvaluation}
39+
appearance="secondary"
40+
disabled={!customModelsExist || unsavedChanges}
41+
>
42+
Evaluate
43+
</VSCodeButton>
44+
);
45+
} else {
46+
return (
47+
<VSCodeButton onClick={onStopEvaluation} appearance="secondary">
48+
<ModelEditorProgressRing />
49+
Stop evaluation
50+
</VSCodeButton>
51+
);
52+
}
53+
};

0 commit comments

Comments
 (0)