Skip to content

Commit

Permalink
reset active tab on open (#12048)
Browse files Browse the repository at this point in the history
  • Loading branch information
riahk authored Dec 16, 2020
1 parent 69185ee commit 8d29381
Showing 1 changed file with 14 additions and 1 deletion.
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

0 comments on commit 8d29381

Please sign in to comment.