From c402f36306dd001947b60749e768dc58949e1bec Mon Sep 17 00:00:00 2001 From: Renat Kalimulin <103274228+Nilumilak@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:53:56 +0300 Subject: [PATCH] BE: FE: Topics: Allow custom topic params upon creation (#271) Co-authored-by: Mgrdich Co-authored-by: VladSenyuta --- .../ui/screens/schemas/SchemaCreateForm.java | 2 + .../screens/topics/TopicCreateEditForm.java | 8 +- .../ui/smokesuite/brokers/BrokersTest.java | 4 +- .../ui/smokesuite/schemas/SchemasTest.java | 2 +- .../Form/CustomParams/CustomParamField.tsx | 23 +- .../shared/Form/CustomParams/CustomParams.tsx | 24 +- .../__test__/CustomParamField.spec.tsx | 46 ++-- .../__test__/CustomParams.spec.tsx | 211 ++++++++++-------- .../InputWithOptions.styled.ts | 151 +++++++++++++ .../InputWithOptions/InputWithOptions.tsx | 94 ++++++++ .../__tests__/InputWithOptions.spec.tsx | 84 +++++++ frontend/src/lib/yupExtended.ts | 34 ++- 12 files changed, 536 insertions(+), 147 deletions(-) create mode 100644 frontend/src/components/common/InputWithOptions/InputWithOptions.styled.ts create mode 100644 frontend/src/components/common/InputWithOptions/InputWithOptions.tsx create mode 100644 frontend/src/components/common/InputWithOptions/__tests__/InputWithOptions.spec.tsx diff --git a/e2e-tests/src/main/java/io/kafbat/ui/screens/schemas/SchemaCreateForm.java b/e2e-tests/src/main/java/io/kafbat/ui/screens/schemas/SchemaCreateForm.java index cb734ba86..309f8fc68 100644 --- a/e2e-tests/src/main/java/io/kafbat/ui/screens/schemas/SchemaCreateForm.java +++ b/e2e-tests/src/main/java/io/kafbat/ui/screens/schemas/SchemaCreateForm.java @@ -3,6 +3,7 @@ import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.$$x; import static com.codeborne.selenide.Selenide.$x; +import static com.codeborne.selenide.Selenide.sleep; import static org.openqa.selenium.By.id; import com.codeborne.selenide.Condition; @@ -96,6 +97,7 @@ public int getVersionsNumberFromList() { @Step public SchemaCreateForm selectVersionFromDropDown(int versionNumberDd) { $x(String.format(ddlElementLocator, versionNumberDd)).shouldBe(Condition.visible).click(); + sleep(1000); return this; } diff --git a/e2e-tests/src/main/java/io/kafbat/ui/screens/topics/TopicCreateEditForm.java b/e2e-tests/src/main/java/io/kafbat/ui/screens/topics/TopicCreateEditForm.java index 00a3f65dd..aedc3e1c5 100644 --- a/e2e-tests/src/main/java/io/kafbat/ui/screens/topics/TopicCreateEditForm.java +++ b/e2e-tests/src/main/java/io/kafbat/ui/screens/topics/TopicCreateEditForm.java @@ -29,11 +29,11 @@ public class TopicCreateEditForm extends BasePage { protected SelenideElement minInSyncReplicasField = $x("//input[@name='minInSyncReplicas']"); protected SelenideElement cleanUpPolicyDdl = $x("//ul[@id='topicFormCleanupPolicy']"); protected SelenideElement maxSizeOnDiscDdl = $x("//ul[@id='topicFormRetentionBytes']"); - protected SelenideElement customParameterDdl = $x("//ul[contains(@name,'customParams')]"); - protected SelenideElement deleteCustomParameterBtn = $x("//span[contains(@title,'Delete customParam')]"); - protected SelenideElement addCustomParameterTypeBtn = $x("//button[contains(text(),'Add Custom Parameter')]"); + protected SelenideElement customParameterDdl = $x("//input[contains(@name, 'customParams')][@role='listitem']"); + protected SelenideElement deleteCustomParameterBtn = $x("//span[contains(@title, 'Delete customParam')]"); + protected SelenideElement addCustomParameterTypeBtn = $x("//button[contains(text(), 'Add Custom Parameter')]"); protected SelenideElement customParameterValueField = $x("//input[@placeholder='Value']"); - protected SelenideElement validationCustomParameterValueMsg = $x("//p[contains(text(),'Value is required')]"); + protected SelenideElement validationCustomParameterValueMsg = $x("//p[contains(text(), 'Value is required')]"); protected String ddlElementLocator = "//li[@value='%s']"; protected String btnTimeToRetainLocator = "//button[@class][text()='%s']"; protected String customParamsElmCss = "ul[role=listbox][name^=customParams][name$=name]"; diff --git a/e2e-tests/src/test/java/io/kafbat/ui/smokesuite/brokers/BrokersTest.java b/e2e-tests/src/test/java/io/kafbat/ui/smokesuite/brokers/BrokersTest.java index 2e41623ea..64fb73cc4 100644 --- a/e2e-tests/src/test/java/io/kafbat/ui/smokesuite/brokers/BrokersTest.java +++ b/e2e-tests/src/test/java/io/kafbat/ui/smokesuite/brokers/BrokersTest.java @@ -160,7 +160,7 @@ public void brokersConfigEditCheck() { configItem .setValue(String.valueOf(newValue)) .clickCancelBtn(); - Assert.assertEquals(getIntegerFromString(configItem.getValue(), false), defaultValue, + Assert.assertEquals(getIntegerFromString(configItem.getValue(), true), defaultValue, "configItem.getValue()"); configItem .clickEditBtn() @@ -173,7 +173,7 @@ public void brokersConfigEditCheck() { softly.assertFalse(configItem.getSaveBtn().isDisplayed(), "getSaveBtn().isDisplayed()"); softly.assertFalse(configItem.getCancelBtn().isDisplayed(), "getCancelBtn().isDisplayed()"); softly.assertTrue(configItem.getEditBtn().isDisplayed(), "getEditBtn().isDisplayed()"); - softly.assertEquals(getIntegerFromString(configItem.getValue(), false), newValue, + softly.assertEquals(getIntegerFromString(configItem.getValue(), true), newValue, "configItem.getValue()"); softly.assertAll(); } diff --git a/e2e-tests/src/test/java/io/kafbat/ui/smokesuite/schemas/SchemasTest.java b/e2e-tests/src/test/java/io/kafbat/ui/smokesuite/schemas/SchemasTest.java index 3b140018e..a8089aab1 100644 --- a/e2e-tests/src/test/java/io/kafbat/ui/smokesuite/schemas/SchemasTest.java +++ b/e2e-tests/src/test/java/io/kafbat/ui/smokesuite/schemas/SchemasTest.java @@ -90,7 +90,7 @@ public void compareVersionsCheck() { .getVersionsNumberFromList(); Assert.assertEquals(versionsNumberFromDdl, latestVersion, "Versions number is not matched"); schemaCreateForm - .selectVersionFromDropDown(1); + .selectVersionFromDropDown(latestVersion); Assert.assertEquals(schemaCreateForm.getMarkedLinesNumber(), 42, "getMarkedLinesNumber()"); } diff --git a/frontend/src/components/Topics/shared/Form/CustomParams/CustomParamField.tsx b/frontend/src/components/Topics/shared/Form/CustomParams/CustomParamField.tsx index 75baca10e..f773129b4 100644 --- a/frontend/src/components/Topics/shared/Form/CustomParams/CustomParamField.tsx +++ b/frontend/src/components/Topics/shared/Form/CustomParams/CustomParamField.tsx @@ -4,12 +4,12 @@ import { TOPIC_CUSTOM_PARAMS } from 'lib/constants'; import { FieldArrayWithId, useFormContext, Controller } from 'react-hook-form'; import { InputLabel } from 'components/common/Input/InputLabel.styled'; import { FormError } from 'components/common/Input/Input.styled'; -import Select from 'components/common/Select/Select'; import Input from 'components/common/Input/Input'; import IconButtonWrapper from 'components/common/Icons/IconButtonWrapper'; import CloseCircleIcon from 'components/common/Icons/CloseCircleIcon'; import * as C from 'components/Topics/shared/Form/TopicForm.styled'; import { ConfigSource } from 'generated-sources'; +import InputWithOptions from 'components/common/InputWithOptions/InputWithOptions'; import { TopicConfigParams, TopicFormData } from 'lib/interfaces/topic'; import * as S from './CustomParams.styled'; @@ -37,6 +37,7 @@ const CustomParamField: React.FC = ({ formState: { errors }, setValue, watch, + trigger, control, } = useFormContext(); const nameValue = watch(`customParams.${index}.name`); @@ -76,17 +77,18 @@ const CustomParamField: React.FC = ({ Custom Parameter * ( - = ({ isSubmitting, config, }) => { - const { control } = useFormContext(); + const { + trigger, + control, + formState: { errors }, + } = useFormContext(); + const { fields, append, remove } = useFieldArray({ control, name: TOPIC_CUSTOM_PARAMS_PREFIX, @@ -36,12 +43,14 @@ const CustomParams: React.FC = ({ }); const [existingFields, setExistingFields] = React.useState([]); - const removeField = (index: number): void => { - setExistingFields( - existingFields.filter((field) => field !== controlledFields[index].name) - ); - remove(index); + const itemIndex = existingFields.indexOf(controlledFields[index].name); + if (itemIndex !== -1) { + existingFields.splice(itemIndex, 1); + setExistingFields(existingFields); + remove(index); + trigger('customParams'); + } }; return ( @@ -58,6 +67,9 @@ const CustomParams: React.FC = ({ setExistingFields={setExistingFields} /> ))} + + +