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

[DC-792] injects matchingKey in the perform block #2119

Merged
merged 3 commits into from
Jun 28, 2024

Conversation

konoufo
Copy link
Contributor

@konoufo konoufo commented Jun 27, 2024

This PR adds the ability to access user-selected record matching field in the perform block. The matchingKey is the field key for one of the action fields of category identifier. The record matching field is meant to be selected via a dropdown in the mapping UI for RETL (upcoming work). See the relevant section of the blueprint for more context.

Testing

Include any additional information about the testing you have completed to
ensure your changes behave as expected. For a speedy review, please check
any of the tasks you completed below during your testing.

  • Added unit tests for new functionality
  • Tested end-to-end using the local server
  • [Segmenters] Tested in the staging environment

@konoufo konoufo changed the title injects matchingKey in the perform block [DC-792] injects matchingKey in the perform block Jun 27, 2024
@konoufo konoufo marked this pull request as ready for review June 27, 2024 21:13
@konoufo konoufo requested a review from a team as a code owner June 27, 2024 21:13
description: 'The user ID',
type: 'string',
required: true,
category: 'identifier'
Copy link
Member

Choose a reason for hiding this comment

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

Still trying to understand the multiple identifiers case, suppose we had an additional identifier field 'email' here. Then we would automatically push a 'Record Matching' dropdown field that users would pick userID or email from, and depending on that the matchingKey would pull the correct value from the payload for the perform block? Is that a good understanding?

Copy link
Contributor Author

@konoufo konoufo Jun 27, 2024

Choose a reason for hiding this comment

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

Still trying to understand the multiple identifiers case, suppose we had an additional identifier field 'email' here. Then we would automatically push a 'Record Matching' dropdown field that users would pick userID or email from, and depending on that the matchingKey would pull the correct value from the payload for the perform block? Is that a good understanding?

@nick-Ag Exactly 💯 . So in the UI, the selected field out of all the identifier fields defined would have been stored in mapping['__segment_internal_matching_key'], which is exactly what matchingKey is set to.

nick-Ag
nick-Ag previously approved these changes Jun 27, 2024
pooyaj
pooyaj previously approved these changes Jun 27, 2024
Copy link
Contributor

@pooyaj pooyaj left a comment

Choose a reason for hiding this comment

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

Small nit otherwise looks great 🙌

@@ -197,6 +197,13 @@ const isSyncMode = (value: unknown): value is SyncMode => {
return syncModeTypes.find((validValue) => value === validValue) !== undefined
}

const INTERNAL_HIDDEN_FIELDS = ['__segment_internal_sync_mode', '__segment_internal_matching_key']
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! more tidy than before 👏

@@ -297,6 +302,10 @@ export class Action<Settings, Payload extends JSONLikeObject, AudienceSettings =

const syncMode = this.definition.syncMode ? bundle.mapping?.['__segment_internal_sync_mode'] : undefined

const matchingKey = Object.values(this.definition.fields).find((field) => field.category === 'identifier')
Copy link
Contributor

Choose a reason for hiding this comment

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

Safe to remove this check to simplify? Can we just make an attempt to pass bundle.mapping?.['__segment_internal_matching_key'] ... I think will be undefined if the destination does not support record matching anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Safe to remove this check to simplify? Can we just make an attempt to pass bundle.mapping?.['__segment_internal_matching_key'] ... I think will be undefined if the destination does not support record matching anyways.

Yeah I guess I was trying to be defensive lol. By the way, do you think there should be validation to make sure that the value in bundle.mapping?.['__segment_internal_matching_key'] is one of the identifier fields?
I'm on the fence. On one hand the UI is unlikely to cause invalid values but on another hand, things happen e.g someone can save a bad mapping via PAPI?

Copy link
Contributor

Choose a reason for hiding this comment

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

I considered removing the condition to simplify future changes. If we decide to change the field category used as the indicator for matching keys, fewer parts of the codebase will need to be updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also no need for validation since even if someone creates a __segment_internal_matching_key with bad value it won't cause any significant issues in the perform block

@konoufo konoufo dismissed stale reviews from pooyaj and nick-Ag via f872dc4 June 27, 2024 22:55
@konoufo konoufo requested a review from a team as a code owner June 27, 2024 22:55
@konoufo konoufo merged commit 510f423 into main Jun 28, 2024
11 checks passed
@konoufo konoufo deleted the DC-792/matching-key-perform-block branch June 28, 2024 22:51
@joe-ayoub-segment
Copy link
Contributor

hi @konoufo PR deployed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants