Commit 4b52f7c4 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner

Make `AnnotationShareInfo` derive privacy within component

Stop passing value of `Annotation.state.isPrivate()` through
`AnnotationHeader` all the way to `AnnotationShareInfo` and
instead compute that within `AnnotationShareInfo` itself.
parent 5c87c784
...@@ -16,7 +16,6 @@ function AnnotationHeader({ ...@@ -16,7 +16,6 @@ function AnnotationHeader({
annotation, annotation,
isEditing, isEditing,
isHighlight, isHighlight,
isPrivate,
onReplyCountClick, onReplyCountClick,
replyCount, replyCount,
showDocumentInfo, showDocumentInfo,
...@@ -60,7 +59,7 @@ function AnnotationHeader({ ...@@ -60,7 +59,7 @@ function AnnotationHeader({
</div> </div>
<div className="annotation-header__row"> <div className="annotation-header__row">
<AnnotationShareInfo annotation={annotation} isPrivate={isPrivate} /> <AnnotationShareInfo annotation={annotation} />
{!isEditing && isHighlight && ( {!isEditing && isHighlight && (
<div className="annotation-header__highlight"> <div className="annotation-header__highlight">
<SvgIcon <SvgIcon
...@@ -84,8 +83,6 @@ AnnotationHeader.propTypes = { ...@@ -84,8 +83,6 @@ AnnotationHeader.propTypes = {
isEditing: propTypes.bool, isEditing: propTypes.bool,
/* Whether the annotation is a highlight */ /* Whether the annotation is a highlight */
isHighlight: propTypes.bool, isHighlight: propTypes.bool,
/* Whether the annotation is an "only me" (private) annotation */
isPrivate: propTypes.bool,
/* Callback for when the toggle-replies element is clicked */ /* Callback for when the toggle-replies element is clicked */
onReplyCountClick: propTypes.func.isRequired, onReplyCountClick: propTypes.func.isRequired,
/* How many replies this annotation currently has */ /* How many replies this annotation currently has */
......
const propTypes = require('prop-types'); const propTypes = require('prop-types');
const { createElement } = require('preact'); const { createElement } = require('preact');
const SvgIcon = require('./svg-icon'); const { withServices } = require('../util/service-context');
const useStore = require('../store/use-store'); const useStore = require('../store/use-store');
const SvgIcon = require('./svg-icon');
/** /**
* Render information about what group an annotation is in and * Render information about what group an annotation is in and
* whether it is private to the current user (only me) * whether it is private to the current user (only me)
*/ */
function AnnotationShareInfo({ annotation, isPrivate }) { function AnnotationShareInfo({ annotation, permissions }) {
const group = useStore(store => store.getGroup(annotation.group)); const group = useStore(store => store.getGroup(annotation.group));
// We may not have access to the group object beyond its ID // We may not have access to the group object beyond its ID
...@@ -19,6 +20,11 @@ function AnnotationShareInfo({ annotation, isPrivate }) { ...@@ -19,6 +20,11 @@ function AnnotationShareInfo({ annotation, isPrivate }) {
// URL (link) returned by the API for this group. Some groups do not have links // URL (link) returned by the API for this group. Some groups do not have links
const linkToGroup = hasGroup && group.links && group.links.html; const linkToGroup = hasGroup && group.links && group.links.html;
const isPrivate = !permissions.isShared(
annotation.permissions,
annotation.user
);
return ( return (
<div className="annotation-share-info"> <div className="annotation-share-info">
{linkToGroup && ( {linkToGroup && (
...@@ -59,8 +65,11 @@ function AnnotationShareInfo({ annotation, isPrivate }) { ...@@ -59,8 +65,11 @@ function AnnotationShareInfo({ annotation, isPrivate }) {
AnnotationShareInfo.propTypes = { AnnotationShareInfo.propTypes = {
/** The current annotation object for which sharing info will be rendered */ /** The current annotation object for which sharing info will be rendered */
annotation: propTypes.object.isRequired, annotation: propTypes.object.isRequired,
/** Is this an "only me" (private) annotation? */
isPrivate: propTypes.bool.isRequired, /** injected services */
permissions: propTypes.object.isRequired,
}; };
module.exports = AnnotationShareInfo; AnnotationShareInfo.injectedProps = ['permissions'];
module.exports = withServices(AnnotationShareInfo);
...@@ -13,7 +13,6 @@ describe('AnnotationHeader', () => { ...@@ -13,7 +13,6 @@ describe('AnnotationHeader', () => {
annotation={fixtures.defaultAnnotation()} annotation={fixtures.defaultAnnotation()}
isEditing={false} isEditing={false}
isHighlight={false} isHighlight={false}
isPrivate={false}
onReplyCountClick={sinon.stub()} onReplyCountClick={sinon.stub()}
replyCount={0} replyCount={0}
showDocumentInfo={false} showDocumentInfo={false}
......
...@@ -10,12 +10,13 @@ describe('AnnotationShareInfo', () => { ...@@ -10,12 +10,13 @@ describe('AnnotationShareInfo', () => {
let fakeGroup; let fakeGroup;
let fakeStore; let fakeStore;
let fakeGetGroup; let fakeGetGroup;
let fakePermissions;
const createAnnotationShareInfo = props => { const createAnnotationShareInfo = props => {
return mount( return mount(
<AnnotationShareInfo <AnnotationShareInfo
annotation={fixtures.defaultAnnotation()} annotation={fixtures.defaultAnnotation()}
isPrivate={false} permissions={fakePermissions}
{...props} {...props}
/> />
); );
...@@ -31,6 +32,9 @@ describe('AnnotationShareInfo', () => { ...@@ -31,6 +32,9 @@ describe('AnnotationShareInfo', () => {
}; };
fakeGetGroup = sinon.stub().returns(fakeGroup); fakeGetGroup = sinon.stub().returns(fakeGroup);
fakeStore = { getGroup: fakeGetGroup }; fakeStore = { getGroup: fakeGetGroup };
fakePermissions = {
isShared: sinon.stub().returns(true),
};
AnnotationShareInfo.$imports.$mock(mockImportedComponents()); AnnotationShareInfo.$imports.$mock(mockImportedComponents());
AnnotationShareInfo.$imports.$mock({ AnnotationShareInfo.$imports.$mock({
...@@ -96,15 +100,19 @@ describe('AnnotationShareInfo', () => { ...@@ -96,15 +100,19 @@ describe('AnnotationShareInfo', () => {
describe('"only you" information', () => { describe('"only you" information', () => {
it('should not show privacy information if annotation is not private', () => { it('should not show privacy information if annotation is not private', () => {
const wrapper = createAnnotationShareInfo({ isPrivate: false }); const wrapper = createAnnotationShareInfo();
const privacy = wrapper.find('.annotation-share-info__private'); const privacy = wrapper.find('.annotation-share-info__private');
assert.notOk(privacy.exists()); assert.notOk(privacy.exists());
}); });
context('private annotation', () => { context('private annotation', () => {
beforeEach(() => {
fakePermissions.isShared.returns(false);
});
it('should show privacy icon', () => { it('should show privacy icon', () => {
const wrapper = createAnnotationShareInfo({ isPrivate: true }); const wrapper = createAnnotationShareInfo();
const privacyIcon = wrapper.find( const privacyIcon = wrapper.find(
'.annotation-share-info__private .annotation-share-info__icon' '.annotation-share-info__private .annotation-share-info__icon'
...@@ -114,7 +122,7 @@ describe('AnnotationShareInfo', () => { ...@@ -114,7 +122,7 @@ describe('AnnotationShareInfo', () => {
assert.equal(privacyIcon.prop('name'), 'lock'); assert.equal(privacyIcon.prop('name'), 'lock');
}); });
it('should not show "only me" text for first-party group', () => { it('should not show "only me" text for first-party group', () => {
const wrapper = createAnnotationShareInfo({ isPrivate: true }); const wrapper = createAnnotationShareInfo();
const privacyText = wrapper.find( const privacyText = wrapper.find(
'.annotation-share-info__private-info' '.annotation-share-info__private-info'
...@@ -124,7 +132,7 @@ describe('AnnotationShareInfo', () => { ...@@ -124,7 +132,7 @@ describe('AnnotationShareInfo', () => {
}); });
it('should show "only me" text for annotation in third-party group', () => { it('should show "only me" text for annotation in third-party group', () => {
fakeGetGroup.returns({ name: 'Some Name' }); fakeGetGroup.returns({ name: 'Some Name' });
const wrapper = createAnnotationShareInfo({ isPrivate: true }); const wrapper = createAnnotationShareInfo();
const privacyText = wrapper.find( const privacyText = wrapper.find(
'.annotation-share-info__private-info' '.annotation-share-info__private-info'
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
<annotation-header annotation="vm.annotation" <annotation-header annotation="vm.annotation"
is-editing="vm.editing()" is-editing="vm.editing()"
is-highlight="vm.isHighlight()" is-highlight="vm.isHighlight()"
is-private="vm.state().isPrivate"
on-reply-count-click="vm.onReplyCountClick()" on-reply-count-click="vm.onReplyCountClick()"
reply-count="vm.replyCount" reply-count="vm.replyCount"
show-document-info="vm.showDocumentInfo"> show-document-info="vm.showDocumentInfo">
...@@ -41,7 +40,7 @@ ...@@ -41,7 +40,7 @@
ng-if="vm.editing()" ng-if="vm.editing()"
annotation="vm.annotation" annotation="vm.annotation"
on-edit-tags="vm.setTags(tags)" on-edit-tags="vm.setTags(tags)"
tag-list="vm.state().tags" tag-list="vm.state().tags"
/> />
</tag-editor> </tag-editor>
......
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