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

🪟 🧹 Display returned error messages on replication view #16280

Merged
merged 10 commits into from
Sep 15, 2022
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
2 changes: 1 addition & 1 deletion airbyte-webapp-e2e-tests/cypress/pages/replicationPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const destinationNamespaceCustom = "div[data-testid='namespaceDefinition-customf
const destinationNamespaceSource = "div[data-testid='namespaceDefinition-source']";
const destinationNamespaceCustomInput = "input[data-testid='input']";
const syncModeDropdown = "div[data-testid='syncSettingsDropdown'] input";
const successResult = "span[data-id='success-result']";
const successResult = "div[data-id='success-result']";
const saveStreamChangesButton = "button[data-testid='resetModal-save']";
const connectionNameInput = "input[data-testid='connectionName']";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export const ConnectionForm: React.FC<ConnectionFormProps> = ({
);

const errorMessage = submitError ? generateMessageFromError(submitError) : null;
const determineErrorMessage = (isValid: boolean) => {
return errorMessage ?? (!isValid ? formatMessage({ id: "connectionForm.validation.error" }) : null);
};

return (
<Formik
Expand Down Expand Up @@ -317,7 +320,7 @@ export const ConnectionForm: React.FC<ConnectionFormProps> = ({
onCancel?.();
}}
successMessage={successMessage}
errorMessage={errorMessage || !isValid ? formatMessage({ id: "connectionForm.validation.error" }) : null}
errorMessage={determineErrorMessage(isValid)}
enableControls={canSubmitUntouchedForm}
/>
)}
Expand All @@ -336,9 +339,7 @@ export const ConnectionForm: React.FC<ConnectionFormProps> = ({
<CreateControls
isSubmitting={isSubmitting}
isValid={isValid && !editingTransformation}
errorMessage={
errorMessage || !isValid ? formatMessage({ id: "connectionForm.validation.error" }) : null
}
errorMessage={determineErrorMessage(isValid)}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@use "../../../../scss/colors";
@use "../../../../scss/variables";

.content {
display: flex;
justify-content: flex-end;
align-items: center;
flex-direction: row;
margin-top: variables.$spacing-lg;
gap: variables.$spacing-lg;
padding: variables.$spacing-sm;
}

.controlButton {
margin-left: variables.$spacing-md;
}

// currently only implemented on transformation view form card, margins are specific to that implementation
// todo: standardize the margin sizes here
.line {
min-width: 100%;
height: variables.$border-thin;
background: colors.$grey;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be $grey-100.

margin: variables.$spacing-lg -27px 0 -24px;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from "react";
import { FormattedMessage } from "react-intl";
import styled from "styled-components";

import { Button, LoadingButton } from "components";

import styles from "./EditControls.module.scss";
import { ResponseMessage } from "./ResponseMessage";

interface EditControlProps {
isSubmitting: boolean;
dirty: boolean;
Expand All @@ -15,35 +17,6 @@ interface EditControlProps {
withLine?: boolean;
}

const Buttons = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: row;
margin-top: 16px;
`;

const ControlButton = styled(LoadingButton)`
margin-left: 10px;
`;

const Success = styled.span`
color: ${({ theme }) => theme.successColor};
font-size: 14px;
line-height: 17px;
`;

const Error = styled(Success)`
color: ${({ theme }) => theme.dangerColor};
`;

const Line = styled.div`
min-width: 100%;
height: 1px;
background: ${({ theme }) => theme.greyColor20};
margin: 16px -27px 0 -24px;
`;

const EditControls: React.FC<EditControlProps> = ({
isSubmitting,
dirty,
Expand All @@ -54,34 +27,25 @@ const EditControls: React.FC<EditControlProps> = ({
enableControls,
withLine,
}) => {
const showStatusMessage = () => {
if (errorMessage) {
return <Error>{errorMessage}</Error>;
}
if (successMessage && !dirty) {
return <Success data-id="success-result">{successMessage}</Success>;
}
return null;
};

return (
<>
{withLine && <Line />}
<Buttons>
<div>{showStatusMessage()}</div>
{withLine && <div className={styles.line} />}
<div className={styles.content}>
<ResponseMessage dirty={dirty} successMessage={successMessage} errorMessage={errorMessage} />
<div>
<Button type="button" secondary disabled={isSubmitting || (!dirty && !enableControls)} onClick={resetForm}>
<FormattedMessage id="form.cancel" />
</Button>
<ControlButton
<LoadingButton
className={styles.controlButton}
type="submit"
isLoading={isSubmitting}
disabled={submitDisabled || isSubmitting || (!dirty && !enableControls)}
>
<FormattedMessage id="form.saveChanges" />
</ControlButton>
</LoadingButton>
</div>
</Buttons>
</div>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@use "../../../../scss/colors";

.message {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1;
}

.success {
color: colors.$green;
}

.error {
color: colors.$red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import classnames from "classnames";

import { Text } from "components/base/Text";

import styles from "./ResponseMessage.module.scss";

interface ResponseMessageProps {
successMessage?: React.ReactNode;
errorMessage?: React.ReactNode;
dirty: boolean;
}
export const ResponseMessage: React.FC<ResponseMessageProps> = ({ successMessage, errorMessage, dirty }) => {
const messageStyle = classnames(styles.message, {
[styles.success]: successMessage,
[styles.error]: errorMessage,
});
if (errorMessage) {
return (
<Text as="div" size="lg" className={messageStyle}>
{errorMessage}
</Text>
);
}

if (successMessage && !dirty) {
return (
<Text as="div" size="lg" className={messageStyle} data-id="success-result">
{successMessage}
</Text>
);
}
return null;
};