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

Don't show edited timestamps if annotations haven't been updated #2690

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

lyzadanger
Copy link
Contributor

Previously, the AnnotationHeader component checked the equivalency
of annotation.created and annotation.updated to determine if an
annotation had been updated subsequent to its creation. This is
problematic if an annotation has a very small difference between its
created and updated dates.

created and updated are returned by the API as ISO-8601 date strings
with microsecond resolution. These days, annotations created by the h
service will have exactly equivalent created and updated timestamps
(assuming they haven't actually been edited subsequently, of course). In
the past, however, annotations often had negligible (sub-second)
differences in their created and updated dates. This resulted in
an edited timestamp misleadingly appearing in the UI for older
annotations.

These changes add a hasBeenEdited function to the
annotation-metadata util module that considers an annotation edited
only if created and updated differ by at least 2 seconds.

Tests for annotation-metadata have also been modernized somewhat here. (This makes the diff look way bigger than it "is").

Fixes #2684

@lyzadanger
Copy link
Contributor Author

@robertknight I hand-edited my local DB to reproduce this issue for development. Let me know if you'd like to reproduce locally and/or would be assisted by any instructions.

@codecov
Copy link

codecov bot commented Oct 30, 2020

Codecov Report

Merging #2690 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2690   +/-   ##
=======================================
  Coverage   97.73%   97.73%           
=======================================
  Files         199      199           
  Lines        7506     7518   +12     
  Branches     1647     1651    +4     
=======================================
+ Hits         7336     7348   +12     
  Misses        170      170           
Impacted Files Coverage Δ
src/sidebar/components/annotation-header.js 100.00% <100.00%> (ø)
src/sidebar/util/annotation-metadata.js 99.10% <100.00%> (+0.10%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da5286b...870a607. Read the comment docs.

@lyzadanger
Copy link
Contributor Author

CI coverage fail because I touched tests in annotation-metadata but did not improve coverage there (I'd presume). I'll take a quick look at coverage for that module and see if it can be improved without fuss. Otherwise I'll leave it for now.

@lyzadanger lyzadanger marked this pull request as draft October 30, 2020 13:25
@lyzadanger
Copy link
Contributor Author

Converting to draft while I make sure that my try/catch handling for Date parsing isn't totally whacko (I think it may be).

@lyzadanger lyzadanger force-pushed the fix-edited-timestamp branch from 1bc46d7 to 8989935 Compare October 30, 2020 13:32
@lyzadanger
Copy link
Contributor Author

lyzadanger commented Oct 30, 2020

Updated. Date's constructor won't throw on string-parsing problems, but instead will return an Invalid Date object. Seems like the most straightforward way to sanity-check it is to check that .getTime() returns a number... I'm a little rusty on Date munging without the crutch of a library, as you see.

Addressing this also cleared up the code coverage fail.

@lyzadanger lyzadanger marked this pull request as ready for review October 30, 2020 13:34
Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

Hi Lyza,

The high-level change makes sense, I had some recommendations around caching the hasBeenEdited calculation, streamlining/simplifying the hasBeenEdited implementation and updating some weird variable names in the tests while you're modernizing that code.

Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

(Edit: I posted a review twice by mistake. Please see the comments above)

@lyzadanger lyzadanger force-pushed the fix-edited-timestamp branch from 8989935 to a5fd5a7 Compare November 2, 2020 14:05
Previously, the `AnnotationHeader` component checked the equivalency
of `annotation.created` and `annotation.updated` to determine if an
annotation had been updated subsequent to its creation. This is
problematic if an annotation has a very small difference between its
`created` and `updated` dates.

`created` and `updated` are returned by the API as ISO-8601 date strings
with microsecond resolution. These days, annotations created by the `h`
service will have exactly equivalent `created` and `updated` timestamps
(assuming they haven't actually been edited subsequently, of course). In
the past, however, annotations often had negligible (sub-second)
differences in their `created` and `updated` dates. This resulted in
an edited timestamp misleadingly appearing in the UI for older
annotations.

These changes add a `hasBeenEdited` function to the
`annotation-metadata` util module that considers an annotation edited
only if `created` and `updated` differ by at least 2 seconds.

Tests for `annotation-metadata` have also been modernized somewhat here.

Fixes #2684
Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

LGTM

assert.isFalse(annotationMetadata.hasBeenEdited(annotation));
});

it('should return false if created and updated are different but problematic', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it('should return false if created and updated are different but problematic', () => {
it('should return false if created and updated are different but cannot be parsed', () => {

I think it is useful to be more specific about what "problematic" means here.

@lyzadanger lyzadanger merged commit 81a45e4 into master Nov 2, 2020
@lyzadanger lyzadanger deleted the fix-edited-timestamp branch November 2, 2020 16:44
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.

Don't show edited timestamps for annotations that have never been edited
2 participants