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: add patch to feed default ValidationOptions on table shorttext #7029

Merged
merged 2 commits into from
Jan 23, 2024

Conversation

KenLSM
Copy link
Contributor

@KenLSM KenLSM commented Jan 21, 2024

Problem

Due to this issue on Mongoose 6.x, discriminated fields doesn't respect inherited defaults.

This currently affects our Table field where a dropdown column is updated to shortText. This would then be updated into the DB without a ValidationOptions field. Consequently, code that references column.ValidationOptions.* would throw an error as the object is undefined.

Note: Inserting a new shortText column uses the helper function that contains the ValidationOptions field, thus not affected by this change.

Solution

Add a patch that checks for shortText and provide a defaulted ValidationOptions object to it.

Tests

Bug fix tests, reproduction steps

  • Add new table field
  • Add new textField column on table
  • Save field
  • Ensure as a respondent submit form succeeds
  • Change textField to dropdown
  • Save field
  • Change dropdown field to textField
  • Save field
  • Ensure as a respondent submit form succeeds

Comment on lines +609 to +610
customVal: null,
selectedValidation: null,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should add the prefill properties too, just for db consistency's sake

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm those are marked as optional on types. But if we look at inheritance it should be populated.

Both are correct. I in favour of keeping it as simple as possible.

newField: FieldUpdateDto,
) => {
if (newField.fieldType === BasicField.Table) {
const defaultValidationOptions = {
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 defaultValidationOptions = {
const defaultValidationOptions: TextValidationOptions = {

(import TextValidationOptions from '../../../../../shared/types')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Added in b8cb466

Copy link
Contributor

@wanlingt wanlingt left a comment

Choose a reason for hiding this comment

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

lgtm! nit: add TextValidationOptions for type safety

@KenLSM KenLSM enabled auto-merge (squash) January 23, 2024 07:47
@KenLSM KenLSM disabled auto-merge January 23, 2024 07:47
@KenLSM KenLSM enabled auto-merge (squash) January 23, 2024 07:57
@KenLSM KenLSM merged commit 9cb3126 into develop Jan 23, 2024
23 checks passed
@KenLSM KenLSM deleted the fix/mongoose-manual-base-schema-inheritance branch January 23, 2024 08:05
This was referenced Jan 24, 2024
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.

None yet

3 participants