You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2023/03/22 21:35:30 UTC
[superset] branch master updated: chore(sqllab): Remove schemaOptions from redux store (#23257)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new ca4dd26648 chore(sqllab): Remove schemaOptions from redux store (#23257)
ca4dd26648 is described below
commit ca4dd26648005f7de139dc53bf89ca078dee2f24
Author: JUST.in DO IT <ju...@airbnb.com>
AuthorDate: Wed Mar 22 14:35:22 2023 -0700
chore(sqllab): Remove schemaOptions from redux store (#23257)
---
superset-frontend/src/SqlLab/actions/sqlLab.js | 6 ----
.../src/SqlLab/actions/sqlLab.test.js | 1 -
.../SqlLab/components/AceEditorWrapper/index.tsx | 32 ++++++++++++++--------
.../src/SqlLab/components/SaveQuery/index.tsx | 1 -
.../SqlLab/components/SqlEditorLeftBar/index.tsx | 11 --------
superset-frontend/src/SqlLab/fixtures.ts | 7 -----
.../hooks/useQueryEditor/useQueryEditor.test.ts | 9 ++----
superset-frontend/src/SqlLab/reducers/sqlLab.js | 12 --------
superset-frontend/src/SqlLab/types.ts | 1 -
.../src/SqlLab/utils/emptyQueryResults.test.js | 4 +--
.../DatabaseSelector/DatabaseSelector.test.tsx | 1 -
.../src/components/DatabaseSelector/index.tsx | 4 ---
.../src/components/TableSelector/index.tsx | 4 ---
13 files changed, 24 insertions(+), 69 deletions(-)
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js
index da0bc2dc5b..50a6346524 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.js
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.js
@@ -50,8 +50,6 @@ export const EXPAND_TABLE = 'EXPAND_TABLE';
export const COLLAPSE_TABLE = 'COLLAPSE_TABLE';
export const QUERY_EDITOR_SETDB = 'QUERY_EDITOR_SETDB';
export const QUERY_EDITOR_SET_SCHEMA = 'QUERY_EDITOR_SET_SCHEMA';
-export const QUERY_EDITOR_SET_SCHEMA_OPTIONS =
- 'QUERY_EDITOR_SET_SCHEMA_OPTIONS';
export const QUERY_EDITOR_SET_TABLE_OPTIONS = 'QUERY_EDITOR_SET_TABLE_OPTIONS';
export const QUERY_EDITOR_SET_TITLE = 'QUERY_EDITOR_SET_TITLE';
export const QUERY_EDITOR_SET_AUTORUN = 'QUERY_EDITOR_SET_AUTORUN';
@@ -946,10 +944,6 @@ export function queryEditorSetSchema(queryEditor, schema) {
};
}
-export function queryEditorSetSchemaOptions(queryEditor, options) {
- return { type: QUERY_EDITOR_SET_SCHEMA_OPTIONS, queryEditor, options };
-}
-
export function queryEditorSetTableOptions(queryEditor, options) {
return { type: QUERY_EDITOR_SET_TABLE_OPTIONS, queryEditor, options };
}
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.js b/superset-frontend/src/SqlLab/actions/sqlLab.test.js
index 3aedf3b255..01886d6f77 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.test.js
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.js
@@ -45,7 +45,6 @@ describe('async actions', () => {
latestQueryId: null,
sql: 'SELECT *\nFROM\nWHERE',
name: 'Untitled Query 1',
- schemaOptions: [{ value: 'main', label: 'main', title: 'main' }],
};
let dispatch;
diff --git a/superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx b/superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx
index 32d17340fb..d14d532dcd 100644
--- a/superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx
+++ b/superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-import React, { useState, useEffect, useRef } from 'react';
+import React, { useState, useEffect, useRef, useMemo } from 'react';
import { useDispatch } from 'react-redux';
import { css, styled, usePrevious } from '@superset-ui/core';
@@ -39,6 +39,7 @@ import {
FullSQLEditor as AceEditor,
} from 'src/components/AsyncAceEditor';
import useQueryEditor from 'src/SqlLab/hooks/useQueryEditor';
+import { useSchemas } from 'src/hooks/apiResources';
type HotKey = {
key: string;
@@ -80,6 +81,7 @@ const StyledAceEditor = styled(AceEditor)`
}
`}
`;
+
const AceEditorWrapper = ({
autocomplete,
onBlur = () => {},
@@ -97,14 +99,27 @@ const AceEditorWrapper = ({
'dbId',
'sql',
'functionNames',
- 'schemaOptions',
'tableOptions',
'validationResult',
'schema',
]);
+ const { data: schemaOptions } = useSchemas({ dbId: queryEditor.dbId });
const currentSql = queryEditor.sql ?? '';
const functionNames = queryEditor.functionNames ?? [];
- const schemas = queryEditor.schemaOptions ?? [];
+
+ // Loading schema, table and column names as auto-completable words
+ const { schemas, schemaWords } = useMemo(
+ () => ({
+ schemas: schemaOptions ?? [],
+ schemaWords: (schemaOptions ?? []).map(s => ({
+ name: s.label,
+ value: s.value,
+ score: SCHEMA_AUTOCOMPLETE_SCORE,
+ meta: 'schema',
+ })),
+ }),
+ [schemaOptions],
+ );
const tables = queryEditor.tableOptions ?? [];
const [sql, setSql] = useState(currentSql);
@@ -192,14 +207,7 @@ const AceEditorWrapper = ({
onChange(text);
};
- const setAutoCompleter = () => {
- // Loading schema, table and column names as auto-completable words
- const schemaWords = schemas.map(s => ({
- name: s.label,
- value: s.value,
- score: SCHEMA_AUTOCOMPLETE_SCORE,
- meta: 'schema',
- }));
+ function setAutoCompleter() {
const columns = {};
const tableWords = tables.map(t => {
@@ -263,7 +271,7 @@ const AceEditorWrapper = ({
}));
setWords(words);
- };
+ }
const getAceAnnotations = () => {
const { validationResult } = queryEditor;
diff --git a/superset-frontend/src/SqlLab/components/SaveQuery/index.tsx b/superset-frontend/src/SqlLab/components/SaveQuery/index.tsx
index 684c4ed39c..b513637b27 100644
--- a/superset-frontend/src/SqlLab/components/SaveQuery/index.tsx
+++ b/superset-frontend/src/SqlLab/components/SaveQuery/index.tsx
@@ -78,7 +78,6 @@ const SaveQuery = ({
'latestQueryId',
'queryLimit',
'schema',
- 'schemaOptions',
'selectedText',
'sql',
'tableOptions',
diff --git a/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx b/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx
index e241e3c2e2..0cacdb86ca 100644
--- a/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx
+++ b/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx
@@ -36,7 +36,6 @@ import {
expandTable,
queryEditorSetSchema,
queryEditorSetTableOptions,
- queryEditorSetSchemaOptions,
setDatabases,
addDangerToast,
resetState,
@@ -228,15 +227,6 @@ const SqlEditorLeftBar = ({
[dispatch, queryEditor],
);
- const handleSchemasLoad = useCallback(
- (options: Array<any>) => {
- if (queryEditor) {
- dispatch(queryEditorSetSchemaOptions(queryEditor, options));
- }
- },
- [dispatch, queryEditor],
- );
-
const handleDbList = useCallback(
(result: DatabaseObject) => {
dispatch(setDatabases(result));
@@ -265,7 +255,6 @@ const SqlEditorLeftBar = ({
handleError={handleError}
onDbChange={onDbChange}
onSchemaChange={handleSchemaChange}
- onSchemasLoad={handleSchemasLoad}
onTableSelectChange={onTablesChange}
onTablesLoad={handleTablesLoad}
schema={schema}
diff --git a/superset-frontend/src/SqlLab/fixtures.ts b/superset-frontend/src/SqlLab/fixtures.ts
index 456a83a3fa..fcb0fff8e3 100644
--- a/superset-frontend/src/SqlLab/fixtures.ts
+++ b/superset-frontend/src/SqlLab/fixtures.ts
@@ -188,13 +188,6 @@ export const defaultQueryEditor = {
tableOptions: [],
functionNames: [],
hideLeftBar: false,
- schemaOptions: [
- {
- value: 'main',
- label: 'main',
- title: 'main',
- },
- ],
templateParams: '{}',
};
diff --git a/superset-frontend/src/SqlLab/hooks/useQueryEditor/useQueryEditor.test.ts b/superset-frontend/src/SqlLab/hooks/useQueryEditor/useQueryEditor.test.ts
index 23de4d6822..9e2d57f3a2 100644
--- a/superset-frontend/src/SqlLab/hooks/useQueryEditor/useQueryEditor.test.ts
+++ b/superset-frontend/src/SqlLab/hooks/useQueryEditor/useQueryEditor.test.ts
@@ -30,12 +30,7 @@ const mockStore = configureStore(middlewares);
test('returns selected queryEditor values', () => {
const { result } = renderHook(
() =>
- useQueryEditor(defaultQueryEditor.id, [
- 'id',
- 'name',
- 'dbId',
- 'schemaOptions',
- ]),
+ useQueryEditor(defaultQueryEditor.id, ['id', 'name', 'dbId', 'schema']),
{
wrapper: createWrapper({
useRedux: true,
@@ -47,7 +42,7 @@ test('returns selected queryEditor values', () => {
id: defaultQueryEditor.id,
name: defaultQueryEditor.name,
dbId: defaultQueryEditor.dbId,
- schemaOptions: defaultQueryEditor.schemaOptions,
+ schema: defaultQueryEditor.schema,
});
});
diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.js b/superset-frontend/src/SqlLab/reducers/sqlLab.js
index a110914b81..ff2cb340bb 100644
--- a/superset-frontend/src/SqlLab/reducers/sqlLab.js
+++ b/superset-frontend/src/SqlLab/reducers/sqlLab.js
@@ -587,18 +587,6 @@ export default function sqlLabReducer(state = {}, action) {
),
};
},
- [actions.QUERY_EDITOR_SET_SCHEMA_OPTIONS]() {
- return {
- ...state,
- ...alterUnsavedQueryEditorState(
- state,
- {
- schemaOptions: action.options,
- },
- action.queryEditor.id,
- ),
- };
- },
[actions.QUERY_EDITOR_SET_TABLE_OPTIONS]() {
return {
...state,
diff --git a/superset-frontend/src/SqlLab/types.ts b/superset-frontend/src/SqlLab/types.ts
index 7317ef0789..ab63e1c760 100644
--- a/superset-frontend/src/SqlLab/types.ts
+++ b/superset-frontend/src/SqlLab/types.ts
@@ -40,7 +40,6 @@ export interface QueryEditor {
sql: string;
remoteId: number | null;
tableOptions: any[];
- schemaOptions?: SchemaOption[];
functionNames: string[];
validationResult?: {
completed: boolean;
diff --git a/superset-frontend/src/SqlLab/utils/emptyQueryResults.test.js b/superset-frontend/src/SqlLab/utils/emptyQueryResults.test.js
index 78072f3e9a..9984e1efca 100644
--- a/superset-frontend/src/SqlLab/utils/emptyQueryResults.test.js
+++ b/superset-frontend/src/SqlLab/utils/emptyQueryResults.test.js
@@ -84,9 +84,9 @@ describe('reduxStateToLocalStorageHelper', () => {
it('should only return selected keys for query editor', () => {
const queryEditors = [defaultQueryEditor];
- expect(Object.keys(queryEditors[0])).toContain('schemaOptions');
+ expect(Object.keys(queryEditors[0])).toContain('schema');
const clearedQueryEditors = clearQueryEditors(queryEditors);
- expect(Object.keys(clearedQueryEditors)[0]).not.toContain('schemaOptions');
+ expect(Object.keys(clearedQueryEditors)[0]).not.toContain('schema');
});
});
diff --git a/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx b/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx
index ce2016a8aa..a684e6d837 100644
--- a/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx
+++ b/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx
@@ -40,7 +40,6 @@ const createProps = (): DatabaseSelectorProps => ({
handleError: jest.fn(),
onDbChange: jest.fn(),
onSchemaChange: jest.fn(),
- onSchemasLoad: jest.fn(),
});
const fakeDatabaseApiResult = {
diff --git a/superset-frontend/src/components/DatabaseSelector/index.tsx b/superset-frontend/src/components/DatabaseSelector/index.tsx
index 65b93d3561..cbac989688 100644
--- a/superset-frontend/src/components/DatabaseSelector/index.tsx
+++ b/superset-frontend/src/components/DatabaseSelector/index.tsx
@@ -93,7 +93,6 @@ export interface DatabaseSelectorProps {
onDbChange?: (db: DatabaseObject) => void;
onEmptyResults?: (searchText?: string) => void;
onSchemaChange?: (schema?: string) => void;
- onSchemasLoad?: (schemas: Array<object>) => void;
readOnly?: boolean;
schema?: string;
sqlLabMode?: boolean;
@@ -126,7 +125,6 @@ export default function DatabaseSelector({
onDbChange,
onEmptyResults,
onSchemaChange,
- onSchemasLoad,
readOnly = false,
schema,
sqlLabMode = false,
@@ -230,8 +228,6 @@ export default function DatabaseSelector({
} = useSchemas({
dbId: currentDb?.value,
onSuccess: data => {
- onSchemasLoad?.(data);
-
if (data.length === 1) {
changeSchema(data[0]);
} else if (!data.find(schemaOption => schema === schemaOption.value)) {
diff --git a/superset-frontend/src/components/TableSelector/index.tsx b/superset-frontend/src/components/TableSelector/index.tsx
index d04de21715..2c51462e6d 100644
--- a/superset-frontend/src/components/TableSelector/index.tsx
+++ b/superset-frontend/src/components/TableSelector/index.tsx
@@ -36,7 +36,6 @@ import RefreshLabel from 'src/components/RefreshLabel';
import CertifiedBadge from 'src/components/CertifiedBadge';
import WarningIconWithTooltip from 'src/components/WarningIconWithTooltip';
import { useToasts } from 'src/components/MessageToasts/withToasts';
-import { SchemaOption } from 'src/SqlLab/types';
import { useTables, Table } from 'src/hooks/apiResources';
import {
getClientErrorMessage,
@@ -98,7 +97,6 @@ interface TableSelectorProps {
isDatabaseSelectEnabled?: boolean;
onDbChange?: (db: DatabaseObject) => void;
onSchemaChange?: (schema?: string) => void;
- onSchemasLoad?: (schemaOptions: SchemaOption[]) => void;
onTablesLoad?: (options: Array<any>) => void;
readOnly?: boolean;
schema?: string;
@@ -160,7 +158,6 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
isDatabaseSelectEnabled = true,
onDbChange,
onSchemaChange,
- onSchemasLoad,
onTablesLoad,
readOnly = false,
onEmptyResults,
@@ -335,7 +332,6 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
onDbChange={readOnly ? undefined : internalDbChange}
onEmptyResults={onEmptyResults}
onSchemaChange={readOnly ? undefined : internalSchemaChange}
- onSchemasLoad={onSchemasLoad}
schema={currentSchema}
sqlLabMode={sqlLabMode}
isDatabaseSelectEnabled={isDatabaseSelectEnabled && !readOnly}