Skip to content

Conversation

binh-dam-ibigroup
Copy link
Contributor

@binh-dam-ibigroup binh-dam-ibigroup commented Jun 15, 2021

Checklist

  • Appropriate branch selected (all PRs must first be merged to dev before they can be merged to master)
  • Any modified or new methods or classes have helpful JSDoc and code is thoroughly commented
  • The description lists all applicable issues this PR seeks to resolve
  • [na] The description lists any configuration setting(s) that differ from the default settings
  • All tests and CI builds passing

Description

Companion PR to ibi-group/datatools-server#392 to address ibi-group/datatools-server#391.

This PR adds UI feedback for invalid substitution patterns.

To test on configurations that enable Normalize Field Transformation:

  1. Follow steps 1-3 from Normalize Field substitution patterns should be validated datatools-server#391
  2. After you enter the invalid substitution pattern EDIT for previously saved invalid substitutions, notice the feedback on the UI (see screenshot). Modify the incorrect substitution pattern to remove the red feedback box, and click the check mark to save the changes and observe the subsequent UI feedback.
  3. EDIT Add a new/change a substitution with an invalid search pattern and click Save. Note the error dialog about the invalid pattern. The new/changed substitution row with the entered values will still be available with the same visual feedback.

image

@landonreed landonreed changed the title fix(SubstitutionRow): Add feedback for invalid substitution patterns. Add feedback for invalid substitution patterns. Jun 15, 2021
Comment on lines 31 to 54
function extractStateFields (props: Props): Substitution {
const { description, normalizeSpace, pattern, replacement } = props.substitution
const { description, normalizeSpace, pattern, replacement, valid } = props.substitution
return {
description: description || '',
normalizeSpace,
normalizeSpace: normalizeSpace || false,
pattern,
replacement
replacement,
valid
}
}

/**
* @returns true if the given substitution pattern is null or empty, false otherwise.
*/
export function isSubstitutionInvalid (substitution: Substitution) {
export function isSubstitutionBlank (substitution: Substitution) {
return !substitution.pattern || substitution.pattern === ''
}

/**
* @returns true if the given substitution is marked invalid by the backend, false otherwise.
*/
export function isSubstitutionInvalid (substitution: Substitution) {
return !substitution.valid
}
Copy link
Contributor

Choose a reason for hiding this comment

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

To better organize things, can these util functions be moved to a util file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, maybe just the isSubstitutionBlank and isSubstitutionInvalid functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in cf0d3a0.

/**
* Determines whether two substitutions are equal (except for the valid field).
*/
function areEqual (sub1: ?Substitution, sub2: ?Substitution): boolean {
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
function areEqual (sub1: ?Substitution, sub2: ?Substitution): boolean {
function substitutionsAreEqual (sub1: ?Substitution, sub2: ?Substitution): boolean {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in cf0d3a0.

Copy link
Contributor

@evansiroky evansiroky left a comment

Choose a reason for hiding this comment

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

This seems like an indirect way of performing validation while preserving the input data. This attempts to save the data and there just happens to be a helpful (but somewhat intrusive) error message that happens to be displayed due to any webservice failure. But of course, the updateFeedSource action is refetching the feed source and thus overwrites the data hence the need for this state management stuff to prevent this "side effect".

The more direct way of doing this would be to attempt a pre-update of the data by making a request to the server and if that failed, don't do the actual update, but do display a non-intrusive error message in the appropriate place in the form. That way the react values would still be preserved and none of this fancy state management workaround would be needed.

That being said, it's built and functions as is. However, since it indirectly depends on the functionality of a somewhat unrelated process, this has the potential to be dead code or if the error message display is refactored, then the UX is different. I don't really like it, but I suppose I can approve.

I will, however, make this conditional on creating a util file for the mentioned functions.

Copy link
Contributor

@landonreed landonreed left a comment

Choose a reason for hiding this comment

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

LGTM thanks @binh-dam-ibigroup.

@landonreed landonreed merged commit 8cfd5fc into dev Jun 18, 2021
@landonreed landonreed deleted the normalize-field-pattern-validation branch June 18, 2021 16:34
@landonreed landonreed mentioned this pull request Sep 2, 2021
7 tasks
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