mirror of
https://github.com/apache/superset.git
synced 2024-09-16 10:39:55 -04:00
chore(sqllab): Remove schemaOptions from redux store (#23257)
This commit is contained in:
parent
b1526c14e0
commit
ca4dd26648
@ -50,8 +50,6 @@ export const EXPAND_TABLE = 'EXPAND_TABLE';
|
|||||||
export const COLLAPSE_TABLE = 'COLLAPSE_TABLE';
|
export const COLLAPSE_TABLE = 'COLLAPSE_TABLE';
|
||||||
export const QUERY_EDITOR_SETDB = 'QUERY_EDITOR_SETDB';
|
export const QUERY_EDITOR_SETDB = 'QUERY_EDITOR_SETDB';
|
||||||
export const QUERY_EDITOR_SET_SCHEMA = 'QUERY_EDITOR_SET_SCHEMA';
|
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_TABLE_OPTIONS = 'QUERY_EDITOR_SET_TABLE_OPTIONS';
|
||||||
export const QUERY_EDITOR_SET_TITLE = 'QUERY_EDITOR_SET_TITLE';
|
export const QUERY_EDITOR_SET_TITLE = 'QUERY_EDITOR_SET_TITLE';
|
||||||
export const QUERY_EDITOR_SET_AUTORUN = 'QUERY_EDITOR_SET_AUTORUN';
|
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) {
|
export function queryEditorSetTableOptions(queryEditor, options) {
|
||||||
return { type: QUERY_EDITOR_SET_TABLE_OPTIONS, queryEditor, options };
|
return { type: QUERY_EDITOR_SET_TABLE_OPTIONS, queryEditor, options };
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,6 @@ describe('async actions', () => {
|
|||||||
latestQueryId: null,
|
latestQueryId: null,
|
||||||
sql: 'SELECT *\nFROM\nWHERE',
|
sql: 'SELECT *\nFROM\nWHERE',
|
||||||
name: 'Untitled Query 1',
|
name: 'Untitled Query 1',
|
||||||
schemaOptions: [{ value: 'main', label: 'main', title: 'main' }],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let dispatch;
|
let dispatch;
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import React, { useState, useEffect, useRef } from 'react';
|
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { css, styled, usePrevious } from '@superset-ui/core';
|
import { css, styled, usePrevious } from '@superset-ui/core';
|
||||||
|
|
||||||
@ -39,6 +39,7 @@ import {
|
|||||||
FullSQLEditor as AceEditor,
|
FullSQLEditor as AceEditor,
|
||||||
} from 'src/components/AsyncAceEditor';
|
} from 'src/components/AsyncAceEditor';
|
||||||
import useQueryEditor from 'src/SqlLab/hooks/useQueryEditor';
|
import useQueryEditor from 'src/SqlLab/hooks/useQueryEditor';
|
||||||
|
import { useSchemas } from 'src/hooks/apiResources';
|
||||||
|
|
||||||
type HotKey = {
|
type HotKey = {
|
||||||
key: string;
|
key: string;
|
||||||
@ -80,6 +81,7 @@ const StyledAceEditor = styled(AceEditor)`
|
|||||||
}
|
}
|
||||||
`}
|
`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const AceEditorWrapper = ({
|
const AceEditorWrapper = ({
|
||||||
autocomplete,
|
autocomplete,
|
||||||
onBlur = () => {},
|
onBlur = () => {},
|
||||||
@ -97,14 +99,27 @@ const AceEditorWrapper = ({
|
|||||||
'dbId',
|
'dbId',
|
||||||
'sql',
|
'sql',
|
||||||
'functionNames',
|
'functionNames',
|
||||||
'schemaOptions',
|
|
||||||
'tableOptions',
|
'tableOptions',
|
||||||
'validationResult',
|
'validationResult',
|
||||||
'schema',
|
'schema',
|
||||||
]);
|
]);
|
||||||
|
const { data: schemaOptions } = useSchemas({ dbId: queryEditor.dbId });
|
||||||
const currentSql = queryEditor.sql ?? '';
|
const currentSql = queryEditor.sql ?? '';
|
||||||
const functionNames = queryEditor.functionNames ?? [];
|
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 tables = queryEditor.tableOptions ?? [];
|
||||||
|
|
||||||
const [sql, setSql] = useState(currentSql);
|
const [sql, setSql] = useState(currentSql);
|
||||||
@ -192,14 +207,7 @@ const AceEditorWrapper = ({
|
|||||||
onChange(text);
|
onChange(text);
|
||||||
};
|
};
|
||||||
|
|
||||||
const setAutoCompleter = () => {
|
function 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',
|
|
||||||
}));
|
|
||||||
const columns = {};
|
const columns = {};
|
||||||
|
|
||||||
const tableWords = tables.map(t => {
|
const tableWords = tables.map(t => {
|
||||||
@ -263,7 +271,7 @@ const AceEditorWrapper = ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
setWords(words);
|
setWords(words);
|
||||||
};
|
}
|
||||||
|
|
||||||
const getAceAnnotations = () => {
|
const getAceAnnotations = () => {
|
||||||
const { validationResult } = queryEditor;
|
const { validationResult } = queryEditor;
|
||||||
|
@ -78,7 +78,6 @@ const SaveQuery = ({
|
|||||||
'latestQueryId',
|
'latestQueryId',
|
||||||
'queryLimit',
|
'queryLimit',
|
||||||
'schema',
|
'schema',
|
||||||
'schemaOptions',
|
|
||||||
'selectedText',
|
'selectedText',
|
||||||
'sql',
|
'sql',
|
||||||
'tableOptions',
|
'tableOptions',
|
||||||
|
@ -36,7 +36,6 @@ import {
|
|||||||
expandTable,
|
expandTable,
|
||||||
queryEditorSetSchema,
|
queryEditorSetSchema,
|
||||||
queryEditorSetTableOptions,
|
queryEditorSetTableOptions,
|
||||||
queryEditorSetSchemaOptions,
|
|
||||||
setDatabases,
|
setDatabases,
|
||||||
addDangerToast,
|
addDangerToast,
|
||||||
resetState,
|
resetState,
|
||||||
@ -228,15 +227,6 @@ const SqlEditorLeftBar = ({
|
|||||||
[dispatch, queryEditor],
|
[dispatch, queryEditor],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSchemasLoad = useCallback(
|
|
||||||
(options: Array<any>) => {
|
|
||||||
if (queryEditor) {
|
|
||||||
dispatch(queryEditorSetSchemaOptions(queryEditor, options));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[dispatch, queryEditor],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleDbList = useCallback(
|
const handleDbList = useCallback(
|
||||||
(result: DatabaseObject) => {
|
(result: DatabaseObject) => {
|
||||||
dispatch(setDatabases(result));
|
dispatch(setDatabases(result));
|
||||||
@ -265,7 +255,6 @@ const SqlEditorLeftBar = ({
|
|||||||
handleError={handleError}
|
handleError={handleError}
|
||||||
onDbChange={onDbChange}
|
onDbChange={onDbChange}
|
||||||
onSchemaChange={handleSchemaChange}
|
onSchemaChange={handleSchemaChange}
|
||||||
onSchemasLoad={handleSchemasLoad}
|
|
||||||
onTableSelectChange={onTablesChange}
|
onTableSelectChange={onTablesChange}
|
||||||
onTablesLoad={handleTablesLoad}
|
onTablesLoad={handleTablesLoad}
|
||||||
schema={schema}
|
schema={schema}
|
||||||
|
@ -188,13 +188,6 @@ export const defaultQueryEditor = {
|
|||||||
tableOptions: [],
|
tableOptions: [],
|
||||||
functionNames: [],
|
functionNames: [],
|
||||||
hideLeftBar: false,
|
hideLeftBar: false,
|
||||||
schemaOptions: [
|
|
||||||
{
|
|
||||||
value: 'main',
|
|
||||||
label: 'main',
|
|
||||||
title: 'main',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
templateParams: '{}',
|
templateParams: '{}',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,12 +30,7 @@ const mockStore = configureStore(middlewares);
|
|||||||
test('returns selected queryEditor values', () => {
|
test('returns selected queryEditor values', () => {
|
||||||
const { result } = renderHook(
|
const { result } = renderHook(
|
||||||
() =>
|
() =>
|
||||||
useQueryEditor(defaultQueryEditor.id, [
|
useQueryEditor(defaultQueryEditor.id, ['id', 'name', 'dbId', 'schema']),
|
||||||
'id',
|
|
||||||
'name',
|
|
||||||
'dbId',
|
|
||||||
'schemaOptions',
|
|
||||||
]),
|
|
||||||
{
|
{
|
||||||
wrapper: createWrapper({
|
wrapper: createWrapper({
|
||||||
useRedux: true,
|
useRedux: true,
|
||||||
@ -47,7 +42,7 @@ test('returns selected queryEditor values', () => {
|
|||||||
id: defaultQueryEditor.id,
|
id: defaultQueryEditor.id,
|
||||||
name: defaultQueryEditor.name,
|
name: defaultQueryEditor.name,
|
||||||
dbId: defaultQueryEditor.dbId,
|
dbId: defaultQueryEditor.dbId,
|
||||||
schemaOptions: defaultQueryEditor.schemaOptions,
|
schema: defaultQueryEditor.schema,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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]() {
|
[actions.QUERY_EDITOR_SET_TABLE_OPTIONS]() {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
@ -40,7 +40,6 @@ export interface QueryEditor {
|
|||||||
sql: string;
|
sql: string;
|
||||||
remoteId: number | null;
|
remoteId: number | null;
|
||||||
tableOptions: any[];
|
tableOptions: any[];
|
||||||
schemaOptions?: SchemaOption[];
|
|
||||||
functionNames: string[];
|
functionNames: string[];
|
||||||
validationResult?: {
|
validationResult?: {
|
||||||
completed: boolean;
|
completed: boolean;
|
||||||
|
@ -84,9 +84,9 @@ describe('reduxStateToLocalStorageHelper', () => {
|
|||||||
|
|
||||||
it('should only return selected keys for query editor', () => {
|
it('should only return selected keys for query editor', () => {
|
||||||
const queryEditors = [defaultQueryEditor];
|
const queryEditors = [defaultQueryEditor];
|
||||||
expect(Object.keys(queryEditors[0])).toContain('schemaOptions');
|
expect(Object.keys(queryEditors[0])).toContain('schema');
|
||||||
|
|
||||||
const clearedQueryEditors = clearQueryEditors(queryEditors);
|
const clearedQueryEditors = clearQueryEditors(queryEditors);
|
||||||
expect(Object.keys(clearedQueryEditors)[0]).not.toContain('schemaOptions');
|
expect(Object.keys(clearedQueryEditors)[0]).not.toContain('schema');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -40,7 +40,6 @@ const createProps = (): DatabaseSelectorProps => ({
|
|||||||
handleError: jest.fn(),
|
handleError: jest.fn(),
|
||||||
onDbChange: jest.fn(),
|
onDbChange: jest.fn(),
|
||||||
onSchemaChange: jest.fn(),
|
onSchemaChange: jest.fn(),
|
||||||
onSchemasLoad: jest.fn(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const fakeDatabaseApiResult = {
|
const fakeDatabaseApiResult = {
|
||||||
|
@ -93,7 +93,6 @@ export interface DatabaseSelectorProps {
|
|||||||
onDbChange?: (db: DatabaseObject) => void;
|
onDbChange?: (db: DatabaseObject) => void;
|
||||||
onEmptyResults?: (searchText?: string) => void;
|
onEmptyResults?: (searchText?: string) => void;
|
||||||
onSchemaChange?: (schema?: string) => void;
|
onSchemaChange?: (schema?: string) => void;
|
||||||
onSchemasLoad?: (schemas: Array<object>) => void;
|
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
schema?: string;
|
schema?: string;
|
||||||
sqlLabMode?: boolean;
|
sqlLabMode?: boolean;
|
||||||
@ -126,7 +125,6 @@ export default function DatabaseSelector({
|
|||||||
onDbChange,
|
onDbChange,
|
||||||
onEmptyResults,
|
onEmptyResults,
|
||||||
onSchemaChange,
|
onSchemaChange,
|
||||||
onSchemasLoad,
|
|
||||||
readOnly = false,
|
readOnly = false,
|
||||||
schema,
|
schema,
|
||||||
sqlLabMode = false,
|
sqlLabMode = false,
|
||||||
@ -230,8 +228,6 @@ export default function DatabaseSelector({
|
|||||||
} = useSchemas({
|
} = useSchemas({
|
||||||
dbId: currentDb?.value,
|
dbId: currentDb?.value,
|
||||||
onSuccess: data => {
|
onSuccess: data => {
|
||||||
onSchemasLoad?.(data);
|
|
||||||
|
|
||||||
if (data.length === 1) {
|
if (data.length === 1) {
|
||||||
changeSchema(data[0]);
|
changeSchema(data[0]);
|
||||||
} else if (!data.find(schemaOption => schema === schemaOption.value)) {
|
} else if (!data.find(schemaOption => schema === schemaOption.value)) {
|
||||||
|
@ -36,7 +36,6 @@ import RefreshLabel from 'src/components/RefreshLabel';
|
|||||||
import CertifiedBadge from 'src/components/CertifiedBadge';
|
import CertifiedBadge from 'src/components/CertifiedBadge';
|
||||||
import WarningIconWithTooltip from 'src/components/WarningIconWithTooltip';
|
import WarningIconWithTooltip from 'src/components/WarningIconWithTooltip';
|
||||||
import { useToasts } from 'src/components/MessageToasts/withToasts';
|
import { useToasts } from 'src/components/MessageToasts/withToasts';
|
||||||
import { SchemaOption } from 'src/SqlLab/types';
|
|
||||||
import { useTables, Table } from 'src/hooks/apiResources';
|
import { useTables, Table } from 'src/hooks/apiResources';
|
||||||
import {
|
import {
|
||||||
getClientErrorMessage,
|
getClientErrorMessage,
|
||||||
@ -98,7 +97,6 @@ interface TableSelectorProps {
|
|||||||
isDatabaseSelectEnabled?: boolean;
|
isDatabaseSelectEnabled?: boolean;
|
||||||
onDbChange?: (db: DatabaseObject) => void;
|
onDbChange?: (db: DatabaseObject) => void;
|
||||||
onSchemaChange?: (schema?: string) => void;
|
onSchemaChange?: (schema?: string) => void;
|
||||||
onSchemasLoad?: (schemaOptions: SchemaOption[]) => void;
|
|
||||||
onTablesLoad?: (options: Array<any>) => void;
|
onTablesLoad?: (options: Array<any>) => void;
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
schema?: string;
|
schema?: string;
|
||||||
@ -160,7 +158,6 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
|
|||||||
isDatabaseSelectEnabled = true,
|
isDatabaseSelectEnabled = true,
|
||||||
onDbChange,
|
onDbChange,
|
||||||
onSchemaChange,
|
onSchemaChange,
|
||||||
onSchemasLoad,
|
|
||||||
onTablesLoad,
|
onTablesLoad,
|
||||||
readOnly = false,
|
readOnly = false,
|
||||||
onEmptyResults,
|
onEmptyResults,
|
||||||
@ -335,7 +332,6 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
|
|||||||
onDbChange={readOnly ? undefined : internalDbChange}
|
onDbChange={readOnly ? undefined : internalDbChange}
|
||||||
onEmptyResults={onEmptyResults}
|
onEmptyResults={onEmptyResults}
|
||||||
onSchemaChange={readOnly ? undefined : internalSchemaChange}
|
onSchemaChange={readOnly ? undefined : internalSchemaChange}
|
||||||
onSchemasLoad={onSchemasLoad}
|
|
||||||
schema={currentSchema}
|
schema={currentSchema}
|
||||||
sqlLabMode={sqlLabMode}
|
sqlLabMode={sqlLabMode}
|
||||||
isDatabaseSelectEnabled={isDatabaseSelectEnabled && !readOnly}
|
isDatabaseSelectEnabled={isDatabaseSelectEnabled && !readOnly}
|
||||||
|
Loading…
Reference in New Issue
Block a user