Skip to content
Open
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
10 changes: 6 additions & 4 deletions ui/src/modules/destinations/pages/CreateDestination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
getConnectorDocumentationPath,
handleSpecResponse,
withAbortController,
trimFormDataStrings,
} from "../../../utils/utils"
import {
CONNECTOR_TYPES,
Expand Down Expand Up @@ -405,7 +406,7 @@ const CreateDestination = forwardRef<
const handleDestinationNameChange = (
e: React.ChangeEvent<HTMLInputElement>,
) => {
const newName = e.target.value
const newName = e.target.value.trim()
if (newName.length >= 1) {
setDestinationNameError(null)
}
Expand Down Expand Up @@ -631,9 +632,10 @@ const CreateDestination = forwardRef<
widgets={widgets}
formData={formData}
onChange={e => {
setFormData(e.formData)
if (onFormDataChange) onFormDataChange(e.formData)
const catalogValue = e.formData?.writer?.catalog_type
const trimmedData = trimFormDataStrings(e.formData)
setFormData(trimmedData)
if (onFormDataChange) onFormDataChange(trimmedData)
const catalogValue = trimmedData?.writer?.catalog_type
if (catalogValue) setCatalog(catalogValue)
}}
onSubmit={handleCreate}
Expand Down
7 changes: 5 additions & 2 deletions ui/src/modules/destinations/pages/DestinationEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
getStatusLabel,
handleSpecResponse,
withAbortController,
trimFormDataStrings,
} from "../../../utils/utils"
import { getStatusIcon } from "../../../utils/statusIcons"
import {
Expand Down Expand Up @@ -595,8 +596,10 @@ const DestinationEdit: React.FC<DestinationEditProps> = ({
widgets={widgets}
formData={formData}
onChange={e => {
setFormData(e.formData)
const catalogValue = e.formData?.writer?.catalog_type
const trimmedData = trimFormDataStrings(e.formData)
setFormData(trimmedData)
if (onFormDataChange) onFormDataChange(trimmedData)
const catalogValue = trimmedData?.writer?.catalog_type
if (catalogValue) setCatalog(catalogValue)
}}
transformErrors={transformErrors}
Expand Down
8 changes: 5 additions & 3 deletions ui/src/modules/sources/pages/CreateSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getConnectorLabel,
handleSpecResponse,
withAbortController,
trimFormDataStrings,
} from "../../../utils/utils"
import {
CONNECTOR_TYPES,
Expand Down Expand Up @@ -315,7 +316,7 @@ const CreateSource = forwardRef<CreateSourceHandle, CreateSourceProps>(
}

const handleSourceNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newName = e.target.value
const newName = e.target.value.trim()
if (newName.length >= 1) {
setSourceNameError(null)
}
Expand Down Expand Up @@ -552,8 +553,9 @@ const CreateSource = forwardRef<CreateSourceHandle, CreateSourceProps>(
widgets={widgets}
formData={formData}
onChange={e => {
setFormData(e.formData)
if (onFormDataChange) onFormDataChange(e.formData)
const trimmedData = trimFormDataStrings(e.formData)
setFormData(trimmedData)
if (onFormDataChange) onFormDataChange(trimmedData)
}}
transformErrors={transformErrors}
uiSchema={uiSchema}
Expand Down
6 changes: 5 additions & 1 deletion ui/src/modules/sources/pages/SourceEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
getStatusLabel,
handleSpecResponse,
withAbortController,
trimFormDataStrings,
} from "../../../utils/utils"
import DocumentationPanel from "../../common/components/DocumentationPanel"
import StepTitle from "../../common/components/StepTitle"
Expand Down Expand Up @@ -641,7 +642,10 @@ const SourceEdit: React.FC<SourceEditProps> = ({
}}
widgets={widgets}
formData={formData}
onChange={e => setFormData(e.formData)}
onChange={e => {
const trimmedData = trimFormDataStrings(e.formData)
setFormData(trimmedData)
}}
transformErrors={transformErrors}
onSubmit={() => handleSave()}
uiSchema={uiSchema}
Expand Down
27 changes: 27 additions & 0 deletions ui/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,30 @@ export const getIngestionMode = (selectedStreams: {
if (upsertCount === allSelectedStreams.length) return IngestionMode.UPSERT
return IngestionMode.CUSTOM
}

// recursively trims all string values in form data used to remove leading/trailing whitespaces from configuration fields
export const trimFormDataStrings = (data: any): any => {
if (data === null || data === undefined) {
return data
}

if (typeof data === "string") {
return data.trim()
}

if (Array.isArray(data)) {
return data.map(item => trimFormDataStrings(item))
}

if (typeof data === "object") {
const trimmedObject: Record<string, any> = {}
for (const key in data) {
if (Object.prototype.hasOwnProperty.call(data, key)) {
trimmedObject[key] = trimFormDataStrings(data[key])
}
}
return trimmedObject
}

return data
}
Loading