Skip to content

Commit 20a0ff0

Browse files
committed
Rename and adjust callbacks for clarity
* `onSetPrivacy` => `onSetPrivate` * internal `onEditTags` takes `tags` instead of `{ tags }`
1 parent 60246db commit 20a0ff0

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

src/sidebar/components/Annotation/AnnotationEditor.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function AnnotationEditor({
5757
const isEmpty = !text && !tags.length;
5858

5959
const onEditTags = useCallback(
60-
({ tags }) => {
60+
tags => {
6161
store.createDraft(draft.annotation, { ...draft, tags });
6262
},
6363
[draft, store]
@@ -78,7 +78,7 @@ function AnnotationEditor({
7878
const tagList = [...tags, newTag];
7979
// Update the tag locally for the suggested-tag list
8080
tagsService.store(tagList);
81-
onEditTags({ tags: tagList });
81+
onEditTags(tagList);
8282
return true;
8383
},
8484
[onEditTags, tags, tagsService]
@@ -96,7 +96,7 @@ function AnnotationEditor({
9696
const index = newTagList.indexOf(tag);
9797
if (index >= 0) {
9898
newTagList.splice(index, 1);
99-
onEditTags({ tags: newTagList });
99+
onEditTags(newTagList);
100100
return true;
101101
}
102102
return false;
@@ -114,9 +114,12 @@ function AnnotationEditor({
114114
/**
115115
* @param {boolean} isPrivate
116116
*/
117-
const onSetPrivacy = useCallback(
117+
const onSetPrivate = useCallback(
118118
isPrivate => {
119-
store.createDraft(annotation, { ...draft, isPrivate });
119+
store.createDraft(annotation, {
120+
...draft,
121+
isPrivate,
122+
});
120123
// Persist this as privacy default for future annotations unless this is a reply
121124
if (!isReply(annotation)) {
122125
store.setDefault('annotationPrivacy', isPrivate ? 'private' : 'shared');
@@ -189,7 +192,7 @@ function AnnotationEditor({
189192
isPrivate={draft.isPrivate}
190193
onCancel={onCancel}
191194
onSave={onSave}
192-
onSetPrivacy={onSetPrivacy}
195+
onSetPrivate={onSetPrivate}
193196
/>
194197
)}
195198
</div>

src/sidebar/components/Annotation/AnnotationPublishControl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import MenuItem from '../MenuItem';
2020
* @prop {boolean} isPrivate - Annotation or draft is "Only Me"
2121
* @prop {() => void} onCancel - Callback for cancel button click
2222
* @prop {() => void} onSave - Callback for save button click
23-
* @prop {(isPrivate: boolean) => void} onSetPrivacy - Callback for save button click
23+
* @prop {(isPrivate: boolean) => void} onSetPrivate - Callback for save button click
2424
* @prop {SidebarSettings} settings - Injected service
2525
*/
2626

@@ -37,7 +37,7 @@ function AnnotationPublishControl({
3737
isPrivate,
3838
onCancel,
3939
onSave,
40-
onSetPrivacy,
40+
onSetPrivate,
4141
settings,
4242
}) {
4343
const buttonStyle = applyTheme(
@@ -98,13 +98,13 @@ function AnnotationPublishControl({
9898
icon={group.type === 'open' ? 'public' : 'groups'}
9999
label={group.name}
100100
isSelected={!isPrivate}
101-
onClick={() => onSetPrivacy(false)}
101+
onClick={() => onSetPrivate(false)}
102102
/>
103103
<MenuItem
104104
icon="lock"
105105
label="Only Me"
106106
isSelected={isPrivate}
107-
onClick={() => onSetPrivacy(true)}
107+
onClick={() => onSetPrivate(true)}
108108
/>
109109
</Menu>
110110
</div>

src/sidebar/components/Annotation/test/AnnotationEditor-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ describe('AnnotationEditor', () => {
269269
draft.isPrivate = false;
270270
const wrapper = createComponent({ draft });
271271

272-
wrapper.find('AnnotationPublishControl').props().onSetPrivacy(true);
272+
wrapper.find('AnnotationPublishControl').props().onSetPrivate(true);
273273

274274
const call = fakeStore.createDraft.getCall(0);
275275

@@ -280,7 +280,7 @@ describe('AnnotationEditor', () => {
280280
it("updates the draft's privacy when set to shared", () => {
281281
const wrapper = createComponent();
282282

283-
wrapper.find('AnnotationPublishControl').props().onSetPrivacy(false);
283+
wrapper.find('AnnotationPublishControl').props().onSetPrivate(false);
284284

285285
const call = fakeStore.createDraft.getCall(0);
286286

@@ -291,7 +291,7 @@ describe('AnnotationEditor', () => {
291291
it('updates privacy default setting', () => {
292292
const wrapper = createComponent();
293293

294-
wrapper.find('AnnotationPublishControl').props().onSetPrivacy(false);
294+
wrapper.find('AnnotationPublishControl').props().onSetPrivate(false);
295295

296296
assert.calledOnce(fakeStore.setDefault);
297297
assert.calledWith(
@@ -305,7 +305,7 @@ describe('AnnotationEditor', () => {
305305
fakeMetadata.isReply.returns(true);
306306
const wrapper = createComponent();
307307

308-
wrapper.find('AnnotationPublishControl').props().onSetPrivacy(false);
308+
wrapper.find('AnnotationPublishControl').props().onSetPrivate(false);
309309

310310
assert.notCalled(fakeStore.setDefault);
311311
});

src/sidebar/components/Annotation/test/AnnotationPublishControl-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('AnnotationPublishControl', () => {
1414

1515
let fakeOnSave;
1616
let fakeOnCancel;
17-
let fakeOnSetPrivacy;
17+
let fakeOnSetPrivate;
1818

1919
const createAnnotationPublishControl = (props = {}) => {
2020
return mount(
@@ -24,7 +24,7 @@ describe('AnnotationPublishControl', () => {
2424
isPrivate={false}
2525
onCancel={fakeOnCancel}
2626
onSave={fakeOnSave}
27-
onSetPrivacy={fakeOnSetPrivacy}
27+
onSetPrivate={fakeOnSetPrivate}
2828
settings={fakeSettings}
2929
{...props}
3030
/>
@@ -34,7 +34,7 @@ describe('AnnotationPublishControl', () => {
3434
beforeEach(() => {
3535
fakeOnCancel = sinon.stub();
3636
fakeOnSave = sinon.stub();
37-
fakeOnSetPrivacy = sinon.stub();
37+
fakeOnSetPrivate = sinon.stub();
3838
fakeGroup = {
3939
name: 'Fake Group',
4040
type: 'private',
@@ -131,8 +131,8 @@ describe('AnnotationPublishControl', () => {
131131

132132
shareMenuItem.prop('onClick')();
133133

134-
assert.calledOnce(fakeOnSetPrivacy);
135-
assert.calledWith(fakeOnSetPrivacy, false);
134+
assert.calledOnce(fakeOnSetPrivate);
135+
assert.calledWith(fakeOnSetPrivate, false);
136136
});
137137

138138
context('private group', () => {
@@ -165,8 +165,8 @@ describe('AnnotationPublishControl', () => {
165165

166166
shareMenuItem.prop('onClick')();
167167

168-
assert.calledOnce(fakeOnSetPrivacy);
169-
assert.calledWith(fakeOnSetPrivacy, true);
168+
assert.calledOnce(fakeOnSetPrivate);
169+
assert.calledWith(fakeOnSetPrivate, true);
170170
});
171171

172172
it('should use a private/lock icon', () => {

0 commit comments

Comments
 (0)