-
Notifications
You must be signed in to change notification settings - Fork 17.7k
fix(sqllab): preserve database state on SET_DATABASES #41281
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,13 +21,53 @@ import sqlLabReducer from 'src/SqlLab/reducers/sqlLab'; | |
| import * as actions from 'src/SqlLab/actions/sqlLab'; | ||
| import type { SqlLabAction } from 'src/SqlLab/actions/sqlLab'; | ||
| import type { SqlLabRootState } from 'src/SqlLab/types'; | ||
| import { table, initialState as mockState } from '../fixtures'; | ||
| import { | ||
| table, | ||
| databases, | ||
| initialState as mockState, | ||
| } from '../fixtures'; | ||
|
|
||
| type SqlLabState = SqlLabRootState['sqlLab']; | ||
| const initialState = mockState.sqlLab as unknown as SqlLabState; | ||
|
|
||
| // eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks | ||
| describe('sqlLabReducer', () => { | ||
| describe('Database actions', () => { | ||
| test('should merge databases instead of replacing existing database state', () => { | ||
| const existingDb = databases.result[0]; | ||
| const incomingDb = databases.result[1]; | ||
|
|
||
| const state = { | ||
| ...initialState, | ||
| databases: { | ||
| [existingDb.id]: { | ||
| ...existingDb, | ||
| extra_json: {}, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const action = actions.setDatabases([ | ||
| { | ||
| ...incomingDb, | ||
| extra: '{}', | ||
| }, | ||
| ] as any); | ||
|
|
||
| const newState = sqlLabReducer(state as any, action); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Avoid casting Severity Level: Minor Why it matters? 🤔This modified TypeScript test line casts (Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** superset-frontend/src/SqlLab/reducers/sqlLab.test.ts
**Line:** 57:57
**Comment:**
*Custom Rule: Avoid casting `state` to `any`; declare `state` with the proper reducer state type so the reducer call remains fully type-checked.
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 |
||
|
|
||
| expect(newState.databases[existingDb.id]).toBeDefined(); | ||
| expect(newState.databases[incomingDb.id]).toBeDefined(); | ||
|
|
||
| expect( | ||
| newState.databases[existingDb.id].database_name, | ||
| ).toBe(existingDb.database_name); | ||
|
|
||
| expect( | ||
| newState.databases[incomingDb.id].database_name, | ||
| ).toBe(incomingDb.database_name); | ||
| }); | ||
| }); | ||
| // eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks | ||
| describe('Query editors actions', () => { | ||
| let newState: SqlLabState; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Remove the
anycast on thesetDatabasespayload and type it using the action creator's expected argument type (or a specific database DTO type) so the test validates real compile-time contracts. [custom_rule]Severity Level: Minor⚠️
Why it matters? 🤔
This is TypeScript code in a modified test file, and it uses
as anyon thesetDatabasespayload. The custom rule explicitly forbids new or modified TypeScript/TSX code from usingany, so this is a real violation.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖