Skip to content

Commit 369258d

Browse files
Add add/remove buttons for models
1 parent 1993db5 commit 369258d

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

extensions/ql-vscode/src/stories/model-editor/MethodRow.stories.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { MethodRow as MethodRowComponent } from "../../view/model-editor/MethodR
66
import { CallClassification, Method } from "../../model-editor/method";
77
import { ModeledMethod } from "../../model-editor/modeled-method";
88
import { VSCodeDataGrid } from "@vscode/webview-ui-toolkit/react";
9-
import { GRID_TEMPLATE_COLUMNS } from "../../view/model-editor/ModeledMethodDataGrid";
9+
import {
10+
MULTIPLE_MODELS_GRID_TEMPLATE_COLUMNS,
11+
SINGLE_MODEL_GRID_TEMPLATE_COLUMNS,
12+
} from "../../view/model-editor/ModeledMethodDataGrid";
1013
import { ModelEditorViewState } from "../../model-editor/shared/view-state";
1114
import { createMockExtensionPack } from "../../../test/factories/model-editor/extension-pack";
1215
import { Mode } from "../../model-editor/shared/mode";
@@ -16,11 +19,16 @@ export default {
1619
component: MethodRowComponent,
1720
} as Meta<typeof MethodRowComponent>;
1821

19-
const Template: StoryFn<typeof MethodRowComponent> = (args) => (
20-
<VSCodeDataGrid gridTemplateColumns={GRID_TEMPLATE_COLUMNS}>
21-
<MethodRowComponent {...args} />
22-
</VSCodeDataGrid>
23-
);
22+
const Template: StoryFn<typeof MethodRowComponent> = (args) => {
23+
const gridTemplateColumns = args.viewState?.showMultipleModels
24+
? MULTIPLE_MODELS_GRID_TEMPLATE_COLUMNS
25+
: SINGLE_MODEL_GRID_TEMPLATE_COLUMNS;
26+
return (
27+
<VSCodeDataGrid gridTemplateColumns={gridTemplateColumns}>
28+
<MethodRowComponent {...args} />
29+
</VSCodeDataGrid>
30+
);
31+
};
2432

2533
const method: Method = {
2634
library: "sql2o-1.6.0.jar",

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
VSCodeButton,
23
VSCodeDataGridCell,
34
VSCodeDataGridRow,
45
VSCodeLink,
@@ -22,6 +23,7 @@ import { ModelTypeDropdown } from "./ModelTypeDropdown";
2223
import { ModelInputDropdown } from "./ModelInputDropdown";
2324
import { ModelOutputDropdown } from "./ModelOutputDropdown";
2425
import { ModelEditorViewState } from "../../model-editor/shared/view-state";
26+
import { Codicon } from "../common";
2527

2628
const MultiModelColumn = styled(VSCodeDataGridCell)`
2729
display: flex;
@@ -55,6 +57,11 @@ const ProgressRing = styled(VSCodeProgressRing)`
5557
margin-left: auto;
5658
`;
5759

60+
const CodiconRow = styled(VSCodeButton)`
61+
min-height: calc(var(--input-height) * 1px);
62+
align-items: center;
63+
`;
64+
5865
const DataGridRow = styled(VSCodeDataGridRow)<{ focused?: boolean }>`
5966
outline: ${(props) =>
6067
props.focused ? "1px solid var(--vscode-focusBorder)" : "none"};
@@ -159,6 +166,13 @@ const ModelableMethodRow = forwardRef<HTMLElement | undefined, MethodRowProps>(
159166
<VSCodeDataGridCell gridColumn={5}>
160167
<InProgressDropdown />
161168
</VSCodeDataGridCell>
169+
{viewState.showMultipleModels && (
170+
<VSCodeDataGridCell gridColumn={6}>
171+
<CodiconRow appearance="icon" disabled={true}>
172+
<Codicon name="add" label="Add new model" />
173+
</CodiconRow>
174+
</VSCodeDataGridCell>
175+
)}
162176
</>
163177
)}
164178
{!props.modelingInProgress && (
@@ -203,6 +217,19 @@ const ModelableMethodRow = forwardRef<HTMLElement | undefined, MethodRowProps>(
203217
/>
204218
))}
205219
</MultiModelColumn>
220+
{viewState.showMultipleModels && (
221+
<MultiModelColumn gridColumn={6}>
222+
{modeledMethods.map((_, index) => (
223+
<CodiconRow key={index} appearance="icon" disabled={false}>
224+
{index === modeledMethods.length - 1 ? (
225+
<Codicon name="add" label="Add new model" />
226+
) : (
227+
<Codicon name="trash" label="Remove model" />
228+
)}
229+
</CodiconRow>
230+
))}
231+
</MultiModelColumn>
232+
)}
206233
</>
207234
)}
208235
</DataGridRow>

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { InProgressMethods } from "../../model-editor/shared/in-progress-methods
1313
import { HiddenMethodsRow } from "./HiddenMethodsRow";
1414
import { ModelEditorViewState } from "../../model-editor/shared/view-state";
1515

16-
export const GRID_TEMPLATE_COLUMNS = "0.5fr 0.125fr 0.125fr 0.125fr 0.125fr";
16+
export const SINGLE_MODEL_GRID_TEMPLATE_COLUMNS =
17+
"0.5fr 0.125fr 0.125fr 0.125fr 0.125fr";
18+
export const MULTIPLE_MODELS_GRID_TEMPLATE_COLUMNS =
19+
"0.5fr 0.125fr 0.125fr 0.125fr 0.125fr max-content";
1720

1821
export type ModeledMethodDataGridProps = {
1922
packageName: string;
@@ -64,8 +67,12 @@ export const ModeledMethodDataGrid = ({
6467

6568
const someMethodsAreVisible = methodsWithModelability.length > 0;
6669

70+
const gridTemplateColumns = viewState.showMultipleModels
71+
? MULTIPLE_MODELS_GRID_TEMPLATE_COLUMNS
72+
: SINGLE_MODEL_GRID_TEMPLATE_COLUMNS;
73+
6774
return (
68-
<VSCodeDataGrid gridTemplateColumns={GRID_TEMPLATE_COLUMNS}>
75+
<VSCodeDataGrid gridTemplateColumns={gridTemplateColumns}>
6976
{someMethodsAreVisible && (
7077
<>
7178
<VSCodeDataGridRow rowType="header">
@@ -84,6 +91,9 @@ export const ModeledMethodDataGrid = ({
8491
<VSCodeDataGridCell cellType="columnheader" gridColumn={5}>
8592
Kind
8693
</VSCodeDataGridCell>
94+
{viewState.showMultipleModels && (
95+
<VSCodeDataGridCell cellType="columnheader" gridColumn={6} />
96+
)}
8797
</VSCodeDataGridRow>
8898
{methodsWithModelability.map(({ method, methodCanBeModeled }) => {
8999
const modeledMethods = modeledMethodsMap[method.signature] ?? [];

0 commit comments

Comments
 (0)