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