bito-code-review[bot] commented on PR #43334:
URL: https://github.com/apache/superset/pull/43334#issuecomment-5343433790
<!-- Bito Reply -->
The flagged issue is correct. The current implementation relies solely on
`latestQueryId` to determine if the dataset button should be enabled. If a user
runs a query successfully, then modifies the SQL in the editor, the
`latestQueryId` still points to the previous successful query, causing the
button to remain enabled even though the current SQL has not been executed.
To resolve this, you should invalidate the successful-run state when the SQL
changes. You can achieve this by tracking the SQL string associated with the
successful query and comparing it to the current editor SQL, or by resetting
the `latestQueryId` (or a derived `hasSuccessfulQuery` flag) whenever the
editor content changes.
Here is a concise implementation to invalidate the state when the SQL
changes:
```tsx
// In superset-frontend/src/SqlLab/components/SaveQuery/index.tsx
// 1. Track the SQL of the last successful run
const [lastSuccessfulSql, setLastSuccessfulSql] = useState<string |
null>(null);
// 2. Update the tracker when the query state becomes success
useEffect(() => {
if (latestQueryState === QueryState.Success) {
setLastSuccessfulSql(queryEditor.sql);
}
}, [latestQueryState, queryEditor.sql]);
// 3. Update the success check to verify the SQL matches
const hasSuccessfulQuery =
latestQueryState === QueryState.Success &&
lastSuccessfulSql === queryEditor.sql;
```
I have checked the PR comments, and there are no other comments in the
provided context. Would you like me to perform any further analysis or address
other parts of the PR?
**superset-frontend/src/SqlLab/components/SaveQuery/index.tsx**
```
const [lastSuccessfulSql, setLastSuccessfulSql] = useState<string |
null>(null);
useEffect(() => {
if (latestQueryState === QueryState.Success) {
setLastSuccessfulSql(queryEditor.sql);
}
}, [latestQueryState, queryEditor.sql]);
const hasSuccessfulQuery =
latestQueryState === QueryState.Success &&
lastSuccessfulSql === queryEditor.sql;
```
--
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]