codeant-ai-for-open-source[bot] commented on code in PR #41052:
URL: https://github.com/apache/superset/pull/41052#discussion_r3413939232
##########
superset-frontend/src/SqlLab/components/SqlEditorTabHeader/index.tsx:
##########
@@ -107,14 +117,23 @@ const SqlEditorTabHeader: FC<Props> = ({ queryEditor })
=> {
[dispatch],
);
- function renameTab() {
- // TODO: Replace native prompt with a proper modal dialog
- // eslint-disable-next-line no-alert
- const newTitle = prompt(t('Enter a new title for the tab'));
- if (newTitle) {
- actions.queryEditorSetTitle(qe, newTitle, qe.id);
+ function openRenameModal() {
+ setNewTitle(qe.name);
+ setIsRenameModalOpen(true);
+ }
+
+ function handleRenameConfirm() {
+ const trimmed = newTitle.trim();
+ if (trimmed) {
+ actions.queryEditorSetTitle(qe, trimmed, qe.id);
}
+ setIsRenameModalOpen(false);
+ }
Review Comment:
**Suggestion:** The confirm handler always closes the modal even when the
title is invalid (empty/whitespace). Because `onPressEnter` calls this handler
directly, pressing Enter with whitespace-only input closes the dialog without
saving, bypassing the intended `saveDisabled` guard and causing an
inconsistent/buggy rename flow. Keep the modal open when trimmed input is empty
(return early) so keyboard and button behavior are consistent. [incorrect
condition logic]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ SQL Lab tab rename modal closes on invalid input.
- ⚠️ Keyboard Enter bypasses saveDisabled validation for whitespace names.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Navigate to SQL Lab in the UI so `TabbedSqlEditors` renders; in
`superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.tsx:16-32`
each tab label
is `<SqlEditorTabHeader queryEditor={qe} />`, which mounts
`SqlEditorTabHeader` for the
active query editor.
2. In any SQL Lab tab, click the tab menu dots rendered by
`MenuDotsDropdown` in
`SqlEditorTabHeader` (`index.tsx:155-236`) and choose the "Rename tab"
option (`items`
entry with `key: '2'` and `onClick: openRenameModal` at
`index.tsx:180-195`), which calls
`openRenameModal` (`index.tsx:120-123`) and opens the `StandardModal` with
the
`rename-tab-input` `Input`.
3. In the rename modal, clear the pre-filled title and type only whitespace
(e.g. a few
spaces) into the input; note that the Save button is disabled because
`saveDisabled={!newTitle.trim()}` on `StandardModal` at `index.tsx:244-250`,
while the
`Input` still has `onPressEnter={handleRenameConfirm}` at
`index.tsx:253-257`.
4. Press Enter while the input contains only whitespace:
`handleRenameConfirm`
(`index.tsx:125-131`) runs, `trimmed` is an empty string so
`queryEditorSetTitle` is not
dispatched, but `setIsRenameModalOpen(false)` still executes, setting
`show={isRenameModalOpen}` on `StandardModal` to `false` and closing the
modal, causing
the dialog to dismiss despite invalid input while the disabled Save button
indicated the
rename should not be submitted.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c6acf3ad0b5249f9a008df78d10051ee&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c6acf3ad0b5249f9a008df78d10051ee&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/SqlLab/components/SqlEditorTabHeader/index.tsx
**Line:** 125:131
**Comment:**
*Incorrect Condition Logic: The confirm handler always closes the modal
even when the title is invalid (empty/whitespace). Because `onPressEnter` calls
this handler directly, pressing Enter with whitespace-only input closes the
dialog without saving, bypassing the intended `saveDisabled` guard and causing
an inconsistent/buggy rename flow. Keep the modal open when trimmed input is
empty (return early) so keyboard and button behavior are consistent.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41052&comment_hash=f757bef6d08cac943e3c55bd9350466c2c93a4ed4b10a40fd56b1916ecd77eb1&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41052&comment_hash=f757bef6d08cac943e3c55bd9350466c2c93a4ed4b10a40fd56b1916ecd77eb1&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]