mirror of
https://github.com/apache/superset.git
synced 2026-05-06 16:34:32 +00:00
fix: clear modal state after adding dataset (#17044)
* fix: clear modal state after adding dataset * Fix test * Small fixes
This commit is contained in:
@@ -26,7 +26,12 @@ import TableSelector from '.';
|
||||
const SupersetClientGet = jest.spyOn(SupersetClient, 'get');
|
||||
|
||||
const createProps = () => ({
|
||||
dbId: 1,
|
||||
database: {
|
||||
id: 1,
|
||||
database_name: 'main',
|
||||
backend: 'sqlite',
|
||||
allow_multi_schema_metadata_fetch: false,
|
||||
},
|
||||
schema: 'test_schema',
|
||||
handleError: jest.fn(),
|
||||
});
|
||||
|
||||
@@ -27,7 +27,9 @@ import { styled, SupersetClient, t } from '@superset-ui/core';
|
||||
import { Select } from 'src/components';
|
||||
import { FormLabel } from 'src/components/Form';
|
||||
import Icons from 'src/components/Icons';
|
||||
import DatabaseSelector from 'src/components/DatabaseSelector';
|
||||
import DatabaseSelector, {
|
||||
DatabaseObject,
|
||||
} from 'src/components/DatabaseSelector';
|
||||
import RefreshLabel from 'src/components/RefreshLabel';
|
||||
import CertifiedIcon from 'src/components/CertifiedIcon';
|
||||
import WarningIconWithTooltip from 'src/components/WarningIconWithTooltip';
|
||||
@@ -76,22 +78,12 @@ const TableLabel = styled.span`
|
||||
|
||||
interface TableSelectorProps {
|
||||
clearable?: boolean;
|
||||
database?: {
|
||||
id: number;
|
||||
database_name: string;
|
||||
backend: string;
|
||||
allow_multi_schema_metadata_fetch: boolean;
|
||||
};
|
||||
dbId: number;
|
||||
database?: DatabaseObject;
|
||||
formMode?: boolean;
|
||||
getDbList?: (arg0: any) => {};
|
||||
handleError: (msg: string) => void;
|
||||
isDatabaseSelectEnabled?: boolean;
|
||||
onDbChange?: (db: {
|
||||
id: number;
|
||||
database_name: string;
|
||||
backend: string;
|
||||
}) => void;
|
||||
onDbChange?: (db: DatabaseObject) => void;
|
||||
onSchemaChange?: (schema?: string) => void;
|
||||
onSchemasLoad?: () => void;
|
||||
onTableChange?: (tableName?: string, schema?: string) => void;
|
||||
@@ -150,7 +142,6 @@ const TableOption = ({ table }: { table: Table }) => {
|
||||
|
||||
const TableSelector: FunctionComponent<TableSelectorProps> = ({
|
||||
database,
|
||||
dbId,
|
||||
formMode = false,
|
||||
getDbList,
|
||||
handleError,
|
||||
@@ -165,7 +156,9 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
|
||||
sqlLabMode = true,
|
||||
tableName,
|
||||
}) => {
|
||||
const [currentDbId, setCurrentDbId] = useState<number | undefined>(dbId);
|
||||
const [currentDatabase, setCurrentDatabase] = useState<
|
||||
DatabaseObject | undefined
|
||||
>(database);
|
||||
const [currentSchema, setCurrentSchema] = useState<string | undefined>(
|
||||
schema,
|
||||
);
|
||||
@@ -176,13 +169,22 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
|
||||
const [tableOptions, setTableOptions] = useState<TableOption[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (currentDbId && currentSchema) {
|
||||
// reset selections
|
||||
if (database === undefined) {
|
||||
setCurrentDatabase(undefined);
|
||||
setCurrentSchema(undefined);
|
||||
setCurrentTable(undefined);
|
||||
}
|
||||
}, [database]);
|
||||
|
||||
useEffect(() => {
|
||||
if (currentDatabase && currentSchema) {
|
||||
setLoadingTables(true);
|
||||
const encodedSchema = encodeURIComponent(currentSchema);
|
||||
const forceRefresh = refresh !== previousRefresh;
|
||||
// TODO: Would be nice to add pagination in a follow-up. Needs endpoint changes.
|
||||
const endpoint = encodeURI(
|
||||
`/superset/tables/${currentDbId}/${encodedSchema}/undefined/${forceRefresh}/`,
|
||||
`/superset/tables/${currentDatabase.id}/${encodedSchema}/undefined/${forceRefresh}/`,
|
||||
);
|
||||
|
||||
if (previousRefresh !== refresh) {
|
||||
@@ -223,7 +225,7 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
|
||||
// We are using the refresh state to re-trigger the query
|
||||
// previousRefresh should be out of dependencies array
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [currentDbId, currentSchema, onTablesLoad, refresh]);
|
||||
}, [currentDatabase, currentSchema, onTablesLoad, refresh]);
|
||||
|
||||
function renderSelectRow(select: ReactNode, refreshBtn: ReactNode) {
|
||||
return (
|
||||
@@ -241,12 +243,8 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
const internalDbChange = (db: {
|
||||
id: number;
|
||||
database_name: string;
|
||||
backend: string;
|
||||
}) => {
|
||||
setCurrentDbId(db?.id);
|
||||
const internalDbChange = (db: DatabaseObject) => {
|
||||
setCurrentDatabase(db);
|
||||
if (onDbChange) {
|
||||
onDbChange(db);
|
||||
}
|
||||
@@ -263,7 +261,8 @@ const TableSelector: FunctionComponent<TableSelectorProps> = ({
|
||||
function renderDatabaseSelector() {
|
||||
return (
|
||||
<DatabaseSelector
|
||||
db={database}
|
||||
key={currentDatabase?.id}
|
||||
db={currentDatabase}
|
||||
formMode={formMode}
|
||||
getDbList={getDbList}
|
||||
handleError={handleError}
|
||||
|
||||
Reference in New Issue
Block a user