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(db-connection-ui): Allow users to pick engine #14884

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import React, {
Reducer,
} from 'react';
import Tabs from 'src/components/Tabs';
import { Alert } from 'src/common/components';
import { Alert, Select } from 'src/common/components';
import Modal from 'src/components/Modal';
import Button from 'src/components/Button';
import withToasts from 'src/messageToasts/enhancers/withToasts';
Expand Down Expand Up @@ -59,6 +59,7 @@ import {
formHelperStyles,
formStyles,
StyledBasicTab,
SelectDatabaseStyles,
} from './styles';

const DOCUMENTATION_LINK =
Expand Down Expand Up @@ -119,7 +120,7 @@ type DBReducerActionType =
| {
type: ActionType.configMethodChange;
payload: { configuration_method: CONFIGURATION_METHOD };
};
}

function dbReducer(
state: Partial<DatabaseObject> | null,
Expand Down Expand Up @@ -166,13 +167,16 @@ function dbReducer(
...action.payload,
};
case ActionType.dbSelected:
return {
...action.payload,
};
case ActionType.configMethodChange:
return {
...action.payload,
};
case ActionType.reset:
default:
return {};
return null;
}
}

Expand All @@ -195,6 +199,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const [validationErrors, getValidation] = useDatabaseValidation();
const [hasConnectedDb, setHasConnectedDb] = useState<boolean>(false);
const [dbName, setDbName] = useState('');
const [isLoading, setLoading] = useState<boolean>(false);
const conf = useCommonConf();

const isEditMode = !!databaseId;
Expand Down Expand Up @@ -298,12 +303,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
if (show) {
setTabKey(DEFAULT_TAB_KEY);
getAvailableDbs();
setDB({
type: ActionType.dbSelected,
payload: {
configuration_method: CONFIGURATION_METHOD.SQLALCHEMY_URI,
}, // todo hook this up to step 1
});
setLoading(true);
}
if (databaseId && show) {
fetchDB();
Expand All @@ -322,6 +322,12 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
}
}, [dbFetched]);

useEffect(() => {
if (isLoading) {
setLoading(false);
}
}, [availableDbs, isLoading]);

const tabChange = (key: string) => {
setTabKey(key);
};
Expand Down Expand Up @@ -518,6 +524,31 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
getValidation={() => getValidation(db)}
validationErrors={validationErrors}
/>
{!isLoading && !db && (
<SelectDatabaseStyles>
<label className="label-select">
What database would you like to connect?
</label>
<Select
style={{ width: '100%' }}
onChange={option => {
setDB({
type: ActionType.dbSelected,
payload: {
configuration_method: CONFIGURATION_METHOD.DYNAMIC_FORM,
engine: option,
},
});
}}
>
{availableDbs?.databases?.map(database => (
<Select.Option value={database.engine} key={database.engine}>
{database.name}
</Select.Option>
))}
</Select>
</SelectDatabaseStyles>
)}
<Button
buttonStyle="link"
onClick={() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,7 @@ export const EditHeaderSubtitle = styled.div`
font-size: ${({ theme }) => theme.typography.sizes.l}px;
font-weight: bold;
`;

export const SelectDatabaseStyles = styled.div`
margin: ${({ theme }) => theme.gridUnit * 4}px;
`;