Skip to content

Feat:Email validation regex field added along with default values#820

Merged
notsidney merged 12 commits intorowyio:developfrom
RajGM:emailValidation_799
Nov 29, 2022
Merged

Feat:Email validation regex field added along with default values#820
notsidney merged 12 commits intorowyio:developfrom
RajGM:emailValidation_799

Conversation

@RajGM
Copy link
Contributor

@RajGM RajGM commented Sep 17, 2022

Signed-off-by: Raj Gaurav Maurya rajgmsocial19@gmail.com

Signed-off-by: Raj Gaurav Maurya <rajgmsocial19@gmail.com>
@RajGM
Copy link
Contributor Author

RajGM commented Sep 18, 2022

@htuerker @harinij

@harinij harinij requested a review from notsidney September 20, 2022 02:39
@harinij harinij changed the base branch from main to develop September 21, 2022 06:32
@notsidney
Copy link
Contributor

notsidney commented Sep 26, 2022

This PR only adds the text field to save the custom regex to the column config. It does not do any validation on data. @harinij is that within the scope of the original issue (#799)?

Edit: we have exiting behavior that validates any field if it has the config.validationRegex field set, so no further implementation is required in this PR.

Signed-off-by: Raj Gaurav Maurya <rajgmsocial19@gmail.com>
@vercel
Copy link

vercel bot commented Oct 2, 2022

@RajGM is attempting to deploy a commit to the Rowy Team on Vercel.

A member of the Team first needs to authorize it.

@RajGM
Copy link
Contributor Author

RajGM commented Oct 2, 2022

Hi @notsidney
It's working now.
Working

@notsidney
Copy link
Contributor

Thanks, it works when I manually update the regex (such as adding a space at the end) then saving.

The issue is that having that as the default value in the UI implies that that setting has already been set and that clicking “Update” will set it. However, reading the code, it’s only set when there is an input to the text field, so it has to be typed in first.

I don’t think it’s a good idea to have it as the default value, but rather have a button next to it that says “Use standard regex” or something similar that sets the regex. This makes sure the user doesn’t think the regex is set but it’s not working.

Copy link
Contributor

@notsidney notsidney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please commit the suggestions, then this PR is ready to be merged.

const emailFieldValidation = useRef<HTMLInputElement>(null);
const useStandardRegex = () => {
if (emailFieldValidation.current != null) {
emailFieldValidation.current.value = "^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
emailFieldValidation.current.value = "^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$";
onChange("validationRegex")("^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$");

As I wrote in a previous comment:

it works when I manually update the regex (such as adding a space at the end) then saving.

it’s only set when there is an input to the text field, so it has to be typed in first.

This is because you call onChange when the user types in the text field only. You manually change the value of the input element in the DOM, which doesn’t update the React state.

So when the user clicks the button, it updates the rendered input but doesn’t save in the column config, so it will never validate unless if they type in the input after clicking the button.


export default function Settings({ onChange, config }: ISettingsProps) {

const emailFieldValidation = useRef<HTMLInputElement>(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const emailFieldValidation = useRef<HTMLInputElement>(null);

Remove unnecessary refs.

return (
<>
<TextField
inputRef={emailFieldValidation}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inputRef={emailFieldValidation}

Remove unnecessary refs.

@vercel
Copy link

vercel bot commented Nov 28, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
rowy-typedoc ⬜️ Ignored (Inspect) Nov 29, 2022 at 0:26AM (UTC)

@RajGM
Copy link
Contributor Author

RajGM commented Nov 28, 2022

Hi @notsidney
In the latest push, I made some changes; the standard regex is copied to the clipboard, and the user pastes it on the input.
Now it's working as expected.
Also, the regex works if the page is reloaded or the application restarts.
Unnecessary refs are deleted as well.

@notsidney
Copy link
Contributor

@RajGM What’s the benefit of copying to the clipboard instead of updating the value in state directly? The user would have to click the button then click on the text field then paste. I already provided a working suggestion that would have resolved this issue.

@RajGM
Copy link
Contributor Author

RajGM commented Nov 29, 2022

Ok, let me directly implement the changes into state using https://www.npmjs.com/package/jotai

Copy link
Contributor

@notsidney notsidney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is entirely unnecessary to have to use Jotai. The suggestion I made previously is enough to implement this behavior. Let’s get this PR over the line.

export default function Settings({ onChange, config }: ISettingsProps) {

const copyStandardRegex = () => {
navigator.clipboard.writeText('^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
navigator.clipboard.writeText('^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$');
onChange("validationRegex")("^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-zA-z]{2,3}$");

As I wrote in a previous comment:

it works when I manually update the regex (such as adding a space at the end) then saving.

it’s only set when there is an input to the text field, so it has to be typed in first.

This is because you call onChange when the user types in the text field only. You manually change the value of the input element in the DOM, which doesn’t update the React state.

So when the user clicks the button, it updates the rendered input but doesn’t save in the column config, so it will never validate unless if they type in the input after clicking the button.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Sidney
Can you please refer to some docs or something.
While I understood what you are trying to convey but being unable to implement the feature.

Copy link
Contributor

@notsidney notsidney Nov 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve gone ahead and merged this PR with some changes to make it work. An updated contribution guide will be published shortly, which will help for more complex contributions. Here’s a draft link.

For this feature:

  1. The Settings component takes onChange and config as props. config is the current local state of the column config. onChange will update the config in local state.
  2. A parent component renders this Settings component and an “Update” button that will save the updated config stored in local state to the database.
  3. Separately, the TextField component has its own onChange prop, where you can pass a function that will be called whenever the user types in that text field.
  4. You set this to update the local state using onChange from Settings. So the user can type their own regex and it will be saved when they click “Update”.
  5. When you created the “Use standard Regex” button, you did not use onChange from Settings, but rather changed the rendered input directly (using a ref). This means you did not “inform” React, so the local state did not change.
  6. When the user clicks “Update”, the parent component saves the local state. But since it was never updated, the standard regex is never saved to the database, so there is no validation.

The way to fix it is to use the onChange prop from Settings for the button, which you already did for the TextField.

@notsidney notsidney merged commit bc48d80 into rowyio:develop Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants