Skip to content

Commit

Permalink
fix(TDS-6666): add skipping commas with back slash (#4258)
Browse files Browse the repository at this point in the history
* replace split with regex for characters escaping

* debug the inputs

* add choice to skip attribute

* fix property use

* Update packages/forms/src/UIForm/fields/Enumeration/EnumerationWidget.js

Co-authored-by: Jean-Michel FRANCOIS <[email protected]>

* Update packages/forms/src/UIForm/fields/Enumeration/EnumerationWidget.js

Co-authored-by: Jean-Michel FRANCOIS <[email protected]>

* Update packages/forms/src/UIForm/fields/Enumeration/EnumerationWidget.js

Co-authored-by: Jean-Michel FRANCOIS <[email protected]>

* Update packages/forms/src/UIForm/fields/Enumeration/EnumerationWidget.js

Co-authored-by: Jean-Michel FRANCOIS <[email protected]>

* Update packages/forms/src/UIForm/fields/Enumeration/EnumerationWidget.js

Co-authored-by: Jean-Michel FRANCOIS <[email protected]>

* changeset

* change var name and add test

* refactor skip commas code

* generate changeset

* delete duplicated code

* undefined guards

* delete changeset

* Update .changeset/forty-cherries-sleep.md

* Update .changeset/forty-cherries-sleep.md

Co-authored-by: abdelillah <[email protected]>
Co-authored-by: Jean-Michel FRANCOIS <[email protected]>
Co-authored-by: Romain GUILLAUME <[email protected]>
  • Loading branch information
4 people authored Jul 28, 2022
1 parent 582ac76 commit 73c84e6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-cherries-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/react-forms': patch
---

fix: move skipCommas options to schema object instead of component api
18 changes: 13 additions & 5 deletions packages/forms/src/UIForm/fields/Enumeration/EnumerationWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class EnumerationForm extends React.Component {
}));
const formattedValue = EnumerationForm.parseStringValueToArray(
value.value,
this.props.skipCommas,
this.props.schema?.skipCommas || false,
);
this.props
.onTrigger(event, {
Expand Down Expand Up @@ -478,7 +478,10 @@ class EnumerationForm extends React.Component {

// if the value is empty, no value update is done
if (value.value && !valueExist) {
item.values = EnumerationForm.parseStringValueToArray(value.value, this.props.skipCommas);
item.values = EnumerationForm.parseStringValueToArray(
value.value,
this.props.schema?.skipCommas || false,
);
}
if (valueExist) {
item.error = this.props.t('ENUMERATION_WIDGET_DUPLICATION_ERROR', {
Expand Down Expand Up @@ -711,7 +714,10 @@ class EnumerationForm extends React.Component {
this.props
.onTrigger(event, {
trigger: {
value: EnumerationForm.parseStringValueToArray(value.value, this.props.skipCommas),
value: EnumerationForm.parseStringValueToArray(
value.value,
this.props.schema?.skipCommas || false,
),
action: ENUMERATION_ADD_ACTION,
},
schema,
Expand All @@ -735,7 +741,10 @@ class EnumerationForm extends React.Component {
schema,
value: this.state.items.concat([
{
values: EnumerationForm.parseStringValueToArray(value.value, this.props.skipCommas),
values: EnumerationForm.parseStringValueToArray(
value.value,
this.props.schema?.skipCommas || false,
),
},
]),
};
Expand Down Expand Up @@ -1060,7 +1069,6 @@ if (process.env.NODE_ENV !== 'production') {
onTrigger: PropTypes.func.isRequired,
properties: PropTypes.object,
schema: PropTypes.object,
skipCommas: PropTypes.bool,
t: PropTypes.func,
value: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,8 @@ describe('EnumerationWidget', () => {
onChange={jest.fn()}
onFinish={jest.fn()}
onTrigger={onTrigger}
schema={{}}
schema={{ skipCommas: true }}
properties={{ connectedMode: true }}
skipCommas
/>,
);

Expand All @@ -258,7 +257,9 @@ describe('EnumerationWidget', () => {

// then
expect(onTrigger).toBeCalledWith(expect.anything(), {
schema: {},
schema: {
skipCommas: true,
},
trigger: {
action: 'ENUMERATION_ADD_ACTION',
value: ['foo, tata'],
Expand Down

0 comments on commit 73c84e6

Please sign in to comment.