Commit 9f41b616 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner

Add edited timestamp to header component

parent 327c061a
...@@ -24,6 +24,9 @@ function AnnotationHeader({ ...@@ -24,6 +24,9 @@ function AnnotationHeader({
}) { }) {
const annotationLink = annotation.links ? annotation.links.html : ''; const annotationLink = annotation.links ? annotation.links.html : '';
const replyPluralized = !replyCount || replyCount > 1 ? 'replies' : 'reply'; const replyPluralized = !replyCount || replyCount > 1 ? 'replies' : 'reply';
// NB: `created` and `updated` are strings, not `Date`s
const hasBeenEdited =
annotation.updated && annotation.created !== annotation.updated;
return ( return (
<header className="annotation-header"> <header className="annotation-header">
...@@ -34,13 +37,26 @@ function AnnotationHeader({ ...@@ -34,13 +37,26 @@ function AnnotationHeader({
{replyCount} {replyPluralized} {replyCount} {replyPluralized}
</a> </a>
</div> </div>
{!isEditing && annotation.updated && ( {!isEditing && annotation.created && (
<div className="annotation-header__timestamp"> <div className="annotation-header__timestamp">
<Timestamp {hasBeenEdited && (
className="annotation-header__timestamp-link" <span className="annotation-header__timestamp-edited">
href={annotationLink} (edited{' '}
timestamp={annotation.updated} <Timestamp
/> className="annotation-header__timestamp-edited-link"
href={annotationLink}
timestamp={annotation.updated}
/>
){' '}
</span>
)}
<span className="annotation-header__timestamp-created">
<Timestamp
className="annotation-header__timestamp-created-link"
href={annotationLink}
timestamp={annotation.created}
/>
</span>
</div> </div>
)} )}
</div> </div>
......
...@@ -62,19 +62,46 @@ describe('AnnotationHeader', () => { ...@@ -62,19 +62,46 @@ describe('AnnotationHeader', () => {
); );
}); });
describe('timestamp', () => { describe('timestamps', () => {
it('should render a timestamp if annotation has an `updated` value', () => { it('should render timestamp container element if annotation has a `created` value', () => {
const wrapper = createAnnotationHeader(); const wrapper = createAnnotationHeader();
const timestamp = wrapper.find(Timestamp); const timestamp = wrapper.find('.annotation-header__timestamp');
assert.isTrue(timestamp.exists()); assert.isTrue(timestamp.exists());
}); });
it('should not render a timestamp if annotation does not have an `updated` value', () => { it('should not render timestamp container if annotation does not have a `created` value', () => {
const wrapper = createAnnotationHeader({ const wrapper = createAnnotationHeader({
annotation: fixtures.newAnnotation(), annotation: fixtures.newAnnotation(),
}); });
const timestamp = wrapper.find(Timestamp); const timestamp = wrapper.find('.annotation-header__timestamp');
assert.isFalse(timestamp.exists());
});
it('should render edited timestamp if annotation has been edited', () => {
const annotation = fixtures.defaultAnnotation();
annotation.updated = '2018-05-10T20:18:56.613388+00:00';
const wrapper = createAnnotationHeader({
annotation: annotation,
});
const timestamp = wrapper
.find(Timestamp)
.filter('.annotation-header__timestamp-edited-link');
assert.isTrue(timestamp.exists());
});
it('should not render edited timestamp if annotation has not been edited', () => {
// Default annotation's created value is same as updated; as if the annotation
// has not been edited before
const wrapper = createAnnotationHeader({
annotation: fixtures.newAnnotation(),
});
const timestamp = wrapper
.find(Timestamp)
.filter('.annotation-header__timestamp-edited-link');
assert.isFalse(timestamp.exists()); assert.isFalse(timestamp.exists());
}); });
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
function defaultAnnotation() { function defaultAnnotation() {
return { return {
id: 'deadbeef', id: 'deadbeef',
created: '2015-05-10T20:18:56.613388+00:00',
document: { document: {
title: 'A special document', title: 'A special document',
}, },
......
...@@ -10,12 +10,29 @@ ...@@ -10,12 +10,29 @@
align-items: baseline; align-items: baseline;
} }
// Timestamps are right aligned in a flex row
&__timestamp { &__timestamp {
margin-left: auto; margin-left: auto;
} }
&__timestamp-link { &__timestamp-edited {
@include font-small; @include font-small;
font-style: italic;
color: $grey-4;
}
&__timestamp-created-link,
&__timestamp-edited-link {
&:hover {
text-decoration: underline;
}
}
&__timestamp-created-link {
color: $grey-5;
}
&__timestamp-edited-link {
color: $grey-4; color: $grey-4;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment