chore(frontend): migrate SqlLab and explore JS/JSX files to TypeScript (#36760)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Evan Rusackas
2026-01-06 10:52:58 -08:00
committed by GitHub
parent aaa174f820
commit 9aff89c1b4
69 changed files with 3272 additions and 1482 deletions

View File

@@ -17,6 +17,7 @@
* under the License.
*/
import type React from 'react';
import { Route } from 'react-router-dom';
import fetchMock from 'fetch-mock';
import { DatasourceType, JsonObject, SupersetClient } from '@superset-ui/core';
@@ -28,7 +29,7 @@ import {
waitFor,
} from 'spec/helpers/testing-library';
import { fallbackExploreInitialData } from 'src/explore/fixtures';
import type { DatasetObject, ColumnObject } from 'src/features/datasets/types';
import type { ColumnObject } from 'src/features/datasets/types';
import DatasourceControl from '.';
const SupersetClientGet = jest.spyOn(SupersetClient, 'get');
@@ -46,20 +47,35 @@ afterEach(() => {
jest.clearAllMocks(); // Clears mock history but keeps spy in place
});
type TestDatasource = Omit<
Partial<DatasetObject>,
'columns' | 'main_dttm_col'
> & {
interface TestDatasource {
id?: number;
name: string;
database: { name: string };
datasource_name?: string;
database: {
id: number;
database_name: string;
name?: string;
backend?: string;
};
columns?: Partial<ColumnObject>[];
type?: DatasourceType;
main_dttm_col?: string | null;
};
owners?: Array<{
first_name: string;
last_name: string;
id: number;
username?: string;
}>;
sql?: string;
metrics?: Array<{ id: number; metric_name: string }>;
[key: string]: unknown;
}
const mockDatasource: TestDatasource = {
id: 25,
database: {
id: 1,
database_name: 'examples',
name: 'examples',
},
name: 'channels',
@@ -69,39 +85,50 @@ const mockDatasource: TestDatasource = {
owners: [{ first_name: 'john', last_name: 'doe', id: 1, username: 'jd' }],
sql: 'SELECT * FROM mock_datasource_sql',
};
const createProps = (overrides: JsonObject = {}) => ({
hovered: false,
type: 'DatasourceControl',
label: 'Datasource',
default: null,
description: null,
value: '25__table',
form_data: {},
datasource: mockDatasource,
validationErrors: [],
name: 'datasource',
actions: {
changeDatasource: jest.fn(),
setControlValue: jest.fn(),
},
isEditable: true,
user: {
createdOn: '2021-04-27T18:12:38.952304',
email: 'admin',
firstName: 'admin',
isActive: true,
lastName: 'admin',
permissions: {},
roles: { Admin: Array(173) },
userId: 1,
username: 'admin',
},
onChange: jest.fn(),
onDatasourceSave: jest.fn(),
...overrides,
});
async function openAndSaveChanges(datasource: TestDatasource) {
// Use type assertion for test props since the component is wrapped with withTheme
// The withTheme HOC makes the props type complex, so we cast through unknown to bypass type check
type DatasourceControlComponentProps = React.ComponentProps<
typeof DatasourceControl
>;
const createProps = (
overrides: JsonObject = {},
): DatasourceControlComponentProps =>
({
hovered: false,
type: 'DatasourceControl',
label: 'Datasource',
default: null,
description: null,
value: '25__table',
form_data: {},
datasource: mockDatasource,
validationErrors: [],
name: 'datasource',
actions: {
changeDatasource: jest.fn(),
setControlValue: jest.fn(),
},
isEditable: true,
user: {
createdOn: '2021-04-27T18:12:38.952304',
email: 'admin',
firstName: 'admin',
isActive: true,
lastName: 'admin',
permissions: {},
roles: { Admin: Array(173) },
userId: 1,
username: 'admin',
},
onChange: jest.fn(),
onDatasourceSave: jest.fn(),
...overrides,
}) as unknown as DatasourceControlComponentProps;
async function openAndSaveChanges(
datasource: TestDatasource | Record<string, unknown>,
) {
fetchMock.get(
'glob:*/api/v1/database/?q=*',
{ result: [] },
@@ -259,7 +286,6 @@ test('Click on Edit dataset', async () => {
test('Edit dataset should be disabled when user is not admin', async () => {
const props = createProps();
// @ts-expect-error
props.user.roles = {};
props.datasource.owners = [];
SupersetClientGet.mockImplementationOnce(
@@ -458,11 +484,11 @@ test('should not set the temporal column', async () => {
const overrideProps = {
...props,
form_data: {
granularity_sqla: null,
granularity_sqla: undefined,
},
datasource: {
...props.datasource,
main_dttm_col: null,
main_dttm_col: undefined,
columns: [
{
column_name: 'test-col',