From abb9c0ba96a1f795964261289b16b6f21f06871e Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 4 Jan 2023 12:12:46 +0100 Subject: [PATCH] improve error indicator --- .../Builder/StreamConfigView.tsx | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/airbyte-webapp/src/components/connectorBuilder/Builder/StreamConfigView.tsx b/airbyte-webapp/src/components/connectorBuilder/Builder/StreamConfigView.tsx index c492fb24b827..db9b84340079 100644 --- a/airbyte-webapp/src/components/connectorBuilder/Builder/StreamConfigView.tsx +++ b/airbyte-webapp/src/components/connectorBuilder/Builder/StreamConfigView.tsx @@ -1,7 +1,7 @@ import { faTrashCan, faCopy } from "@fortawesome/free-regular-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import classNames from "classnames"; -import { useField } from "formik"; +import { FormikErrors, useField } from "formik"; import { useState } from "react"; import { FormattedMessage, useIntl } from "react-intl"; @@ -28,15 +28,22 @@ interface StreamConfigViewProps { } export const StreamConfigView: React.FC = ({ streamNum }) => { + const streamPath = `streams[${streamNum}]`; + const streamFieldPath = (fieldPath: string) => `${streamPath}.${fieldPath}`; + const { formatMessage } = useIntl(); - const [field, , helpers] = useField("streams"); - const [selectedTab, setSelectedTab] = useState<"configuration" | "schema">("configuration"); + const [field, meta, helpers] = useField("streams"); + const currentStreamErrors = meta.error?.[streamNum] as FormikErrors; + const hasSchemaErrors = Boolean(currentStreamErrors?.schema); + const hasConfigErrors = Boolean( + Object.keys(currentStreamErrors || {}).filter((errorKey) => errorKey !== "schema").length > 0 + ); + const [selectedTab, setSelectedTab] = useState<"configuration" | "schema">( + hasSchemaErrors && !hasConfigErrors ? "schema" : "configuration" + ); const { openConfirmationModal, closeConfirmationModal } = useConfirmationModalService(); const { setSelectedView, setTestStreamIndex } = useConnectorBuilderState(); - const streamPath = `streams[${streamNum}]`; - const streamFieldPath = (fieldPath: string) => `${streamPath}.${fieldPath}`; - const handleDelete = () => { openConfirmationModal({ text: "connectorBuilder.deleteStreamModal.text", @@ -54,9 +61,6 @@ export const StreamConfigView: React.FC = ({ streamNum }) }); }; - const [, meta] = useField(streamFieldPath("schema")); - const hasSchemaErrors = Boolean(meta.error); - return ( {/* Not using intl for the labels and tooltips in this component in order to keep maintainence simple */} @@ -66,6 +70,7 @@ export const StreamConfigView: React.FC = ({ streamNum }) label={formatMessage({ id: "connectorBuilder.streamConfiguration" })} selected={selectedTab === "configuration"} onSelect={() => setSelectedTab("configuration")} + showErrorIndicator={hasConfigErrors} />