Skip to content

Commit

Permalink
fix: Leaving editable tab in error state
Browse files Browse the repository at this point in the history
  • Loading branch information
hetunandu committed Dec 5, 2024
1 parent 1f07be3 commit 954e920
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe("EditableName", () => {

await userEvent.click(document.body);

expect(getByRole("tooltip").textContent).toEqual(validationError);
expect(getByRole("tooltip").textContent).toEqual("");

expect(exitEditing).toHaveBeenCalled();
expect(onNameSave).not.toHaveBeenCalledWith(invalidTitle);
Expand Down Expand Up @@ -187,7 +187,7 @@ describe("EditableName", () => {
});

fireEvent.focusOut(inputElement);
expect(getByRole("tooltip").textContent).toEqual(validationError);
expect(getByRole("tooltip").textContent).toEqual("");
expect(exitEditing).toHaveBeenCalled();
expect(onNameSave).not.toHaveBeenCalledWith(invalidTitle);
});
Expand Down
7 changes: 7 additions & 0 deletions app/client/src/IDE/Components/EditableName/EditableName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ export const EditableName = ({
const nameError = validate(editableName);

if (editableName === name) {
// No change detected
exitWithoutSaving();
} else if (nameError === null) {
// Save the new name
exitEditing();
onNameSave(editableName);
} else {
// Exit edit mode and revert name
setEditableName(name);
setValidationError(null);
exitEditing();
}
}, [
editableName,
Expand Down

0 comments on commit 954e920

Please sign in to comment.