Skip to content

Commit 2453c64

Browse files
committed
Only disable add button when there are no models yet
This will change the add button in the method modeling panel to only be disabled if there is exactly 1 unmodeled method and there are no unmodeled methods. This should be more intuitive for users since they are able to see in 1 screen that there is an unmodeled method.
1 parent 1993db5 commit 2453c64

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import { useCallback, useMemo, useState } from "react";
2+
import { useCallback, useState } from "react";
33
import { Method } from "../../model-editor/method";
44
import { ModeledMethod } from "../../model-editor/modeled-method";
55
import { styled } from "styled-components";
@@ -88,13 +88,6 @@ export const MultipleModeledMethodsPanel = ({
8888
setSelectedIndex(newSelectedIndex);
8989
}, [onChange, modeledMethods, selectedIndex]);
9090

91-
const anyUnmodeled = useMemo(
92-
() =>
93-
modeledMethods.length === 0 ||
94-
modeledMethods.some((m) => m.type === "none"),
95-
[modeledMethods],
96-
);
97-
9891
const handleChange = useCallback(
9992
(modeledMethod: ModeledMethod) => {
10093
if (modeledMethods.length > 0) {
@@ -163,7 +156,10 @@ export const MultipleModeledMethodsPanel = ({
163156
appearance="icon"
164157
aria-label="Add modeling"
165158
onClick={handleAddClick}
166-
disabled={anyUnmodeled}
159+
disabled={
160+
modeledMethods.length === 0 ||
161+
(modeledMethods.length === 1 && modeledMethods[0].type === "none")
162+
}
167163
>
168164
<Codicon name="add" />
169165
</VSCodeButton>

extensions/ql-vscode/src/view/method-modeling/__tests__/MultipleModeledMethodsPanel.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ describe(MultipleModeledMethodsPanel.name, () => {
485485
}),
486486
];
487487

488-
it("cannot add modeling", () => {
488+
it("can add modeling", () => {
489489
render({
490490
method,
491491
modeledMethods,
@@ -494,7 +494,7 @@ describe(MultipleModeledMethodsPanel.name, () => {
494494

495495
expect(
496496
screen.getByLabelText("Add modeling").getElementsByTagName("input")[0],
497-
).toBeDisabled();
497+
).toBeEnabled();
498498
});
499499

500500
it("can delete first modeling", async () => {

0 commit comments

Comments
 (0)