Merge pull request #2959 from github/koesie10/modeled-methods-panel-add-button
Only disable add button when there are no models yet
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as React from "react";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { useCallback, useState } from "react";
|
||||
import { Method } from "../../model-editor/method";
|
||||
import { ModeledMethod } from "../../model-editor/modeled-method";
|
||||
import { styled } from "styled-components";
|
||||
@@ -100,13 +100,6 @@ export const MultipleModeledMethodsPanel = ({
|
||||
setSelectedIndex(newSelectedIndex);
|
||||
}, [onChange, modeledMethods, selectedIndex]);
|
||||
|
||||
const anyUnmodeled = useMemo(
|
||||
() =>
|
||||
modeledMethods.length === 0 ||
|
||||
modeledMethods.some((m) => m.type === "none"),
|
||||
[modeledMethods],
|
||||
);
|
||||
|
||||
const handleChange = useCallback(
|
||||
(modeledMethod: ModeledMethod) => {
|
||||
if (modeledMethods.length > 0) {
|
||||
@@ -186,7 +179,10 @@ export const MultipleModeledMethodsPanel = ({
|
||||
appearance="icon"
|
||||
aria-label="Add modeling"
|
||||
onClick={handleAddClick}
|
||||
disabled={anyUnmodeled}
|
||||
disabled={
|
||||
modeledMethods.length === 0 ||
|
||||
(modeledMethods.length === 1 && modeledMethods[0].type === "none")
|
||||
}
|
||||
>
|
||||
<Codicon name="add" />
|
||||
</VSCodeButton>
|
||||
|
||||
@@ -536,7 +536,7 @@ describe(MultipleModeledMethodsPanel.name, () => {
|
||||
}),
|
||||
];
|
||||
|
||||
it("cannot add modeling", () => {
|
||||
it("can add modeling", () => {
|
||||
render({
|
||||
method,
|
||||
modeledMethods,
|
||||
@@ -545,7 +545,7 @@ describe(MultipleModeledMethodsPanel.name, () => {
|
||||
|
||||
expect(
|
||||
screen.getByLabelText("Add modeling").getElementsByTagName("input")[0],
|
||||
).toBeDisabled();
|
||||
).toBeEnabled();
|
||||
});
|
||||
|
||||
it("can delete first modeling", async () => {
|
||||
|
||||
Reference in New Issue
Block a user