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 Back button to extra options #15300

Merged
merged 22 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dbbf58c
fix: add icons (#15122)
AAfghahi Jun 11, 2021
e5b66dc
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 11, 2021
03d3326
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 15, 2021
5cfe664
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 15, 2021
7a7f39b
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 16, 2021
54965a1
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 16, 2021
9a2a58e
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 16, 2021
be0408b
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 16, 2021
be5ea73
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 16, 2021
a7425e4
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 16, 2021
8a8998e
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 17, 2021
fc31ea2
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 17, 2021
8a4ff62
spinner
AAfghahi Jun 17, 2021
34e8de1
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 17, 2021
cd6744f
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 17, 2021
4a0eefa
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 17, 2021
de00e6d
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 18, 2021
33764a3
Merge branch 'pexdax/db-connection-ui' of ssh://github.com/apache/sup…
AAfghahi Jun 18, 2021
8fe27f6
first draft
AAfghahi Jun 18, 2021
bddb335
working
AAfghahi Jun 19, 2021
aa22011
added back button to create modal
AAfghahi Jun 22, 2021
4ccac81
revisions and testing
AAfghahi Jun 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const ModalHeader = ({
db,
dbName,
dbModel,
editNewDb,
}: {
isLoading: boolean;
isEditMode: boolean;
Expand All @@ -58,6 +59,7 @@ const ModalHeader = ({
db: Partial<DatabaseObject> | null;
dbName: string;
dbModel: DatabaseForm;
editNewDb?: boolean;
}) => {
const isEditHeader = (
<>
Expand Down Expand Up @@ -102,7 +104,14 @@ const ModalHeader = ({
<p className="helper"> Step 2 of 3 </p>
<h4>Enter the required {dbModel.name} credentials</h4>
<p className="helper">
Need help? Learn more about connecting to {dbModel.name}.
Need help? Learn more about{' '}
<a
href={documentationLink(db?.engine)}
target="_blank"
rel="noopener noreferrer"
>
connecting to {dbModel.name}.
</a>
</p>
</StyledFormHeader>
);
Expand All @@ -122,10 +131,10 @@ const ModalHeader = ({
if (useSqlAlchemyForm) {
return useSqlAlchemyFormHeader;
}
if (hasConnectedDb) {
if (hasConnectedDb && !editNewDb) {
return hasConnectedDbHeader;
}
if (db) {
if (db || editNewDb) {
return hasDbHeader;
}
return noDbHeader;
Expand Down
158 changes: 106 additions & 52 deletions superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
] = useDatabaseValidation();
const [hasConnectedDb, setHasConnectedDb] = useState<boolean>(false);
const [dbName, setDbName] = useState('');
const [editNewDb, setEditNewDb] = useState<boolean>(false);
const [isLoading, setLoading] = useState<boolean>(false);
const conf = useCommonConf();
const dbImages = getDatabaseImages();
Expand Down Expand Up @@ -350,6 +351,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
setDB({ type: ActionType.reset });
setHasConnectedDb(false);
setValidationErrors(null); // reset validation errors on close
setEditNewDb(false);
onHide();
};

Expand Down Expand Up @@ -405,7 +407,9 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
if (onDatabaseAdd) {
onDatabaseAdd();
}
onClose();
if (!editNewDb) {
onClose();
}
}
} else if (db) {
// Create
Expand Down Expand Up @@ -438,6 +442,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
}
}
}
setEditNewDb(false);
setLoading(false);
};

Expand Down Expand Up @@ -537,10 +542,19 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
</div>
);

const renderModalFooter = () =>
db // if db show back + connect
? [
!hasConnectedDb && (
const handleBackButton = () => {
Copy link
Member

Choose a reason for hiding this comment

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

handleBackButtonOnFinish

if (dbFetched) {
fetchResource(dbFetched.id as number);
}
setEditNewDb(true);
};

const renderModalFooter = () => {
if (db) {
// if db show back + connenct
if (!hasConnectedDb || editNewDb) {
return (
<>
<StyledFooterButton
key="back"
onClick={() => {
Expand All @@ -549,26 +563,34 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
>
Back
</StyledFooterButton>
),
!hasConnectedDb ? ( // if hasConnectedDb show back + finish
<StyledFooterButton
key="submit"
buttonStyle="primary"
onClick={onSave}
>
Connect
</StyledFooterButton>
) : (
<StyledFooterButton
key="submit"
buttonStyle="primary"
onClick={onClose}
>
Finish
</StyledFooterButton>
),
]
: [];
</>
);
}

return (
<>
<StyledFooterButton key="back" onClick={handleBackButton}>
Back
</StyledFooterButton>
<StyledFooterButton
key="submit"
buttonStyle="primary"
onClick={onClose}
>
Finish
</StyledFooterButton>
</>
);
}
return [];
};

const renderEditModalFooter = () => (
<>
Expand Down Expand Up @@ -613,6 +635,68 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
setTabKey(key);
};

const renderExtraOptions = () => {
Copy link
Member

Choose a reason for hiding this comment

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

Can change the name to renderFinishState or something that extent?

if (!editNewDb) {
return (
<ExtraOptions
db={db as DatabaseObject}
onInputChange={({ target }: { target: HTMLInputElement }) =>
onChange(ActionType.inputChange, {
type: target.type,
name: target.name,
checked: target.checked,
value: target.value,
})
}
onTextChange={({ target }: { target: HTMLTextAreaElement }) =>
onChange(ActionType.textChange, {
name: target.name,
value: target.value,
})
}
onEditorChange={(payload: { name: string; json: any }) =>
onChange(ActionType.editorChange, payload)
}
onExtraInputChange={({ target }: { target: HTMLInputElement }) => {
onChange(ActionType.extraInputChange, {
type: target.type,
name: target.name,
checked: target.checked,
value: target.value,
});
}}
onExtraEditorChange={(payload: { name: string; json: any }) =>
onChange(ActionType.extraEditorChange, payload)
}
/>
);
}
return (
<DatabaseConnectionForm
isEditMode
sslForced={sslForced}
dbModel={dbModel}
db={dbFetched as DatabaseObject}
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}
/>
);
};

const isDynamic = (engine: string | undefined) =>
availableDbs?.databases.filter(
(DB: DatabaseObject) => DB.backend === engine || DB.engine === engine,
Expand Down Expand Up @@ -807,39 +891,9 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
db={db}
dbName={dbName}
dbModel={dbModel}
editNewDb={editNewDb}
/>

<ExtraOptions
db={db as DatabaseObject}
onInputChange={({ target }: { target: HTMLInputElement }) =>
onChange(ActionType.inputChange, {
type: target.type,
name: target.name,
checked: target.checked,
value: target.value,
})
}
onTextChange={({ target }: { target: HTMLTextAreaElement }) =>
onChange(ActionType.textChange, {
name: target.name,
value: target.value,
})
}
onEditorChange={(payload: { name: string; json: any }) =>
onChange(ActionType.editorChange, payload)
}
onExtraInputChange={({ target }: { target: HTMLInputElement }) => {
onChange(ActionType.extraInputChange, {
type: target.type,
name: target.name,
checked: target.checked,
value: target.value,
});
}}
onExtraEditorChange={(payload: { name: string; json: any }) =>
onChange(ActionType.extraEditorChange, payload)
}
/>
{renderExtraOptions()}
</>
) : (
<>
Expand Down Expand Up @@ -875,8 +929,8 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
css={(theme: SupersetTheme) => antDAlertStyles(theme)}
type="info"
showIcon
message={t('Whitelisting IPs')}
description={connectionAlert.WHITELISTED_IPS}
message={t('IP Allowlist')}
description={connectionAlert.ALLOWED_IPS}
/>
)}
<DatabaseConnectionForm
Expand Down
11 changes: 11 additions & 0 deletions superset/db_engine_specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,17 @@ def validate_parameters(
port = parameters.get("port", None)
if not port:
return errors
try:
port = int(port)
except (ValueError, TypeError):
errors.append(
SupersetError(
message="Port must be a valid integer",
error_type=SupersetErrorType.CONNECTION_INVALID_PORT_ERROR,
level=ErrorLevel.ERROR,
extra={"invalid": ["port"]},
),
)
if not (isinstance(port, int) and 0 <= port < 2 ** 16):
errors.append(
SupersetError(
Expand Down