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

objectDifference.ts - enhancements and fixes; Unit test - Jest; #36

Conversation

gswierczynski
Copy link

@gswierczynski gswierczynski commented Jul 9, 2023

objectDifference.ts - support for removal from link/block lists;
objectDifference.ts - support for change resulting in empty link/block list;
objectDifference.ts - fix bug from version 2.4.5 (isArray called with origObj instead of value);
Add unit tests for objectDifference.ts;
Add unit testing framework - jest;
Update typescript to 5.1.6;

Addresses #35 among other things.

Version 2.4.5 introduced a bug that is causing script not to fire in multiple situations (isArray called with origObj instead of value).

Here's an update to objectDifferences.ts that addresses that.
I rewrote the function to additionally add support for moments when elements are being deleted from list (be that blocks or ref links).
Added Jest Unit Test framework and wrote a couple of unit tests for the difference function.

I am not a java script developer so I might not be following some insider best practices.

Please let me know if something should be corrected or adjusted.

objectDifference.ts - support for change resulting in empty link/block list;
objectDifference.ts - fix bug from version 2.4.5 (isArray called with origObj instead of value);
Add unit tests for objectDifference.ts;
Add unit testing framework - jest;
Update typescript to 5.1.6;
@hatched-grzegorz
Copy link
Contributor

I am still noticing some undesired behavior in browser so further updates might be required (to the FieldExtension.tsx)

@hatched-grzegorz
Copy link
Contributor

Updated script triggering mechanism.

For each modified flattened path the code will be checked agains presence of the oldest ancestor from the modified path up to the level where field holding the script resides.

{
  computed_field
  text_field
  blocks {
    block_computed_field
    block_text_field
    inner_blocks {
      inner_block_text_field
    }
  }
}
compute field modified path code checked for presence of
computed_field textField textField
computed_field blocks.0.block_text blocks
block_computed_field textField ignored
block_computed_field blocks.0.block_text block_text
block_computed_field blocks.0.inner_blocks.0.inner_block_text_field inner_blocks

@velomovies
Copy link
Collaborator

@gswierczynski Thanks for the extensive PR.

I like the change in the object differences function, but I see some code style changes (like removed spaces or single/double quotes https://github.com/voorhoede/datocms-plugin-computed-fields/pull/36/files#diff-4ac47e410f008329ee7cbc652eb14e4fa23c06c36c411278561ac51e8108f225R1). Can you make sure that stays consistent?

I think we don't want to add unit testing in this PR. Since we have a lot of other plugins we want to keep them consistent. Next to a github action that tests the code we also want it to be implemented consistent to other plugins (like we did in this plugin: https://github.com/voorhoede/datocms-plugin-translate-fields/tree/main).

Is it okay if we cherry pick some test code and implement that in a different PR?

Next to that (just to have a small and clean PR) updating any packages I want to do in a seperate PR.

@gswierczynski
Copy link
Author

@velomovies Thank you for taking a look.

Totally understandable. On all points.

This Unit Test approach was just the first solution I found that helped me tinker with the implementation.

Code style changes sponsored by WebStorm - there's not much of it. I can adjust by hand.

By all means pick and choose from the tests into another PR with proper approach.

I will remove tests, style changes and package upgrade in this PR.

Removal of unit tests;
Removal of typescript upgrade;
Removal of package number update;
Revert package-lock.json;
@gswierczynski
Copy link
Author

@velomovies Cleaned up.
5466bba contains changelog entry with some formatted explanation if needed.

@velomovies
Copy link
Collaborator

Perfect, thank you! I will do a last check and merge it

@velomovies
Copy link
Collaborator

This is sufficient for now. When we add the testing library, I think we also want to have a seperate function for these lines: https://github.com/voorhoede/datocms-plugin-computed-fields/pull/36/files#diff-4ac47e410f008329ee7cbc652eb14e4fa23c06c36c411278561ac51e8108f225R54

Commenting this so we can reference it ;)

Thanks @gswierczynski. This will be merged and available in version 2.4.6

@velomovies velomovies merged commit 2ab7758 into voorhoede:main Jul 10, 2023
@velomovies velomovies mentioned this pull request Jul 10, 2023
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