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

NEOS-1379: handle duplicate mongo mappings #2581

Merged
merged 12 commits into from
Sep 5, 2024
Merged

Conversation

evisdrenova
Copy link
Contributor

No description provided.

@evisdrenova evisdrenova added the enhancement New feature or request label Sep 1, 2024
Copy link

vercel bot commented Sep 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
neosync-docs ⬜️ Ignored (Inspect) Visit Preview Sep 4, 2024 4:36am

Copy link

linear bot commented Sep 1, 2024

@evisdrenova evisdrenova changed the title NEOS-1379: Duplicate mongo mappings NEOS-1379: handle duplicate mongo mappings Sep 2, 2024
Copy link
Member

@nickzelei nickzelei left a comment

Choose a reason for hiding this comment

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

Left a few comments. Thanks for working this! I think we can clean this up to be a lot more efficient and require overall less code.
Let me know if you have any Q's.

@evisdrenova evisdrenova force-pushed the duplicateMongoMappings branch from 90cad2d to 30f1d55 Compare September 4, 2024 04:36
Copy link
Member

@nickzelei nickzelei left a comment

Choose a reason for hiding this comment

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

Left a few questions...some things I don't quite understand maybe you could help with.

Also, it would be a good sanity check if you could also make sure this stuff all works with Dynamodb.
Some of the string slicing is a little scary to me and would just be nice tomake sure it all is working for both mongo and dynamo.

// we pass in an optional curr value so that we don't throw errors when searching for duplicates and the existing key is there
// for ex. if the initial value is "email" and we change it to "emaila" and then back to "email", it throws an error because the key set is made from all of the rows of the data which includes the original value, so we delete it if currValue is valid so we don't throw that error and allow the user to just save their current value without changing it
const isDuplicateKey = useCallback(
(newValue: string, schema: string, table: string, currValue?: string) => {
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem right to me.
I would expect a function called isDuplicateKey to be a signature similar to: function isDuplicateKey(key: string): boolean
or at most: isDuplicateKey(schema: string, table: string, key: string): string

So I'm pretty confused as to why there is a currValue and newValue here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking here is that if a user is trying to edit a mapping in line, then we have a newValue that we have to use as a key to check against the existing data to see if it's there. That value changes on every keystroke and it's not saved to the data object yet.

So we use the newValue to create a string that we can then check to see if it exists in the set. If it does, then we return true for the duplicate.

The currValue is optional here since it's only used for the inline mapping and is used to ensure that an existing mapping doesn't throw a value.

If the data object is: [{a.b.c},{d.e.f}], and the user clicks on the edit button, if we don't know what the currValue of the row that the user is trying to edit, then we throw an error if the user wants to not make any changes. For. ex. if the current row mapping is {a.b.c} and we want to edit this, the user makes a change to {a.b.t}, that works since that's not a mapping that exists. However, if the user, for whatever reason doesn't want to make the change and just wants to exist the mapping, then they will revert the mapping to {a.b.c} which will throw a duplicate error since that already exists.

So the currValue is used to prevent this case by deleting the mapping that the user is currently editing from the set so that it doesn't throw a duplicate error and the user can save the original mapping.

The other way we can fix this is to give the user a button to exit the editing process which will then end the editing process and not save the update. I didn't do that since it felt like too many buttons already in that small form.

Copy link
Member

Choose a reason for hiding this comment

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

I see your thinking.

However, this is really just an edge case when the newValue and currValue are equivalent for the existing collection right?

onDuplicate should be smart enough to know that for the current rowIndex being updated, if the values are the same, don't do anything.

onDuplicate could just not fire if it knows curValue === newValue.

Anyways, just a thought, maybe I'm missing something here, but my spidey senses tend to go off when I see mutations in functions that are just checking if something exists in a set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will handle this in a new PR and clean it up a little more

Copy link
Member

@nickzelei nickzelei left a comment

Choose a reason for hiding this comment

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

Overall the functionality is there but still have some thoughts around the handling of the onDuplicate and isDuplicate functions.

@evisdrenova evisdrenova merged commit b2c7658 into main Sep 5, 2024
6 checks passed
@evisdrenova evisdrenova deleted the duplicateMongoMappings branch September 5, 2024 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants