From 34f99708d46e1b5b0f0211f493be9617da86dcbf Mon Sep 17 00:00:00 2001 From: "JUST.in DO IT" Date: Thu, 5 Oct 2023 12:33:01 -0400 Subject: [PATCH] chore(sqllab): Typescript for SqlEditor component (#25228) --- superset-frontend/package-lock.json | 13 + superset-frontend/package.json | 1 + .../components/AceEditorWrapper/index.tsx | 3 +- .../components/RunQueryActionButton/index.tsx | 3 +- .../src/SqlLab/components/SaveQuery/index.tsx | 7 +- .../components/ScheduleQueryButton/index.tsx | 2 +- ...{SqlEditor.test.jsx => SqlEditor.test.tsx} | 41 ++- .../SqlEditor/{index.jsx => index.tsx} | 272 ++++++++++-------- .../components/SqlEditorLeftBar/index.tsx | 10 +- .../components/TemplateParamsEditor/index.tsx | 2 +- superset-frontend/src/SqlLab/constants.ts | 3 +- superset-frontend/src/SqlLab/types.ts | 2 + .../src/components/DatabaseSelector/index.tsx | 8 +- .../databases/DatabaseModal/index.test.tsx | 2 + .../src/features/databases/types.ts | 5 +- 15 files changed, 216 insertions(+), 158 deletions(-) rename superset-frontend/src/SqlLab/components/SqlEditor/{SqlEditor.test.jsx => SqlEditor.test.tsx} (89%) rename superset-frontend/src/SqlLab/components/SqlEditor/{index.jsx => index.tsx} (87%) diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index 4c0fa255e..b8780a78a 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -191,6 +191,7 @@ "@types/jquery": "^3.5.8", "@types/js-levenshtein": "^1.1.0", "@types/json-bigint": "^1.0.1", + "@types/mousetrap": "^1.6.11", "@types/react": "^16.9.43", "@types/react-dom": "^16.9.8", "@types/react-gravatar": "^2.6.8", @@ -19514,6 +19515,12 @@ "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==", "dev": true }, + "node_modules/@types/mousetrap": { + "version": "1.6.11", + "resolved": "https://registry.npmjs.org/@types/mousetrap/-/mousetrap-1.6.11.tgz", + "integrity": "sha512-F0oAily9Q9QQpv9JKxKn0zMKfOo36KHCW7myYsmUyf2t0g+sBTbG3UleTPoguHdE1z3GLFr3p7/wiOio52QFjQ==", + "dev": true + }, "node_modules/@types/ms": { "version": "0.7.31", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", @@ -79317,6 +79324,12 @@ "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==", "dev": true }, + "@types/mousetrap": { + "version": "1.6.11", + "resolved": "https://registry.npmjs.org/@types/mousetrap/-/mousetrap-1.6.11.tgz", + "integrity": "sha512-F0oAily9Q9QQpv9JKxKn0zMKfOo36KHCW7myYsmUyf2t0g+sBTbG3UleTPoguHdE1z3GLFr3p7/wiOio52QFjQ==", + "dev": true + }, "@types/ms": { "version": "0.7.31", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", diff --git a/superset-frontend/package.json b/superset-frontend/package.json index 299017b0d..8cee75833 100644 --- a/superset-frontend/package.json +++ b/superset-frontend/package.json @@ -256,6 +256,7 @@ "@types/jquery": "^3.5.8", "@types/js-levenshtein": "^1.1.0", "@types/json-bigint": "^1.0.1", + "@types/mousetrap": "^1.6.11", "@types/react": "^16.9.43", "@types/react-dom": "^16.9.8", "@types/react-gravatar": "^2.6.8", diff --git a/superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx b/superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx index 0adf3f8e1..17c84a366 100644 --- a/superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx +++ b/superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx @@ -17,6 +17,7 @@ * under the License. */ import React, { useState, useEffect, useRef } from 'react'; +import type { IAceEditor } from 'react-ace/lib/types'; import { useDispatch } from 'react-redux'; import { css, styled, usePrevious } from '@superset-ui/core'; @@ -30,7 +31,7 @@ type HotKey = { key: string; descr: string; name: string; - func: () => void; + func: (aceEditor: IAceEditor) => void; }; type AceEditorWrapperProps = { diff --git a/superset-frontend/src/SqlLab/components/RunQueryActionButton/index.tsx b/superset-frontend/src/SqlLab/components/RunQueryActionButton/index.tsx index d2da58709..30f812113 100644 --- a/superset-frontend/src/SqlLab/components/RunQueryActionButton/index.tsx +++ b/superset-frontend/src/SqlLab/components/RunQueryActionButton/index.tsx @@ -19,7 +19,6 @@ import React, { useMemo } from 'react'; import { t, styled, useTheme } from '@superset-ui/core'; -import { Menu } from 'src/components/Menu'; import Button from 'src/components/Button'; import Icons from 'src/components/Icons'; import { DropdownButton } from 'src/components/DropdownButton'; @@ -33,7 +32,7 @@ export interface RunQueryActionButtonProps { queryState?: string; runQuery: (c?: boolean) => void; stopQuery: () => void; - overlayCreateAsMenu: typeof Menu | null; + overlayCreateAsMenu: React.ReactElement | null; } const buildText = ( diff --git a/superset-frontend/src/SqlLab/components/SaveQuery/index.tsx b/superset-frontend/src/SqlLab/components/SaveQuery/index.tsx index 6ed0f4c66..a7ac8b1b2 100644 --- a/superset-frontend/src/SqlLab/components/SaveQuery/index.tsx +++ b/superset-frontend/src/SqlLab/components/SaveQuery/index.tsx @@ -17,6 +17,7 @@ * under the License. */ import React, { useState, useEffect, useMemo } from 'react'; +import type { DatabaseObject } from 'src/features/databases/types'; import { Row, Col } from 'src/components'; import { Input, TextArea } from 'src/components/Input'; import { t, styled } from '@superset-ui/core'; @@ -39,10 +40,10 @@ interface SaveQueryProps { onSave: (arg0: QueryPayload, id: string) => void; onUpdate: (arg0: QueryPayload, id: string) => void; saveQueryWarning: string | null; - database: Record; + database: Partial | undefined; } -type QueryPayload = { +export type QueryPayload = { name: string; description?: string; id?: string; @@ -65,7 +66,7 @@ const SaveQuery = ({ queryEditorId, onSave = () => {}, onUpdate, - saveQueryWarning = null, + saveQueryWarning, database, columns, }: SaveQueryProps) => { diff --git a/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx b/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx index d0a381638..f2e3d3358 100644 --- a/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx +++ b/superset-frontend/src/SqlLab/components/ScheduleQueryButton/index.tsx @@ -79,7 +79,7 @@ interface ScheduleQueryButtonProps { defaultLabel?: string; sql: string; schema?: string; - dbId: number; + dbId?: number; animation?: boolean; onSchedule?: Function; scheduleQueryWarning: string | null; diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.jsx b/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx similarity index 89% rename from superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.jsx rename to superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx index ff335e14e..63f67170d 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.jsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx @@ -21,7 +21,6 @@ import { act } from 'react-dom/test-utils'; import { fireEvent, render, waitFor } from 'spec/helpers/testing-library'; import fetchMock from 'fetch-mock'; import reducers from 'spec/helpers/reducerIndex'; -import SqlEditor from 'src/SqlLab/components/SqlEditor'; import { setupStore } from 'src/views/store'; import { initialState, @@ -34,10 +33,20 @@ import ResultSet from 'src/SqlLab/components/ResultSet'; import { api } from 'src/hooks/apiResources/queryApi'; import { getExtensionsRegistry } from '@superset-ui/core'; import setupExtensions from 'src/setup/setupExtensions'; +import type { Action, Middleware, Store } from 'redux'; +import SqlEditor, { Props } from '.'; jest.mock('src/components/AsyncAceEditor', () => ({ ...jest.requireActual('src/components/AsyncAceEditor'), - FullSQLEditor: ({ onChange, onBlur, value }) => ( + FullSQLEditor: ({ + onChange, + onBlur, + value, + }: { + onChange: (value: string) => void; + onBlur: React.FocusEventHandler; + value: string; + }) => (