refactor(sqllab): Remove tableOptions from redux state (#23488)

This commit is contained in:
JUST.in DO IT
2023-04-20 15:55:55 -07:00
committed by GitHub
parent a09162bb37
commit 5bec1a65ae
9 changed files with 12 additions and 92 deletions

View File

@@ -39,7 +39,7 @@ import {
FullSQLEditor as AceEditor,
} from 'src/components/AsyncAceEditor';
import useQueryEditor from 'src/SqlLab/hooks/useQueryEditor';
import { useSchemas } from 'src/hooks/apiResources';
import { useSchemas, useTables } from 'src/hooks/apiResources';
type HotKey = {
key: string;
@@ -96,11 +96,19 @@ const AceEditorWrapper = ({
'dbId',
'sql',
'functionNames',
'tableOptions',
'validationResult',
'schema',
]);
const { data: schemaOptions } = useSchemas({ dbId: queryEditor.dbId });
const { data: schemaOptions } = useSchemas({
...(autocomplete && { dbId: queryEditor.dbId }),
});
const { data: tableData } = useTables({
...(autocomplete && {
dbId: queryEditor.dbId,
schema: queryEditor.schema,
}),
});
const currentSql = queryEditor.sql ?? '';
const functionNames = queryEditor.functionNames ?? [];
@@ -117,7 +125,7 @@ const AceEditorWrapper = ({
}),
[schemaOptions],
);
const tables = queryEditor.tableOptions ?? [];
const tables = tableData?.options ?? [];
const [sql, setSql] = useState(currentSql);
const [words, setWords] = useState<AceCompleterKeyword[]>([]);

View File

@@ -80,7 +80,6 @@ const SaveQuery = ({
'schema',
'selectedText',
'sql',
'tableOptions',
'templateParams',
]);
const query = useMemo(

View File

@@ -35,7 +35,6 @@ import {
collapseTable,
expandTable,
queryEditorSetSchema,
queryEditorSetTableOptions,
setDatabases,
addDangerToast,
resetState,
@@ -218,15 +217,6 @@ const SqlEditorLeftBar = ({
[dispatch, queryEditor],
);
const handleTablesLoad = useCallback(
(options: Array<any>) => {
if (queryEditor) {
dispatch(queryEditorSetTableOptions(queryEditor, options));
}
},
[dispatch, queryEditor],
);
const handleDbList = useCallback(
(result: DatabaseObject) => {
dispatch(setDatabases(result));
@@ -256,7 +246,6 @@ const SqlEditorLeftBar = ({
onDbChange={onDbChange}
onSchemaChange={handleSchemaChange}
onTableSelectChange={onTablesChange}
onTablesLoad={handleTablesLoad}
schema={schema}
tableValue={selectedTableNames}
sqlLabMode