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): Show Preferred DBs #14951

Merged
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6d0c45f
Creating IconButton
lyndsiWilliams May 19, 2021
b0cdaba
Changed naming: logo is now icon
lyndsiWilliams Jun 1, 2021
8d96434
Hard-coded inset values for ellipses
lyndsiWilliams Jun 1, 2021
3eea36d
Removed default SVG
lyndsiWilliams Jun 1, 2021
b0ab2da
Fixed test
lyndsiWilliams Jun 1, 2021
c8b148e
Removed logo from test
lyndsiWilliams Jun 1, 2021
e7f0dbb
split db modal file
eschutho Apr 21, 2021
b57d090
hook up available databases
eschutho Apr 28, 2021
271c6e9
use new validation component
eschutho May 21, 2021
ef63e3c
feat(db-connection-ui): Allow users to pick engine (#14884)
hughhhh Jun 1, 2021
8907bc1
Merge branch 'lyndsi/create-icon-button' of https://github.com/preset…
hughhhh Jun 1, 2021
96a87d8
saving for now
hughhhh Jun 1, 2021
717c9ab
update styles
hughhhh Jun 2, 2021
e299bfa
save
hughhhh Jun 2, 2021
8cfa0d8
create 1 function for setting the DB
hughhhh Jun 2, 2021
7c610d5
add function to preferred section
hughhhh Jun 2, 2021
dcf8144
small refactor and added styling
hughhhh Jun 2, 2021
ef23e53
add new footer buttons
hughhhh Jun 2, 2021
2602827
add finsh buttong
hughhhh Jun 2, 2021
530150e
refactor db modal render
hughhhh Jun 2, 2021
508a6b9
fix comments issue
hughhhh Jun 2, 2021
607e01a
add header
hughhhh Jun 3, 2021
b343ca4
add bottom footer to sqlalchemy form
hughhhh Jun 3, 2021
0df0cab
add back headers
hughhhh Jun 3, 2021
0d3c31d
fix merge conflicts
hughhhh Jun 3, 2021
c21987f
add step
hughhhh Jun 3, 2021
9d2b36e
address comments
hughhhh Jun 4, 2021
6c9fc9c
fix merge conflicts
hughhhh Jun 4, 2021
4aa2428
oops
hughhhh Jun 4, 2021
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
3 changes: 1 addition & 2 deletions superset-frontend/src/components/IconButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const StyledButton = styled(Button)`
display: flex;
flex-direction: column;
padding: 0;
width: 33%;
`;
const StyledImage = styled.div`
margin: ${({ theme }) => theme.gridUnit * 8}px 0;
Expand Down Expand Up @@ -76,8 +77,6 @@ const StyledInner = styled.div`
`;

const StyledBottom = styled.div`
padding: ${({ theme }) => theme.gridUnit * 6}px
${({ theme }) => theme.gridUnit * 4}px;
border-radius: 0 0 ${({ theme }) => theme.borderRadius}px
${({ theme }) => theme.borderRadius}px;
background-color: ${({ theme }) => theme.colors.grayscale.light4};
Expand Down
182 changes: 129 additions & 53 deletions superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -60,6 +61,7 @@ import {
formStyles,
StyledBasicTab,
SelectDatabaseStyles,
StyledFormHeader,
} from './styles';

const DOCUMENTATION_LINK =
Expand Down Expand Up @@ -299,6 +301,73 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
}
};

const setDatabaseModel = option => {
Copy link
Member

Choose a reason for hiding this comment

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

can the param be "engine" if it's just a string? Maybe a type on that would help, too.

const isDynamic =
availableDbs?.databases.filter(db => db.engine === option)[0]
.parameters !== undefined;
setDB({
type: ActionType.dbSelected,
payload: {
configuration_method: isDynamic
? CONFIGURATION_METHOD.DYNAMIC_FORM
: CONFIGURATION_METHOD.SQLALCHEMY_URI,
engine: option,
},
});
console.log('isDynamic', isDynamic);
Copy link
Member

Choose a reason for hiding this comment

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

nit remove

};

const renderAvailableSelector = () => (
Copy link
Member

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?

<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}>
{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
? [
Copy link
Member

Choose a reason for hiding this comment

The 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);
Expand Down Expand Up @@ -369,14 +438,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>
) : (
)}
{/* 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{' '}
Expand All @@ -391,6 +464,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
</CreateHeaderSubtitle>
</TabHeader>
)}
{/* Add styled header here when not in edit mode */}
<hr />
<Tabs
defaultActiveKey={DEFAULT_TAB_KEY}
Expand Down Expand Up @@ -481,6 +555,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
width="500px"
show={show}
title={<h4>{t('Connect a database')}</h4>}
footer={renderModalFooter()}
>
{hasConnectedDb ? (
<ExtraOptions
Expand All @@ -505,64 +580,65 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
/>
) : (
<>
<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}
/>
{/* Step 1 */}
{!isLoading && !db && (
<SelectDatabaseStyles>
<label className="label-select">
What database would you like to connect?
</label>
<Select
style={{ width: '100%' }}
onChange={option => {
<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 => (
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ export const StyledFormHeader = styled.header`
font-weight: bold;
font-size: ${({ theme }) => theme.typography.sizes.l}px;
}

.select-db {
.helper {
margin-top: 0;
}
h4 {
margin: 0 0 29px;
}
}
`;

export const antdCollapseStyles = (theme: SupersetTheme) => css`
Expand Down Expand Up @@ -313,6 +322,12 @@ export const TabHeader = styled.div`
padding: 0px;
margin: 0 ${({ theme }) => theme.gridUnit * 4}px
${({ theme }) => theme.gridUnit * 8}px;

.helper {
color: ${({ theme }) => theme.colors.grayscale.base};
font-size: ${({ theme }) => theme.typography.sizes.s - 1}px;
margin: 0px;
}
`;

export const CreateHeaderTitle = styled.div`
Expand Down Expand Up @@ -340,5 +355,30 @@ export const EditHeaderSubtitle = styled.div`
`;

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

Choose a reason for hiding this comment

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

use gridUnit


.preferred {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-bottom: 32px;
}

.preferred-item {
width: 133px;
height: 133px;
}

.available {
.available-label {
font-weight: bold;
margin-top: 32px;
margin-bottom: 16px;
}
}

.label-available-select {
text-transform: uppercase;
font-size: ${({ theme }) => theme.typography.sizes.s - 1}px;
}
`;
8 changes: 4 additions & 4 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Copy link
Member Author

Choose a reason for hiding this comment

The 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.
]

Expand Down