From 473238c7a5a2bbcc4c8e1bf5cf12c61ce175672b Mon Sep 17 00:00:00 2001 From: Milan Patel Date: Sun, 18 Jun 2023 12:27:45 +0530 Subject: [PATCH 1/6] Enhanced paste function to accept various format - add formats like (x, y) or (x,y) or x, y or x,y. --- .../GeoPointEditor/GeoPointEditor.react.js | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/components/GeoPointEditor/GeoPointEditor.react.js b/src/components/GeoPointEditor/GeoPointEditor.react.js index 597bc529ee..cb4b1a6f12 100644 --- a/src/components/GeoPointEditor/GeoPointEditor.react.js +++ b/src/components/GeoPointEditor/GeoPointEditor.react.js @@ -106,26 +106,32 @@ export default class GeoPointEditor extends React.Component { let value = e.target.value; if (!validateNumeric(value)) { - var values = value.split(','); - - if (values.length == 2) { - values = values.map(val => val.trim()); - - if (values[0].length > 0 && validateNumeric(values[0])) { - - if (values[1].length <= 0 || !validateNumeric(values[1])) { - this.setState({ latitude: values[0] }); - this.longitudeRef.current.focus(); - this.longitudeRef.current.setSelectionRange(0, String(this.state.longitude).length); - return; - } - - if (validateNumeric(values[1])) { - this.setState({ latitude: values[0] }); - this.setState({ longitude: values[1] }); - this.longitudeRef.current.focus(); - return; - } + // This regex will match this form of input: (x, y) or (x,y) or x, y or x,y + const regex = /\((-?\d+\.?\d*),\s*(-?\d+\.?\d*)\)|(-?\d+\.?\d*),\s*(-?\d+\.?\d*)/; + const match = value.match(regex); + + if (!match) { + return null; + } + + let values = match[0].replace(/[\(\)]/g, '').split(','); + + values = values.map(val => val.trim()); + + if (values[0].length > 0 && validateNumeric(values[0])) { + + if (values[1].length <= 0 || !validateNumeric(values[1])) { + this.setState({ latitude: values[0] }); + this.longitudeRef.current.focus(); + this.longitudeRef.current.setSelectionRange(0, String(this.state.longitude).length); + return; + } + + if (validateNumeric(values[1])) { + this.setState({ latitude: values[0] }); + this.setState({ longitude: values[1] }); + this.longitudeRef.current.focus(); + return; } } } From 4aea9be75d56fab1fdac6d57687b51705e2aafe5 Mon Sep 17 00:00:00 2001 From: Milan Patel Date: Sun, 18 Jun 2023 12:41:08 +0530 Subject: [PATCH 2/6] fix linting issue --- src/components/GeoPointEditor/GeoPointEditor.react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/GeoPointEditor/GeoPointEditor.react.js b/src/components/GeoPointEditor/GeoPointEditor.react.js index cb4b1a6f12..02dd701367 100644 --- a/src/components/GeoPointEditor/GeoPointEditor.react.js +++ b/src/components/GeoPointEditor/GeoPointEditor.react.js @@ -114,7 +114,7 @@ export default class GeoPointEditor extends React.Component { return null; } - let values = match[0].replace(/[\(\)]/g, '').split(','); + let values = match[0].replace(/[()]/g, '').split(','); values = values.map(val => val.trim()); From aaed956cb4b6a527354934d4a73c86cace347055 Mon Sep 17 00:00:00 2001 From: Milan Patel Date: Tue, 20 Jun 2023 02:10:44 +0530 Subject: [PATCH 3/6] refactor regex for pasted value --- src/components/GeoPointEditor/GeoPointEditor.react.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/GeoPointEditor/GeoPointEditor.react.js b/src/components/GeoPointEditor/GeoPointEditor.react.js index 02dd701367..2fa5efa297 100644 --- a/src/components/GeoPointEditor/GeoPointEditor.react.js +++ b/src/components/GeoPointEditor/GeoPointEditor.react.js @@ -106,17 +106,16 @@ export default class GeoPointEditor extends React.Component { let value = e.target.value; if (!validateNumeric(value)) { - // This regex will match this form of input: (x, y) or (x,y) or x, y or x,y - const regex = /\((-?\d+\.?\d*),\s*(-?\d+\.?\d*)\)|(-?\d+\.?\d*),\s*(-?\d+\.?\d*)/; - const match = value.match(regex); + // This regex will match this form of input: (x, y) or (x,y) or x, y or x,y and many more + const regex = + /[\[("' ]?(?[0-9.]+)["' ]?,["' ]?(?[0-9.]+)["' )\]]?/; + const match = regex.exec(value); if (!match) { return null; } - let values = match[0].replace(/[()]/g, '').split(','); - - values = values.map(val => val.trim()); + const values = [match.groups.x, match.groups.y]; if (values[0].length > 0 && validateNumeric(values[0])) { From 59fe314d566aece26b652bf653dacf806925b2f7 Mon Sep 17 00:00:00 2001 From: Milan Patel Date: Tue, 20 Jun 2023 02:12:39 +0530 Subject: [PATCH 4/6] fix lint --- src/components/GeoPointEditor/GeoPointEditor.react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/GeoPointEditor/GeoPointEditor.react.js b/src/components/GeoPointEditor/GeoPointEditor.react.js index 2fa5efa297..3db49252b7 100644 --- a/src/components/GeoPointEditor/GeoPointEditor.react.js +++ b/src/components/GeoPointEditor/GeoPointEditor.react.js @@ -108,7 +108,7 @@ export default class GeoPointEditor extends React.Component { if (!validateNumeric(value)) { // This regex will match this form of input: (x, y) or (x,y) or x, y or x,y and many more const regex = - /[\[("' ]?(?[0-9.]+)["' ]?,["' ]?(?[0-9.]+)["' )\]]?/; + /[[("' ]?(?[0-9.]+)["' ]?,["' ]?(?[0-9.]+)["' )\]]?/; const match = regex.exec(value); if (!match) { From 55595619b6fdd1ed54a31bbd1668ee06cfe95d2a Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Tue, 20 Jun 2023 02:33:15 +0200 Subject: [PATCH 5/6] Update src/components/GeoPointEditor/GeoPointEditor.react.js Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- src/components/GeoPointEditor/GeoPointEditor.react.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/GeoPointEditor/GeoPointEditor.react.js b/src/components/GeoPointEditor/GeoPointEditor.react.js index 3db49252b7..8d65b892fc 100644 --- a/src/components/GeoPointEditor/GeoPointEditor.react.js +++ b/src/components/GeoPointEditor/GeoPointEditor.react.js @@ -106,7 +106,6 @@ export default class GeoPointEditor extends React.Component { let value = e.target.value; if (!validateNumeric(value)) { - // This regex will match this form of input: (x, y) or (x,y) or x, y or x,y and many more const regex = /[[("' ]?(?[0-9.]+)["' ]?,["' ]?(?[0-9.]+)["' )\]]?/; const match = regex.exec(value); From 5e6636d03ae604b895de87377c5ca78f010a5c68 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Tue, 20 Jun 2023 02:34:55 +0200 Subject: [PATCH 6/6] Update src/components/GeoPointEditor/GeoPointEditor.react.js Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com> --- src/components/GeoPointEditor/GeoPointEditor.react.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/GeoPointEditor/GeoPointEditor.react.js b/src/components/GeoPointEditor/GeoPointEditor.react.js index 8d65b892fc..f29e1713b1 100644 --- a/src/components/GeoPointEditor/GeoPointEditor.react.js +++ b/src/components/GeoPointEditor/GeoPointEditor.react.js @@ -106,8 +106,7 @@ export default class GeoPointEditor extends React.Component { let value = e.target.value; if (!validateNumeric(value)) { - const regex = - /[[("' ]?(?[0-9.]+)["' ]?,["' ]?(?[0-9.]+)["' )\]]?/; + const regex = /[[("' ]?(?[0-9.]+)["' ]?,["' ]?(?[0-9.]+)["' )\]]?/; const match = regex.exec(value); if (!match) {