Commit f6a2d4a9 authored by Kyle Keating's avatar Kyle Keating Committed by Kyle Keating

Improve typecheck (annotation-publish-control, annotation-share-control)

parent d4164c52
...@@ -12,11 +12,26 @@ import Menu from './menu'; ...@@ -12,11 +12,26 @@ import Menu from './menu';
import MenuItem from './menu-item'; import MenuItem from './menu-item';
import SvgIcon from '../../shared/components/svg-icon'; import SvgIcon from '../../shared/components/svg-icon';
/**
* @typedef {import('../../types/api').Annotation} Annotation
* @typedef {import('../../types/config').MergedConfig} MergedConfig
*/
/**
* @typedef AnnotationPublishControlProps
* @prop {Annotation} annotation
* @prop {boolean} [isDisabled]
* - Should the save button be disabled? Hint: it will be if the annotation has no content
* @prop {() => any} onSave - Callback for save button click
* @prop {MergedConfig} settings - Injected service
*/
/** /**
* Render a compound control button for publishing (saving) an annotation: * Render a compound control button for publishing (saving) an annotation:
* - Save the annotation — left side of button * - Save the annotation — left side of button
* - Choose sharing/privacy option - drop-down menu on right side of button * - Choose sharing/privacy option - drop-down menu on right side of button
* *
* @param {AnnotationPublishControlProps} props
*/ */
function AnnotationPublishControl({ function AnnotationPublishControl({
annotation, annotation,
...@@ -32,6 +47,12 @@ function AnnotationPublishControl({ ...@@ -32,6 +47,12 @@ function AnnotationPublishControl({
const setDefault = useStore(store => store.setDefault); const setDefault = useStore(store => store.setDefault);
const removeAnnotations = useStore(store => store.removeAnnotations); const removeAnnotations = useStore(store => store.removeAnnotations);
if (!group) {
// If there is no group, then don't render anything as a missing group
// may mean the group is not loaded yet.
return null;
}
const isPrivate = draft ? draft.isPrivate : !isShared(annotation.permissions); const isPrivate = draft ? draft.isPrivate : !isShared(annotation.permissions);
const publishDestination = isPrivate ? 'Only Me' : group.name; const publishDestination = isPrivate ? 'Only Me' : group.name;
...@@ -114,17 +135,8 @@ function AnnotationPublishControl({ ...@@ -114,17 +135,8 @@ function AnnotationPublishControl({
AnnotationPublishControl.propTypes = { AnnotationPublishControl.propTypes = {
annotation: propTypes.object.isRequired, annotation: propTypes.object.isRequired,
/**
* Should the save button be disabled?
* Hint: it will be if the annotation has no content
*/
isDisabled: propTypes.bool, isDisabled: propTypes.bool,
/** Callback for save button click */
onSave: propTypes.func.isRequired, onSave: propTypes.func.isRequired,
/** services */
settings: propTypes.object.isRequired, settings: propTypes.object.isRequired,
}; };
......
...@@ -11,8 +11,27 @@ import useElementShouldClose from './hooks/use-element-should-close'; ...@@ -11,8 +11,27 @@ import useElementShouldClose from './hooks/use-element-should-close';
import ShareLinks from './share-links'; import ShareLinks from './share-links';
import SvgIcon from '../../shared/components/svg-icon'; import SvgIcon from '../../shared/components/svg-icon';
/**
* @typedef {import('../../types/api').Annotation} Annotation
* @typedef {import('../../types/api').Group} Group
*/
/**
* @typedef AnnotationShareControlProps
* @prop {Annotation} annotation - The annotation in question
* @prop {Group} [group] -
* Group that the annotation is in. If missing, this component will not render.
* FIXME: Refactor after root cause is addressed.
* See https://github.com/hypothesis/client/issues/1542
* @prop {string} shareUri - The URI to view the annotation on its own
* @prop {Object} analytics - Injected service
* @prop {Object} toastMessenger - Injected service
*/
/** /**
* "Popup"-style component for sharing a single annotation. * "Popup"-style component for sharing a single annotation.
*
* @param {AnnotationShareControlProps} props
*/ */
function AnnotationShareControl({ function AnnotationShareControl({
annotation, annotation,
...@@ -135,18 +154,9 @@ function AnnotationShareControl({ ...@@ -135,18 +154,9 @@ function AnnotationShareControl({
} }
AnnotationShareControl.propTypes = { AnnotationShareControl.propTypes = {
/* The annotation in question */
annotation: propTypes.object.isRequired, annotation: propTypes.object.isRequired,
/** group that the annotation is in
* If missing, this component will not render
* FIXME: Refactor after root cause is addressed
* See https://github.com/hypothesis/client/issues/1542
*/
group: propTypes.object, group: propTypes.object,
/** The URI to view the annotation on its own */
shareUri: propTypes.string.isRequired, shareUri: propTypes.string.isRequired,
/* services */
analytics: propTypes.object.isRequired, analytics: propTypes.object.isRequired,
toastMessenger: propTypes.object.isRequired, toastMessenger: propTypes.object.isRequired,
}; };
......
...@@ -70,6 +70,12 @@ describe('AnnotationPublishControl', () => { ...@@ -70,6 +70,12 @@ describe('AnnotationPublishControl', () => {
$imports.$restore(); $imports.$restore();
}); });
it('should not render if group is missing', () => {
fakeStore.getGroup.returns(undefined);
const wrapper = createAnnotationPublishControl();
assert.isFalse(wrapper.find('.annotation-publish-control').exists());
});
describe('theming', () => { describe('theming', () => {
it('should apply theme styles', () => { it('should apply theme styles', () => {
const fakeStyle = { foo: 'bar' }; const fakeStyle = { foo: 'bar' };
......
...@@ -33,9 +33,7 @@ ...@@ -33,9 +33,7 @@
// Remove them from this list as they are resolved. // Remove them from this list as they are resolved.
"sidebar/components/hooks/use-root-thread.js", "sidebar/components/hooks/use-root-thread.js",
"sidebar/components/annotation-header.js", "sidebar/components/annotation-header.js",
"sidebar/components/annotation-publish-control.js",
"sidebar/components/annotation-quote.js", "sidebar/components/annotation-quote.js",
"sidebar/components/annotation-share-control.js",
"sidebar/components/annotation-share-info.js", "sidebar/components/annotation-share-info.js",
"sidebar/components/annotation-viewer-content.js", "sidebar/components/annotation-viewer-content.js",
"sidebar/components/annotation.js", "sidebar/components/annotation.js",
......
...@@ -118,6 +118,7 @@ ...@@ -118,6 +118,7 @@
* @prop {string} logo * @prop {string} logo
* @prop {boolean} isMember * @prop {boolean} isMember
* @prop {boolean} isScopedToUri * @prop {boolean} isScopedToUri
* @prop {string} name
* @prop {boolean} canLeave * @prop {boolean} canLeave
*/ */
......
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