Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incoherency allowed characters tableName/columnName (+ improved regex & docs) #4173

Merged
merged 19 commits into from
Sep 30, 2024

Conversation

svandenhoek
Copy link
Contributor

@svandenhoek svandenhoek commented Aug 29, 2024

What are the main changes you did:

how to test:

  • explain here what to do to test this (or point to unit tests)

todo:

  • updated docs in case of new feature
  • added/updated tests
  • added/updated testplan to include a test for this fix, including ref to bug using # notation

Copy link
Member

@mswertz mswertz left a comment

Choose a reason for hiding this comment

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

looks good, let me know when finished

@svandenhoek
Copy link
Contributor Author

integrated #4172

@svandenhoek svandenhoek changed the title fix: incoherency allowed characters tableName/columnName (+ improved regex) fix: incoherency allowed characters tableName/columnName (+ improved regex & docs) Sep 2, 2024
@svandenhoek svandenhoek marked this pull request as ready for review September 2, 2024 13:16
Copy link
Member

@mswertz mswertz left a comment

Choose a reason for hiding this comment

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

nice. Small comments. I particular make sure that user documentation starts with human explanation and then add regexp for the tech reader.

apps/molgenis-components/src/components/constants.ts Outdated Show resolved Hide resolved
docs/molgenis/use_schema.md Outdated Show resolved Hide resolved
Copy link
Contributor

@davidruvolo51 davidruvolo51 left a comment

Choose a reason for hiding this comment

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

Looks good. I think some minor revisions to the error message could help make it clearer for end users. Perhaps something like this:

Table names must start with a letter followed by one or more letters, numbers or underscores. Names cannot exceed 31 characters. Spaces are also allowed as long as they do not occur immediately before or after an underscore.

We could also have a few examples: My table, myTable, my_table, My table 2, etc.

@@ -0,0 +1,30 @@
import { test, expect } from '@playwright/test';

let regexErrorMessage='Table name must start with a letter, followed by letters/underscores/spaces/numbers (though no underscore preceded/followed by a space) and with a maximum of 31 characters, i.e. ^(?!.* _|.*_ )[a-zA-Z][a-zA-Z0-9 _]{0,30}$'
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless the message is reassigned, const should be used here instead of let.

@@ -178,7 +179,7 @@ export default {
) {
return undefined;
} else {
return "Table name must start with a letter, followed by letters, underscores, a space or numbers, i.e. [a-zA-Z][a-zA-Z0-9_]*. Maximum length: 31 characters";
return "Table name must start with a letter, followed by letters/underscores/spaces/numbers (though no underscore preceded/followed by a space) and with a maximum of 31 characters, i.e. ^(?!.* _|.*_ )[a-zA-Z][a-zA-Z0-9 _]{0,30}$";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we put the regex pattern in the error message? It is helpful for developers, but I'm not sure if many end users (data managers, lab personnel, etc.) would understand this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point. I left it in as they were present already, though for a user (without IT background) it indeed can just cause confusion.

if (!this.column.name.match(/^[a-zA-Z][a-zA-Z0-9_ ]+$/)) {
return "Name should start with letter, followed by letter, number, whitespace or underscore ([a-zA-Z][a-zA-Z0-9_ ]*)";
if (!this.column.name.match(constants.COLUMN_NAME_REGEX)) {
return "Name should start with a letter, followed by letters/underscores/spaces/numbers (though no underscore preceded/followed by a space), i.e. ^(?!.* _|.*_ )[a-zA-Z][a-zA-Z0-9 _]*$";
Copy link
Contributor

Choose a reason for hiding this comment

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

(See comment above)

) {
return "Name is required and can only contain 'azAZ_ '";
return "Name is required and must start with a letter, followed by letters/underscores/spaces/numbers (though no underscore preceded/followed by a space) and with a maximum of 31 characters, i.e. ^(?!.* _|.*_ )[a-zA-Z][a-zA-Z0-9 _]{0,30}$";
Copy link
Contributor

Choose a reason for hiding this comment

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

(Same as above)

@svandenhoek
Copy link
Contributor Author

@mswertz:

  • Regex now after human-readable in docs.
  • Added limit (63) to column names.

@davidruvolo51:

  • A table with examples is added for database creation docs and table/column names refer to that table for examples.
  • Renamed error messages (without regex, though slightly deviated from your example).
  • Fixed let -> const

Copy link
Contributor

@davidruvolo51 davidruvolo51 left a comment

Choose a reason for hiding this comment

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

Looks great!

Copy link

sonarcloud bot commented Sep 30, 2024

@svandenhoek svandenhoek merged commit 5e6a0ff into master Sep 30, 2024
6 checks passed
@svandenhoek svandenhoek deleted the fix/tableName_regex branch September 30, 2024 12:40
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