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

Added useEuiTextDiff hook #3288

Merged
merged 59 commits into from
Jun 5, 2020
Merged

Added useEuiTextDiff hook #3288

merged 59 commits into from
Jun 5, 2020

Conversation

anishagg17
Copy link
Contributor

@anishagg17 anishagg17 commented Apr 9, 2020

Summary

stepping towards #1896

Created useEuiTextDiff component, hook based on text-diff which renders comparison of initial and final text to the user

Can take in timeout , customElement renderer as prop to enhance experience.

Screenshots

Screenshot 2020-05-20 at 7 49 00 PM

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in IE11 and Firefox
  • Props have proper autodocs
  • Added documentation examples
  • Added or updated jest tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@anishagg17
Copy link
Contributor Author

@miukimiu I don't know why euiColourSecondary isn't being applied to <ins> tag

at the same time euiColourDanger works for <del> tag

@miukimiu
Copy link
Contributor

miukimiu commented Apr 9, 2020

jenkins test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3288/

@chandlerprall chandlerprall self-assigned this Apr 17, 2020
@chandlerprall
Copy link
Contributor

chandlerprall commented Apr 22, 2020

To test, I've benchmarked diff, text-diff, fast-diff, and heckel-diff. The first three are all based on the algorithm presented in An O(ND) Difference Algorithm and Its Variations (Myers, 1986) while heckel-diff implements A technique for isolating differences between files (Heckel, 1978). Each library returns the same type of output, but heckel-diff is not as precise with its change boundaries.

benchmarks

  1. two word difference in a one-line sentence
  2. handfull of line deletions/modifications in a ~100 line file, simulating removing of a component's prop
  3. replacing a 108 line TSX file with a 43 line SCSS file
  4. adding a ~30 line comment to a 749 line TSX file

results
(times in ms, each test case+library combination ran 100 times)

case 0			avg	min	max
	diff		0	0	1
	textdiff	0	0	1
	fastdiff	0	0	1
	heckeldiff	0	0	1

case 1			avg	min	max
	diff		4	4	8
	textdiff	0	0	0
	fastdiff	0	0	0
	heckeldiff	1	1	3

case 2			avg	min	max
	diff		1363	1223	1964
	textdiff	41	37	86
	fastdiff	40	35	185
	heckeldiff	2	1	5

case 3			avg	min	max
	diff		336	319	511
	textdiff	0	0	0
	fastdiff	0	0	0
	heckeldiff	17	16	23

interpretations

  • diff's performance is terrible
  • heckel-diff is imperceptibly slower for a single diff in non-pathological cases, and substantially faster in pathological cases
  • text-diff and fast-diff average to the same, but text-diff has the faster warm-up/initial execution time

Given those results, my consideration is between text-diff and heckel-diff. Given that text-diff is faster in the general cases and has more accurate results, that library is my choice. It also happens to be the one already implemented in this PR. 🎉

Next I'll start reviewing the implementation of EuiTextDiff

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Thanks for your patience! I've run through and added some thoughts, but I really like how you've set it up.

src/components/code/_code_block.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
@anishagg17
Copy link
Contributor Author

anishagg17 commented Apr 30, 2020

the text is updated when the timeout condition is met, it also triggers when timeout is changed but the initialText doesn't retain the state and that's why no further changes are observed on changing the slider

src/components/code/index.ts Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Couple more things, and once Caroline's done with the design pass will take a last review of the docs side.

src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text_diff.tsx Outdated Show resolved Hide resolved
src/components/code/text-diff.d.ts Outdated Show resolved Hide resolved
@chandlerprall
Copy link
Contributor

I've updated the Checklist in the description, remaining items are a changelog entry and couple jest snapshots:

  • snapshot using the default props
  • second snapshot with the three custom components
  • both snapshot tests should set timeout to 0 so we don't introduce any flakiness

/cc @cchaos if you want to take any more passes at this

@cchaos
Copy link
Contributor

cchaos commented Jun 4, 2020

@anishagg17 My final review is PR4U: anishagg17#11

- Adding prop comments
- Fixing text contrast
- Adding snippets
- Added “NEW” badge
@cchaos
Copy link
Contributor

cchaos commented Jun 4, 2020

Oh and don't forget a changelog entry!

@anishagg17
Copy link
Contributor Author

Screenshot 2020-06-05 at 3 05 38 PM

I am getting such errors while rendering the test

@cchaos
Copy link
Contributor

cchaos commented Jun 5, 2020

retest

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3288/

@anishagg17
Copy link
Contributor Author

@cchaos I am really sorry to say that I forgot to push the snaps and updated test file. Now, the tests are working fine and snaps are updated.

@cchaos
Copy link
Contributor

cchaos commented Jun 5, 2020

No worries! I'll rerun.

Jenkins, test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3288/

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Woohoo! Changes LGTM!

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

🎉 Awesome job! LGTM with a small CL change.

CHANGELOG.md Outdated Show resolved Hide resolved
anishagg17 and others added 2 commits June 5, 2020 18:40
Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
@chandlerprall chandlerprall merged commit e03e961 into elastic:master Jun 5, 2020
@anishagg17 anishagg17 deleted the text branch June 5, 2020 20:35
@anishagg17 anishagg17 changed the title Added EuiTextDiff component Added useEuiTextDiff hook Jun 5, 2020
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3288/

@thompsongl
Copy link
Contributor

Congrats on getting this merged, @anishagg17 🎉

@anishagg17
Copy link
Contributor Author

Thank you very much 🚀

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.

6 participants