Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: database add/edit modal: reset active tab on open #12048

Merged
merged 1 commit into from
Dec 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ interface DatabaseModalProps {
database?: DatabaseObject | null; // If included, will go into edit mode
}

const DEFAULT_TAB_KEY = '1';

const StyledIcon = styled(Icon)`
margin: auto ${({ theme }) => theme.gridUnit * 2}px auto 0;
`;
Expand Down Expand Up @@ -129,6 +131,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const [disableSave, setDisableSave] = useState<boolean>(true);
const [db, setDB] = useState<DatabaseObject | null>(null);
const [isHidden, setIsHidden] = useState<boolean>(true);
const [tabKey, setTabKey] = useState<string>(DEFAULT_TAB_KEY);

const isEditMode = database !== null;
const defaultExtra =
Expand Down Expand Up @@ -291,12 +294,14 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
) {
if (database && database.id !== null && !dbLoading) {
const id = database.id || 0;
setTabKey(DEFAULT_TAB_KEY);

fetchResource(id).then(() => {
setDB(dbFetched);
});
}
} else if (!isEditMode && (!db || db.id || (isHidden && show))) {
setTabKey(DEFAULT_TAB_KEY);
setDB({
database_name: '',
sqlalchemy_uri: '',
Expand All @@ -313,6 +318,10 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
setIsHidden(false);
}

const tabChange = (key: string) => {
setTabKey(key);
};

return (
<Modal
name="database"
Expand All @@ -330,7 +339,11 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
</h4>
}
>
<Tabs defaultActiveKey="1">
<Tabs
defaultActiveKey={DEFAULT_TAB_KEY}
activeKey={tabKey}
onTabClick={tabChange}
>
<Tabs.TabPane
tab={
<span>
Expand Down