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

feat: add prop to setDBEngine in DatabaseModal #18653

Merged
merged 8 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -1016,4 +1016,24 @@ describe('DatabaseModal', () => {
});
});
});
describe('DatabaseModal w/ Deeplinking Engine', () => {
const renderAndWait = async () => {
const mounted = act(async () => {
render(<DatabaseModal {...dbProps} setDBEngine={'PostgreSQL'} />, {
hughhhh marked this conversation as resolved.
Show resolved Hide resolved
useRedux: true,
});
});

return mounted;
};

beforeEach(async () => {
await renderAndWait();
});

it('enters step 2 of 3 when proper database is selected', () => {
const step2of3text = screen.getByText(/step 2 of 3/i);
expect(step2of3text).toBeVisible();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ interface DatabaseModalProps {
onHide: () => void;
show: boolean;
databaseId: number | undefined; // If included, will go into edit mode
setDBEngine: string | undefined; // if included goto step 2 with engine already set
}

enum ActionType {
Expand Down Expand Up @@ -428,6 +429,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
onHide,
show,
databaseId,
setDBEngine,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this property name is optimal because it sounds a bit like an operation instead of a React-style declarative declaration. Can we delete set part of that name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with this 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, this sounds mode like a hook for setting state than a value.

}) => {
const [db, setDB] = useReducer<
Reducer<Partial<DatabaseObject> | null, DBReducerActionType>
Expand Down Expand Up @@ -656,6 +658,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
},
});
} else {
console.log(availableDbs);
hughhhh marked this conversation as resolved.
Show resolved Hide resolved
const selectedDbModel = availableDbs?.databases.filter(
(db: DatabaseObject) => db.name === database_name,
)[0];
Expand Down Expand Up @@ -850,6 +853,11 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
if (isLoading) {
setLoading(false);
}

if (availableDbs && setDBEngine) {
// set model if passed into props
setDatabaseModel(setDBEngine);
}
}, [availableDbs]);

const tabChange = (key: string) => {
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/views/components/MenuRight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
import LanguagePicker from './LanguagePicker';
import { NavBarProps, MenuObjectProps } from './Menu';

import DatabaseModal from '../CRUD/data/database/DatabaseModal';

export const dropdownItems = [
{
label: t('SQL query'),
Expand Down