Skip to content

Commit 96fc345

Browse files
fix: Not able to remove commas in Multiple mappings (#3148)
* fix: Not able to remove commas in Multiple mappings * fix: Remove console log
1 parent 99cf353 commit 96fc345

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/components/MappingEditor/MappingEditor.module.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@
9191

9292
/* Multiple */
9393

94-
.multiple {
94+
.mappings :global(.dcl.text-area) {
9595
width: 100%;
9696
}

src/components/MappingEditor/MappingEditor.tsx

+25-12
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,32 @@ export const MappingEditor = (props: Props) => {
6969
onChange({ type: MappingType.SINGLE, id: data.value.replaceAll(',', '') })
7070
}, [])
7171

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

80-
onChange({
81-
type: MappingType.MULTIPLE,
82-
ids
83-
})
84-
}, [])
76+
// If it's removing a whitespace character, remove the last comma
77+
if (mappingValue.slice(0, -1) === data.value && mappingValue.slice(-1)) {
78+
value = value.slice(0, value.length - 1)
79+
}
80+
81+
const ids =
82+
value
83+
.toString()
84+
// Only allow numbers, commas and whitespaces
85+
.replaceAll(/[^0-9,\s]/g, '')
86+
// Remove whitespaces before commas
87+
.replaceAll(/\s,/g, '')
88+
.split(',')
89+
.map(s => s.trim()) ?? []
90+
91+
onChange({
92+
type: MappingType.MULTIPLE,
93+
ids
94+
})
95+
},
96+
[mappingValue]
97+
)
8598

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

0 commit comments

Comments
 (0)