Commit 20a0ff01 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Rename and adjust callbacks for clarity

* `onSetPrivacy` => `onSetPrivate`
* internal `onEditTags` takes `tags` instead of `{ tags }`
parent 60246db2
...@@ -57,7 +57,7 @@ function AnnotationEditor({ ...@@ -57,7 +57,7 @@ function AnnotationEditor({
const isEmpty = !text && !tags.length; const isEmpty = !text && !tags.length;
const onEditTags = useCallback( const onEditTags = useCallback(
({ tags }) => { tags => {
store.createDraft(draft.annotation, { ...draft, tags }); store.createDraft(draft.annotation, { ...draft, tags });
}, },
[draft, store] [draft, store]
...@@ -78,7 +78,7 @@ function AnnotationEditor({ ...@@ -78,7 +78,7 @@ function AnnotationEditor({
const tagList = [...tags, newTag]; const tagList = [...tags, newTag];
// Update the tag locally for the suggested-tag list // Update the tag locally for the suggested-tag list
tagsService.store(tagList); tagsService.store(tagList);
onEditTags({ tags: tagList }); onEditTags(tagList);
return true; return true;
}, },
[onEditTags, tags, tagsService] [onEditTags, tags, tagsService]
...@@ -96,7 +96,7 @@ function AnnotationEditor({ ...@@ -96,7 +96,7 @@ function AnnotationEditor({
const index = newTagList.indexOf(tag); const index = newTagList.indexOf(tag);
if (index >= 0) { if (index >= 0) {
newTagList.splice(index, 1); newTagList.splice(index, 1);
onEditTags({ tags: newTagList }); onEditTags(newTagList);
return true; return true;
} }
return false; return false;
...@@ -114,9 +114,12 @@ function AnnotationEditor({ ...@@ -114,9 +114,12 @@ function AnnotationEditor({
/** /**
* @param {boolean} isPrivate * @param {boolean} isPrivate
*/ */
const onSetPrivacy = useCallback( const onSetPrivate = useCallback(
isPrivate => { isPrivate => {
store.createDraft(annotation, { ...draft, isPrivate }); store.createDraft(annotation, {
...draft,
isPrivate,
});
// Persist this as privacy default for future annotations unless this is a reply // Persist this as privacy default for future annotations unless this is a reply
if (!isReply(annotation)) { if (!isReply(annotation)) {
store.setDefault('annotationPrivacy', isPrivate ? 'private' : 'shared'); store.setDefault('annotationPrivacy', isPrivate ? 'private' : 'shared');
...@@ -189,7 +192,7 @@ function AnnotationEditor({ ...@@ -189,7 +192,7 @@ function AnnotationEditor({
isPrivate={draft.isPrivate} isPrivate={draft.isPrivate}
onCancel={onCancel} onCancel={onCancel}
onSave={onSave} onSave={onSave}
onSetPrivacy={onSetPrivacy} onSetPrivate={onSetPrivate}
/> />
)} )}
</div> </div>
......
...@@ -20,7 +20,7 @@ import MenuItem from '../MenuItem'; ...@@ -20,7 +20,7 @@ import MenuItem from '../MenuItem';
* @prop {boolean} isPrivate - Annotation or draft is "Only Me" * @prop {boolean} isPrivate - Annotation or draft is "Only Me"
* @prop {() => void} onCancel - Callback for cancel button click * @prop {() => void} onCancel - Callback for cancel button click
* @prop {() => void} onSave - Callback for save button click * @prop {() => void} onSave - Callback for save button click
* @prop {(isPrivate: boolean) => void} onSetPrivacy - Callback for save button click * @prop {(isPrivate: boolean) => void} onSetPrivate - Callback for save button click
* @prop {SidebarSettings} settings - Injected service * @prop {SidebarSettings} settings - Injected service
*/ */
...@@ -37,7 +37,7 @@ function AnnotationPublishControl({ ...@@ -37,7 +37,7 @@ function AnnotationPublishControl({
isPrivate, isPrivate,
onCancel, onCancel,
onSave, onSave,
onSetPrivacy, onSetPrivate,
settings, settings,
}) { }) {
const buttonStyle = applyTheme( const buttonStyle = applyTheme(
...@@ -98,13 +98,13 @@ function AnnotationPublishControl({ ...@@ -98,13 +98,13 @@ function AnnotationPublishControl({
icon={group.type === 'open' ? 'public' : 'groups'} icon={group.type === 'open' ? 'public' : 'groups'}
label={group.name} label={group.name}
isSelected={!isPrivate} isSelected={!isPrivate}
onClick={() => onSetPrivacy(false)} onClick={() => onSetPrivate(false)}
/> />
<MenuItem <MenuItem
icon="lock" icon="lock"
label="Only Me" label="Only Me"
isSelected={isPrivate} isSelected={isPrivate}
onClick={() => onSetPrivacy(true)} onClick={() => onSetPrivate(true)}
/> />
</Menu> </Menu>
</div> </div>
......
...@@ -269,7 +269,7 @@ describe('AnnotationEditor', () => { ...@@ -269,7 +269,7 @@ describe('AnnotationEditor', () => {
draft.isPrivate = false; draft.isPrivate = false;
const wrapper = createComponent({ draft }); const wrapper = createComponent({ draft });
wrapper.find('AnnotationPublishControl').props().onSetPrivacy(true); wrapper.find('AnnotationPublishControl').props().onSetPrivate(true);
const call = fakeStore.createDraft.getCall(0); const call = fakeStore.createDraft.getCall(0);
...@@ -280,7 +280,7 @@ describe('AnnotationEditor', () => { ...@@ -280,7 +280,7 @@ describe('AnnotationEditor', () => {
it("updates the draft's privacy when set to shared", () => { it("updates the draft's privacy when set to shared", () => {
const wrapper = createComponent(); const wrapper = createComponent();
wrapper.find('AnnotationPublishControl').props().onSetPrivacy(false); wrapper.find('AnnotationPublishControl').props().onSetPrivate(false);
const call = fakeStore.createDraft.getCall(0); const call = fakeStore.createDraft.getCall(0);
...@@ -291,7 +291,7 @@ describe('AnnotationEditor', () => { ...@@ -291,7 +291,7 @@ describe('AnnotationEditor', () => {
it('updates privacy default setting', () => { it('updates privacy default setting', () => {
const wrapper = createComponent(); const wrapper = createComponent();
wrapper.find('AnnotationPublishControl').props().onSetPrivacy(false); wrapper.find('AnnotationPublishControl').props().onSetPrivate(false);
assert.calledOnce(fakeStore.setDefault); assert.calledOnce(fakeStore.setDefault);
assert.calledWith( assert.calledWith(
...@@ -305,7 +305,7 @@ describe('AnnotationEditor', () => { ...@@ -305,7 +305,7 @@ describe('AnnotationEditor', () => {
fakeMetadata.isReply.returns(true); fakeMetadata.isReply.returns(true);
const wrapper = createComponent(); const wrapper = createComponent();
wrapper.find('AnnotationPublishControl').props().onSetPrivacy(false); wrapper.find('AnnotationPublishControl').props().onSetPrivate(false);
assert.notCalled(fakeStore.setDefault); assert.notCalled(fakeStore.setDefault);
}); });
......
...@@ -14,7 +14,7 @@ describe('AnnotationPublishControl', () => { ...@@ -14,7 +14,7 @@ describe('AnnotationPublishControl', () => {
let fakeOnSave; let fakeOnSave;
let fakeOnCancel; let fakeOnCancel;
let fakeOnSetPrivacy; let fakeOnSetPrivate;
const createAnnotationPublishControl = (props = {}) => { const createAnnotationPublishControl = (props = {}) => {
return mount( return mount(
...@@ -24,7 +24,7 @@ describe('AnnotationPublishControl', () => { ...@@ -24,7 +24,7 @@ describe('AnnotationPublishControl', () => {
isPrivate={false} isPrivate={false}
onCancel={fakeOnCancel} onCancel={fakeOnCancel}
onSave={fakeOnSave} onSave={fakeOnSave}
onSetPrivacy={fakeOnSetPrivacy} onSetPrivate={fakeOnSetPrivate}
settings={fakeSettings} settings={fakeSettings}
{...props} {...props}
/> />
...@@ -34,7 +34,7 @@ describe('AnnotationPublishControl', () => { ...@@ -34,7 +34,7 @@ describe('AnnotationPublishControl', () => {
beforeEach(() => { beforeEach(() => {
fakeOnCancel = sinon.stub(); fakeOnCancel = sinon.stub();
fakeOnSave = sinon.stub(); fakeOnSave = sinon.stub();
fakeOnSetPrivacy = sinon.stub(); fakeOnSetPrivate = sinon.stub();
fakeGroup = { fakeGroup = {
name: 'Fake Group', name: 'Fake Group',
type: 'private', type: 'private',
...@@ -131,8 +131,8 @@ describe('AnnotationPublishControl', () => { ...@@ -131,8 +131,8 @@ describe('AnnotationPublishControl', () => {
shareMenuItem.prop('onClick')(); shareMenuItem.prop('onClick')();
assert.calledOnce(fakeOnSetPrivacy); assert.calledOnce(fakeOnSetPrivate);
assert.calledWith(fakeOnSetPrivacy, false); assert.calledWith(fakeOnSetPrivate, false);
}); });
context('private group', () => { context('private group', () => {
...@@ -165,8 +165,8 @@ describe('AnnotationPublishControl', () => { ...@@ -165,8 +165,8 @@ describe('AnnotationPublishControl', () => {
shareMenuItem.prop('onClick')(); shareMenuItem.prop('onClick')();
assert.calledOnce(fakeOnSetPrivacy); assert.calledOnce(fakeOnSetPrivate);
assert.calledWith(fakeOnSetPrivacy, true); assert.calledWith(fakeOnSetPrivate, true);
}); });
it('should use a private/lock icon', () => { it('should use a private/lock icon', () => {
......
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