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

chore: Add tooltips and button to Connect Postgresql DB Modal Form #15179

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bf0131e
Added tooltips. Still need to place in the right spot.
Jun 15, 2021
69682a9
Revert to where I started.
Jun 15, 2021
8f9475b
Merge remote-tracking branch 'upstream/pexdax/db-connection-ui' into …
andrewbastian Jun 15, 2021
dbf8770
Added 3 tooltips, 1 Button(need link config). BigQuery not added yet.
andrewbastian Jun 15, 2021
e590bfc
Merge branch 'pexdax/db-connection-ui' of https://github.com//apache/…
andrewbastian Jun 16, 2021
fa6c2c5
Added tooltip BigOuery modal. `span` above upload btn missing `*`
andrewbastian Jun 16, 2021
23178d4
Merge branch 'pexdax/db-connection-ui' of https://github.com//apache/…
andrewbastian Jun 17, 2021
aea5905
Added tooltip to `Host` field. Alignment needs to be fixed.
andrewbastian Jun 17, 2021
9a2216d
Merge branch 'pexdax/db-connection-ui' of https://github.com//apache/…
andrewbastian Jun 17, 2021
2622bfe
Stuck trying to add conditional render of tooltip to LabeledErrorBoun…
andrewbastian Jun 17, 2021
b73b40b
Clean commit for review
andrewbastian Jun 18, 2021
a4654a3
Dynamic tooltip componet created. Needs alignment of SVG still.
andrewbastian Jun 18, 2021
8d364cc
Merge branch 'pexdax/db-connection-ui' of https://github.com//apache/…
andrewbastian Jun 18, 2021
c1325ab
Fixed typo.
andrewbastian Jun 18, 2021
46ebb23
Added line spacing back in
andrewbastian Jun 18, 2021
c8bbce0
Changed required props to optional/Remove comment
andrewbastian Jun 18, 2021
49bafb3
Fixed alignment of tooltips & moved 2tooltips outside of Btn
andrewbastian Jun 18, 2021
6da403e
Merge branch 'pexdax/db-connection-ui' of https://github.com//apache/…
andrewbastian Jun 18, 2021
34d56a1
Added one more line space back in
andrewbastian Jun 18, 2021
c103c02
Removed Typo
andrewbastian Jun 18, 2021
23b5a1d
Removed another typo
andrewbastian Jun 18, 2021
2cdf91a
Flixed linter error
andrewbastian Jun 18, 2021
4a39740
Created test for tooltip.
andrewbastian Jun 18, 2021
b0de82a
Added expectation for visible tooltipIcon
andrewbastian Jun 18, 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 @@ -32,6 +32,7 @@ export const InteractiveLabeledErrorBoundInput = ({
placeholder,
type,
id,
tooltipText,
}: LabeledErrorBoundInputProps) => {
const [currentValue, setCurrentValue] = useState(value);

Expand All @@ -58,6 +59,8 @@ export const InteractiveLabeledErrorBoundInput = ({
placeholder={placeholder}
type={type}
required
hasTooltip
tooltipText={tooltipText}
/>
);
};
Expand All @@ -66,6 +69,7 @@ InteractiveLabeledErrorBoundInput.args = {
name: 'Username',
placeholder: 'Example placeholder text...',
id: 1,
tooltipText: 'This is a tooltip',
};

InteractiveLabeledErrorBoundInput.argTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import { render, fireEvent, screen } from 'spec/helpers/testing-library';
import LabeledErrorBoundInput from 'src/components/Form/LabeledErrorBoundInput';

const defaultProps = {
Expand All @@ -27,6 +27,8 @@ const defaultProps = {
validationMethods: () => {},
errorMessage: '',
helpText: 'This is a line of example help text',
hasTooltip: false,
tooltipText: 'This is a tooltip',
value: '',
placeholder: 'Example placeholder text...',
type: 'textbox',
Expand Down Expand Up @@ -58,4 +60,19 @@ describe('LabeledErrorBoundInput', () => {
expect(textboxInput).toBeVisible();
expect(errorText).toBeVisible();
});
it('renders a LabledErrorBoundInput with a InfoTooltip', async () => {
defaultProps.hasTooltip = true;
render(<LabeledErrorBoundInput {...defaultProps} />);

const label = screen.getByText(/username/i);
const textboxInput = screen.getByRole('textbox');
const tooltipIcon = screen.getByTestId('info-solid-small');

fireEvent.mouseOver(tooltipIcon);

expect(tooltipIcon).toBeVisible();
expect(label).toBeVisible();
expect(textboxInput).toBeVisible();
expect(await screen.findByText('This is a tooltip')).toBeInTheDocument();
});
});
22 changes: 21 additions & 1 deletion superset-frontend/src/components/Form/LabeledErrorBoundInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import React from 'react';
import { Input } from 'antd';
import { styled, css, SupersetTheme } from '@superset-ui/core';
import InfoTooltip from 'src/components/InfoTooltip';
import FormItem from './FormItem';
import FormLabel from './FormLabel';

andrewbastian marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -30,6 +31,8 @@ export interface LabeledErrorBoundInputProps {
errorMessage: string | null;
helpText?: string;
required?: boolean;
hasTooltip?: boolean;
tooltipText?: string | null;
id?: string;
classname?: string;
[x: string]: any;
Expand Down Expand Up @@ -61,6 +64,7 @@ const alertIconStyles = (theme: SupersetTheme, hasError: boolean) => css`
}
}`}
`;

const StyledFormGroup = styled('div')`
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
Expand All @@ -73,20 +77,36 @@ const StyledFormGroup = styled('div')`
}
`;

const infoTooltip = (theme: SupersetTheme) => css`
svg {
vertical-align: bottom;
margin-bottom: ${theme.gridUnit * 0.25}px;
}
`;

const LabeledErrorBoundInput = ({
label,
validationMethods,
errorMessage,
helpText,
required = false,
hasTooltip = false,
tooltipText,
id,
className,
...props
}: LabeledErrorBoundInputProps) => (
<StyledFormGroup className={className}>
<FormLabel htmlFor={id} required={required}>
<FormLabel
htmlFor={id}
required={required}
css={(theme: SupersetTheme) => infoTooltip(theme)}
>
{label}
</FormLabel>
{hasTooltip && (
<InfoTooltip tooltip={`${tooltipText}`} viewBox="0 -6 24 24" />
)}
<FormItem
css={(theme: SupersetTheme) => alertIconStyles(theme, !!errorMessage)}
validateTrigger={Object.keys(validationMethods)}
Expand Down
5 changes: 3 additions & 2 deletions superset-frontend/src/components/InfoTooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export interface InfoTooltipProps {
trigger?: string | Array<string>;
overlayStyle?: any;
bgColor?: string;
viewBox?: string;
}

const StyledTooltip = styled(Tooltip)`
cursor: pointer;

path:first-of-type {
fill: #999999;
}
Expand All @@ -65,6 +65,7 @@ export default function InfoTooltip({
trigger = 'hover',
overlayStyle = defaultOverlayStyle,
bgColor = defaultColor,
viewBox,
}: InfoTooltipProps) {
return (
<StyledTooltip
Expand All @@ -74,7 +75,7 @@ export default function InfoTooltip({
overlayStyle={overlayStyle}
color={bgColor}
>
<Icon name="info-solid-small" />
<Icon name="info-solid-small" viewBox={viewBox} />
</StyledTooltip>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export const FormFieldOrder = [

interface FieldPropTypes {
required: boolean;
hasTooltip?: boolean;
tooltipText?: (valuse: any) => string;
onParametersChange: (value: any) => string;
onParametersUploadFileChange: (value: any) => string;
changeMethods: { onParametersChange: (value: any) => string } & {
Expand Down Expand Up @@ -107,8 +109,22 @@ const CredentialsInfo = ({ changeMethods, isEditMode, db }: FieldPropTypes) => {
</span>
</div>
) : (
<div className="input-container">
<span className="label-select">Upload Credentials</span>
<div
className="input-container"
css={(theme: SupersetTheme) => infoTooltip(theme)}
>
<span
css={{ display: 'flex', alignItems: 'center' }}
className="label-select"
>
Upload Credentials{' '}
<InfoTooltip
tooltip={t(
'Use the JSON file you automatically downloaded when creating your service account in Google BigQuery.',
)}
/>
</span>

{!fileToUpload && (
<Button
className="input-upload-btn"
Expand Down Expand Up @@ -175,6 +191,10 @@ const hostField = ({
name="host"
value={db?.parameters?.host}
required={required}
hasTooltip
tooltipText={t(
'This can be either an IP address (e.g. 127.0.0.1) or a domain name (e.g. mydatabase.com).',
)}
validationMethods={{ onBlur: getValidation }}
errorMessage={validationErrors?.host}
placeholder="e.g. 127.0.0.1"
Expand Down Expand Up @@ -328,8 +348,8 @@ const forceSSLField = ({
/>
<span css={toggleStyle}>SSL</span>
<InfoTooltip
tooltip={t('SSL will be enabled in the database connection')}
placement="bottomRight"
tooltip={t('SSL Mode "require" will be used.')}
placement="right"
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ 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 InfoTooltip from 'src/components/InfoTooltip';
import withToasts from 'src/messageToasts/enhancers/withToasts';
import {
testDatabaseConnection,
Expand Down Expand Up @@ -65,6 +66,7 @@ import {
formStyles,
StyledBasicTab,
SelectDatabaseStyles,
infoTooltip,
StyledFooterButton,
StyledStickyHeader,
} from './styles';
Expand Down Expand Up @@ -678,22 +680,31 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
isEditMode={isEditMode}
/>
{isDynamic(db?.backend || db?.engine) && (
<Button
buttonStyle="link"
onClick={() =>
setDB({
type: ActionType.configMethodChange,
payload: {
database_name: db?.database_name,
configuration_method: CONFIGURATION_METHOD.DYNAMIC_FORM,
engine: db?.engine,
},
})
}
css={theme => alchemyButtonLinkStyles(theme)}
>
Connect this database using the dynamic form instead
</Button>
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
<Button
buttonStyle="link"
onClick={() =>
setDB({
type: ActionType.configMethodChange,
payload: {
database_name: db?.database_name,
configuration_method:
CONFIGURATION_METHOD.DYNAMIC_FORM,
engine: db?.engine,
},
})
}
css={theme => alchemyButtonLinkStyles(theme)}
>
Connect this database using the dynamic form instead
</Button>
<InfoTooltip
tooltip={t(
'Click this link to switch to an alternate form that exposes only the required fields needed to connect this database.',
)}
viewBox="0 -3 24 24"
/>
</div>
)}
</>
) : (
Expand Down Expand Up @@ -904,24 +915,31 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
getValidation={() => getValidation(db)}
validationErrors={validationErrors}
/>

<Button
buttonStyle="link"
onClick={() =>
setDB({
type: ActionType.configMethodChange,
payload: {
engine: db.engine,
configuration_method:
CONFIGURATION_METHOD.SQLALCHEMY_URI,
database_name: db.database_name,
},
})
}
css={buttonLinkStyles}
>
Connect this database with a SQLAlchemy URI string instead
</Button>
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
<Button
buttonStyle="link"
onClick={() =>
setDB({
type: ActionType.configMethodChange,
payload: {
engine: db.engine,
configuration_method:
CONFIGURATION_METHOD.SQLALCHEMY_URI,
database_name: db.database_name,
},
})
}
css={buttonLinkStyles}
>
Connect this database with a SQLAlchemy URI string instead
</Button>
<InfoTooltip
tooltip={t(
'Click this link to switch to an alternate form that allows you to input the SQLAlchemy URL for this database manually.',
)}
viewBox="6 3 24 24"
/>
</div>
{/* Step 2 */}
</>
))}
Expand Down