-
Notifications
You must be signed in to change notification settings - Fork 18.2k
feat(db-connection-ui): Show Preferred DBs #14951
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
Merged
hughhhh
merged 29 commits into
pexdax/db-connection-ui
from
pexdax/db-connection-ui-show-preferred
Jun 4, 2021
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
6d0c45f
Creating IconButton
lyndsiWilliams b0cdaba
Changed naming: logo is now icon
lyndsiWilliams 8d96434
Hard-coded inset values for ellipses
lyndsiWilliams 3eea36d
Removed default SVG
lyndsiWilliams b0ab2da
Fixed test
lyndsiWilliams c8b148e
Removed logo from test
lyndsiWilliams e7f0dbb
split db modal file
eschutho b57d090
hook up available databases
eschutho 271c6e9
use new validation component
eschutho ef63e3c
feat(db-connection-ui): Allow users to pick engine (#14884)
hughhhh 8907bc1
Merge branch 'lyndsi/create-icon-button' of https://github.com/preset…
hughhhh 96a87d8
saving for now
hughhhh 717c9ab
update styles
hughhhh e299bfa
save
hughhhh 8cfa0d8
create 1 function for setting the DB
hughhhh 7c610d5
add function to preferred section
hughhhh dcf8144
small refactor and added styling
hughhhh ef23e53
add new footer buttons
hughhhh 2602827
add finsh buttong
hughhhh 530150e
refactor db modal render
hughhhh 508a6b9
fix comments issue
hughhhh 607e01a
add header
hughhhh b343ca4
add bottom footer to sqlalchemy form
hughhhh 0df0cab
add back headers
hughhhh 0d3c31d
fix merge conflicts
hughhhh c21987f
add step
hughhhh 9d2b36e
address comments
hughhhh 6c9fc9c
fix merge conflicts
hughhhh 4aa2428
oops
hughhhh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import Tabs from 'src/components/Tabs'; | |
| import { Alert, Select } from 'src/common/components'; | ||
| import Modal from 'src/components/Modal'; | ||
| import Button from 'src/components/Button'; | ||
| import IconButton from 'src/components/IconButton'; | ||
| import withToasts from 'src/messageToasts/enhancers/withToasts'; | ||
| import { | ||
| testDatabaseConnection, | ||
|
|
@@ -61,6 +62,7 @@ import { | |
| formStyles, | ||
| StyledBasicTab, | ||
| SelectDatabaseStyles, | ||
| StyledFormHeader, | ||
| } from './styles'; | ||
|
|
||
| const DOCUMENTATION_LINK = | ||
|
|
@@ -290,6 +292,76 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ | |
| } | ||
| }; | ||
|
|
||
| const setDatabaseModel = engine => { | ||
| const isDynamic = | ||
| availableDbs?.databases.filter(db => db.engine === engine)[0] | ||
| .parameters !== undefined; | ||
| setDB({ | ||
| type: ActionType.dbSelected, | ||
| payload: { | ||
| configuration_method: isDynamic | ||
| ? CONFIGURATION_METHOD.DYNAMIC_FORM | ||
| : CONFIGURATION_METHOD.SQLALCHEMY_URI, | ||
| engine, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| const renderAvailableSelector = () => ( | ||
| <div className="available"> | ||
| <span className="available-label"> | ||
| Or choose from a list of other databases we support{' '} | ||
| </span> | ||
| <label className="label-available-select">supported databases</label> | ||
| <Select | ||
| style={{ width: '100%' }} | ||
| onChange={setDatabaseModel} | ||
| placeholder="Choose a database..." | ||
| > | ||
| {availableDbs?.databases?.map(database => ( | ||
| <Select.Option value={database.engine} key={database.engine}> | ||
| {database.name} | ||
| </Select.Option> | ||
| ))} | ||
| </Select> | ||
| </div> | ||
| ); | ||
|
|
||
| const renderPreferredSelector = () => ( | ||
| <div className="preferred"> | ||
| {availableDbs?.databases | ||
| ?.filter(db => db.preferred) | ||
| .map(database => ( | ||
| <IconButton | ||
| className="preferred-item" | ||
| onClick={() => setDatabaseModel(database.engine)} | ||
| buttonText={database.name} | ||
| /> | ||
| ))} | ||
| </div> | ||
| ); | ||
|
|
||
| const renderModalFooter = () => | ||
| db // if db show back + connect | ||
| ? [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. db && ( would that work instead? |
||
| <Button | ||
| key="back" | ||
| onClick={() => { | ||
| setDB({ type: ActionType.reset }); | ||
| }} | ||
| > | ||
| Back | ||
| </Button>, | ||
| !hasConnectedDb ? ( // if hasConnectedDb show back + finish | ||
| <Button key="submit" type="primary" onClick={onSave}> | ||
| Connect | ||
| </Button> | ||
| ) : ( | ||
| <Button onClick={onClose}>Finish</Button> | ||
| ), | ||
| ] | ||
| : []; | ||
|
|
||
| useEffect(() => { | ||
| if (show) { | ||
| setTabKey(DEFAULT_TAB_KEY); | ||
|
|
@@ -359,15 +431,18 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ | |
| title={ | ||
| <h4>{isEditMode ? t('Edit database') : t('Connect a database')}</h4> | ||
| } | ||
| footer={renderModalFooter()} | ||
| > | ||
| {isEditMode ? ( | ||
| {isEditMode && ( | ||
| <TabHeader> | ||
| <EditHeaderTitle>{db?.backend}</EditHeaderTitle> | ||
| <EditHeaderSubtitle>{dbName}</EditHeaderSubtitle> | ||
| </TabHeader> | ||
| ) : ( | ||
| // TODO: Fix headers when we get rid of tabs | ||
| )} | ||
| {/* Show Legacy Header */} | ||
| {useSqlAlchemyForm && ( | ||
| <TabHeader> | ||
| <p className="helper"> Step 2 of 2 </p> | ||
| <CreateHeaderTitle>Enter Primary Credentials</CreateHeaderTitle> | ||
| <CreateHeaderSubtitle> | ||
| Need help? Learn how to connect your database{' '} | ||
|
|
@@ -382,6 +457,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ | |
| </CreateHeaderSubtitle> | ||
| </TabHeader> | ||
| )} | ||
| {/* Add styled header here when not in edit mode */} | ||
| <hr /> | ||
| <Tabs | ||
| defaultActiveKey={DEFAULT_TAB_KEY} | ||
|
|
@@ -492,6 +568,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ | |
| width="500px" | ||
| show={show} | ||
| title={<h4>{t('Connect a database')}</h4>} | ||
| footer={renderModalFooter()} | ||
| > | ||
| {hasConnectedDb ? ( | ||
| <ExtraOptions | ||
|
|
@@ -516,65 +593,65 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({ | |
| /> | ||
| ) : ( | ||
| <> | ||
| <DatabaseConnectionForm | ||
| db={db} | ||
| dbModel={dbModel} | ||
| onParametersChange={({ target }: { target: HTMLInputElement }) => | ||
| onChange(ActionType.parametersChange, { | ||
| type: target.type, | ||
| name: target.name, | ||
| checked: target.checked, | ||
| value: target.value, | ||
| }) | ||
| } | ||
| onChange={({ target }: { target: HTMLInputElement }) => | ||
| onChange(ActionType.textChange, { | ||
| name: target.name, | ||
| value: target.value, | ||
| }) | ||
| } | ||
| getValidation={() => getValidation(db)} | ||
| validationErrors={validationErrors} | ||
| /> | ||
| {/* Step 1 */} | ||
| {!isLoading && !db && ( | ||
| <SelectDatabaseStyles> | ||
| <Label className="label-select"> | ||
| What database would you like to connect? | ||
| </Label> | ||
| <Select | ||
| style={{ width: '100%' }} | ||
| onChange={(option: string) => { | ||
| <StyledFormHeader> | ||
| <div className="select-db"> | ||
| <p className="helper"> Step 1 of 3 </p> | ||
| <h4>Select a database to connect</h4> | ||
| </div> | ||
| </StyledFormHeader> | ||
| {renderPreferredSelector()} | ||
| {renderAvailableSelector()} | ||
| </SelectDatabaseStyles> | ||
| )} | ||
| {/* Step 1 */} | ||
|
|
||
| {/* Step 2 */} | ||
| {!isLoading && db && ( | ||
| <> | ||
| <DatabaseConnectionForm | ||
| dbModel={dbModel} | ||
| onParametersChange={({ | ||
| target, | ||
| }: { | ||
| target: HTMLInputElement; | ||
| }) => | ||
| onChange(ActionType.parametersChange, { | ||
| type: target.type, | ||
| name: target.name, | ||
| checked: target.checked, | ||
| value: target.value, | ||
| }) | ||
| } | ||
| onChange={({ target }: { target: HTMLInputElement }) => | ||
| onChange(ActionType.textChange, { | ||
| name: target.name, | ||
| value: target.value, | ||
| }) | ||
| } | ||
| getValidation={() => getValidation(db)} | ||
| validationErrors={validationErrors} | ||
| /> | ||
|
|
||
| <Button | ||
| buttonStyle="link" | ||
| onClick={() => | ||
| setDB({ | ||
| type: ActionType.dbSelected, | ||
| type: ActionType.configMethodChange, | ||
| payload: { | ||
| configuration_method: CONFIGURATION_METHOD.DYNAMIC_FORM, | ||
| engine: option, | ||
| configuration_method: CONFIGURATION_METHOD.SQLALCHEMY_URI, | ||
| }, | ||
| }); | ||
| }} | ||
| }) | ||
| } | ||
| css={buttonLinkStyles} | ||
| > | ||
| {availableDbs?.databases?.map((database: DatabaseForm) => ( | ||
| <Select.Option value={database.engine} key={database.engine}> | ||
| {database.name} | ||
| </Select.Option> | ||
| ))} | ||
| </Select> | ||
| </SelectDatabaseStyles> | ||
| Connect this database with a SQLAlchemy URI string instead | ||
| </Button> | ||
| {/* Step 2 */} | ||
| </> | ||
| )} | ||
| <Button | ||
| buttonStyle="link" | ||
| onClick={() => | ||
| setDB({ | ||
| type: ActionType.configMethodChange, | ||
| payload: { | ||
| configuration_method: CONFIGURATION_METHOD.SQLALCHEMY_URI, | ||
| }, | ||
| }) | ||
| } | ||
| css={buttonLinkStyles} | ||
| > | ||
| Connect this database with a SQLAlchemy URI string instead | ||
| </Button> | ||
| </> | ||
| )} | ||
| </Modal> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1075,10 +1075,10 @@ def CSV_TO_HIVE_UPLOAD_DIRECTORY_FUNC( | |
| # use the "engine_name" attribute of the corresponding DB engine spec | ||
| # in `superset/db_engine_specs/`. | ||
| PREFERRED_DATABASES: List[str] = [ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will remove before merging |
||
| # "PostgreSQL", | ||
| # "Presto", | ||
| # "MySQL", | ||
| # "SQLite", | ||
| "PostgreSQL", | ||
| "Presto", | ||
| "MySQL", | ||
| "SQLite", | ||
| # etc. | ||
| ] | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move step one into a separate file?