-
Notifications
You must be signed in to change notification settings - Fork 257
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
Required Fields V2 - Conditionally Required Fields #2099
Conversation
…ricts them to anyOf, allOf, oneOf which are all a list of fieldKeys
hi @nick-Ag - I know this is still in draft, so just out of curiosity what will this do?
Will it hide or show fields in the UI depending on which fields have a mapping populated? Keen to understand the intent here as I think the second approach would be really valuable. |
Planning on the second approach primarily. I also want the validation to appear in the UX so that users can't save mappings where the group condition has not been met. Looking forward to showing more soon! |
New required fields detectedWarning Your PR adds new required fields to an existing destination. Adding new required settings/mappings for a destination already in production requires updating existing customer destination configuration. Ignore this warning if this PR is for a new destination with no active customers in production. The following required fields were added in this PR:
Add these new fields as optional instead and assume default values in |
…ld defined for one field.
…Adds a new unit test for multiple object dependant conditions
Hi @nick-Ag , qq:
|
|
I'm going to make a small update to the PR to handle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work! Great tests!
Left just one question about nulls.
hi @nick-Ag. Couple of questions about how this code will behave:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for answering my questions! Nice work! ✨ This will be very useful feature saving us some lines of code and bring in some consistency!
Looks great 🙌 This is not part of the scope? right?
wondering if we handle it gracefully if someone puts a condition on the required field ( ideal if we can prevent it via typescript ) |
|
Fantastic question. Based on a unit test I just wrote that case is not handled correctly. Going to circle back and address it before merging. Will consider both preventing it entirely vs. implementing it correctly |
Nice question @pooyaj . My vote is to implement it if possible (if @nick-Ag can do it!). The reason is that Object fields are a neat way to squeeze a lot of fields into a small amount of page real estate. and they also allow us to locate related fields close together. It would be a missed opportunity if 'required' didn't work on these sub fields. |
…o on how conditional fields work
Have implemented that use case & updated the README with some documentation about this feature. This one is ready to go out. Looking for final review @joe-ayoub-segment , @varadarajan-tw , @pooyaj |
creationName: { | ||
label: "The name of the resource to create, required when operation = 'create'", | ||
required: { | ||
// This field is required only when the 'operation' field has the value 'create' | ||
match: 'all', | ||
conditions: [ | ||
{ | ||
fieldKey: 'operation', | ||
operator: 'is', | ||
value: 'create' | ||
} | ||
] | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @nick-Ag .
Can we include an example with dot notation for a reference to an object.property field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed the functionality with @nick-Ag . I'm not the best person to review the code though, so please have someone who understands this part of the codebase do a review.
This PR revamps the
required
property for action input fields such that a destination builder can define conditionally required fields. These builder defined conditional requirements are then compiled into a JSONSchema4 object, which is used to validate each mapping before theperform
block is triggered.SDD: Link
Conditional Field Example:
For example, the Salesforce Lead
last_name
field is only required when a user is creating a lead. We can now encode that in the definition of the field directly like this:This builder defined condition will then be compiled into a JSONSchema like this:
And eventually will validate Payloads such as these:
{ operation: 'create', first_name: 'nick' } // invalid - missing last_name
{ operation: 'create', last_name: 'aguilar' } // valid - required last_name is included
{ operation: 'update', first_name: 'nick' } // valid - last_name is not required
Reviewing this PR:
~2800 lines added:
Testing
Deployed successfully to staging. I have updated the Salesforce Lead action's
last_name
field with a conditional requirement.As of now these conditions are not implemented in the UI, and I am only expecting new AJV error messages when the conditional requirement is not met.
The conditional requirement is enforced when
![Screenshot 2024-12-02 at 10 19 17 AM](https://private-user-images.githubusercontent.com/27820201/391674524-edd32034-c3e4-419c-8c08-4c1b2ede3e1b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwOTI3NzcsIm5iZiI6MTczOTA5MjQ3NywicGF0aCI6Ii8yNzgyMDIwMS8zOTE2NzQ1MjQtZWRkMzIwMzQtYzNlNC00MTljLThjMDgtNGMxYjJlZGUzZTFiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA5MTQzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJkZjU4ZTBhNzk2YjhkNThlNmQzNTJkNDBhY2ZjMGEzMmQ1NTE1NjQ3ZGJiMjZmM2IzY2VlNGM2MDcyMGQxNjImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.eFoCWnJfmyUkcm8yKgqn3ez8yGRQ0zfZTmwi3E_5QtM)
operation: create
butlast_name
is missing:When
![Screenshot 2024-12-02 at 10 21 05 AM](https://private-user-images.githubusercontent.com/27820201/391674663-ca173b85-971a-4f1c-803b-5afb45fab88a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwOTI3NzcsIm5iZiI6MTczOTA5MjQ3NywicGF0aCI6Ii8yNzgyMDIwMS8zOTE2NzQ2NjMtY2ExNzNiODUtOTcxYS00ZjFjLTgwM2ItNWFmYjQ1ZmFiODhhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA5MTQzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWIyMjQyM2UxNjk4NGNjOGRkYjIyYzNiN2QxMjJmOWRkYzM2YTYwYTYyMmZiNTcxNjVjMWNkZDEyN2FmZjA1OTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.nhr9BP9NslQiXo7mimPFULgpF2uM-3YylSyXgPVEYso)
operation: create
andlast_name
is defined, the condition is met and event delivery succeeds:When
![Screenshot 2024-12-02 at 10 26 43 AM](https://private-user-images.githubusercontent.com/27820201/391674869-1354b628-adfd-4eeb-955e-6bd5ca75f24f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwOTI3NzcsIm5iZiI6MTczOTA5MjQ3NywicGF0aCI6Ii8yNzgyMDIwMS8zOTE2NzQ4NjktMTM1NGI2MjgtYWRmZC00ZWViLTk1NWUtNmJkNWNhNzVmMjRmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDA5MTQzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ4MTZmYTYwMzgzY2E5Y2VkOTlkZWRkOGQxNWNjNTk0ODg4ZTQwZDZlMzFiNTEyNWRhNmRjMDNhZjcwMTJkZjMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.lISYnBs6D1nvSCcIXpJKzJKGsxPjoAixdYis_7rIk3g)
operation: update
the condition is not enforced andlast_name
can be undefined:Merge & Deploy Timing
This PR will be a part of a series of PRs. It should not be merged or deployed before these other PRs are ready.
@joe-ayoub-segment - I will handle the final deploy of this one
app
: https://github.com/segmentio/app/pull/22618action-cli
: https://github.com/segmentio/action-cli/pull/196 💬