Skip to content

Commit

Permalink
fix: Not able to remove commas in Multiple mappings (#3148)
Browse files Browse the repository at this point in the history
* fix: Not able to remove commas in Multiple mappings

* fix: Remove console log
  • Loading branch information
LautaroPetaccio authored Aug 2, 2024
1 parent 99cf353 commit 96fc345
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/MappingEditor/MappingEditor.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@

/* Multiple */

.multiple {
.mappings :global(.dcl.text-area) {
width: 100%;
}
37 changes: 25 additions & 12 deletions src/components/MappingEditor/MappingEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,32 @@ export const MappingEditor = (props: Props) => {
onChange({ type: MappingType.SINGLE, id: data.value.replaceAll(',', '') })
}, [])

const handleMultipleMappingValueChange = useCallback((_, data: TextAreaProps | InputOnChangeData) => {
const ids =
data.value
?.toString()
.replaceAll(/[^0-9,\s]/g, '')
.split(',')
.map(value => value.trim()) ?? []
const handleMultipleMappingValueChange = useCallback(
(_, data: TextAreaProps | InputOnChangeData) => {
let value = (data.value ?? '').toString()

onChange({
type: MappingType.MULTIPLE,
ids
})
}, [])
// If it's removing a whitespace character, remove the last comma
if (mappingValue.slice(0, -1) === data.value && mappingValue.slice(-1)) {
value = value.slice(0, value.length - 1)
}

const ids =
value
.toString()
// Only allow numbers, commas and whitespaces
.replaceAll(/[^0-9,\s]/g, '')
// Remove whitespaces before commas
.replaceAll(/\s,/g, '')
.split(',')
.map(s => s.trim()) ?? []

onChange({
type: MappingType.MULTIPLE,
ids
})
},
[mappingValue]
)

const handleFromMappingValueChange = useCallback(
(_: React.ChangeEvent<HTMLInputElement>, data: InputOnChangeData) => {
Expand Down

0 comments on commit 96fc345

Please sign in to comment.