mirror of
https://github.com/apache/superset.git
synced 2026-04-24 18:44:53 +00:00
chore(sqllab): Remove schemaOptions from redux store (#23257)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -78,7 +78,6 @@ const SaveQuery = ({
|
||||
'latestQueryId',
|
||||
'queryLimit',
|
||||
'schema',
|
||||
'schemaOptions',
|
||||
'selectedText',
|
||||
'sql',
|
||||
'tableOptions',
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user