Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nu-1889] provide an unique validation message to the scenario labels #7182

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions designer/client/cypress/e2e/labels.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe("Scenario labels", () => {

cy.get("[data-testid=scenario-label-0]").should("be.visible").contains("tagX");

cy.get("@labelInput").should("be.visible").click().type("tagX");

cy.wait("@labelvalidation");

cy.get("@labelInput").should("be.visible").contains("This label already exists. Please enter a unique value.");

cy.get("@labelInput").find("input").clear();

cy.get("@labelInput").should("be.visible").click().type("tag2");

cy.wait("@labelvalidation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ interface AddLabelProps {
onClick: () => void;
}

const labelUniqueValidation = (label: string) => ({
label,
messages: [
i18next.t("panels.scenarioDetails.labels.validation.uniqueValue", "This label already exists. Please enter a unique value."),
],
});

const AddLabel = ({ onClick }: AddLabelProps) => {
return (
<Typography
Expand Down Expand Up @@ -125,9 +132,12 @@ export const ScenarioLabels = ({ readOnly }: Props) => {
setIsEdited(true);
};

const isInputInSelectedOptions = (inputValue: string): boolean => {
return scenarioLabelOptions.some((option) => inputValue === toLabelValue(option));
};
const isInputInSelectedOptions = useCallback(
(inputValue: string): boolean => {
return scenarioLabelOptions.some((option) => inputValue === toLabelValue(option));
},
[scenarioLabelOptions],
);

const inputHelperText = useMemo(() => {
if (inputErrors.length !== 0) {
Expand All @@ -151,9 +161,13 @@ export const ScenarioLabels = ({ readOnly }: Props) => {
}
}

if (isInputInSelectedOptions(newInput)) {
setInputErrors((prevState) => [...prevState, labelUniqueValidation(newInput)]);
}

setInputTyping(false);
}, 500);
}, []);
}, [isInputInSelectedOptions]);

const validateSelectedOptions = useMemo(() => {
return debounce(async (labels: LabelOption[]) => {
Expand Down
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
* [#7099](https://github.com/TouK/nussknacker/pull/7099) Provide an option to embedded video to the markdown
* [#7102](https://github.com/TouK/nussknacker/pull/7102) Introduce a new UI to defining aggregations within nodes
* [#7147](https://github.com/TouK/nussknacker/pull/7147) Fix redundant "ParameterName(...)" wrapper string in exported PDFs in nodes details
* [#7182](https://github.com/TouK/nussknacker/pull/7182) Provide an unique validation message to the scenario labels
* [#7178](https://github.com/TouK/nussknacker/pull/7178) Remove autocompletion from markdown editors

## 1.17
Expand Down
Loading