Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
86382c83
Unverified
Commit
86382c83
authored
Jul 14, 2020
by
Kyle Keating
Committed by
GitHub
Jul 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve typechecking for util/ and services/ (#2315)
parent
360d308a
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
76 additions
and
34 deletions
+76
-34
analytics.js
src/sidebar/services/analytics.js
+10
-1
annotations.js
src/sidebar/services/annotations.js
+20
-9
api.js
src/sidebar/services/api.js
+2
-0
copy-to-clipboard.js
src/sidebar/util/copy-to-clipboard.js
+1
-0
dom.js
src/sidebar/util/dom.js
+1
-1
group-list-item-common.js
src/sidebar/util/group-list-item-common.js
+0
-4
group-list-item-common-test.js
src/sidebar/util/test/group-list-item-common-test.js
+0
-16
tsconfig.json
src/tsconfig.json
+1
-0
annotator.js
src/types/annotator.js
+34
-0
api.js
src/types/api.js
+7
-3
No files found.
src/sidebar/services/analytics.js
View file @
86382c83
...
@@ -34,7 +34,6 @@ export const events = {
...
@@ -34,7 +34,6 @@ export const events = {
* behavior across different environments in which the client is used.
* behavior across different environments in which the client is used.
*
*
* @param {Window} win
* @param {Window} win
* @param {Object} settings - Settings rendered into sidebar HTML
* @return {string}
* @return {string}
*/
*/
function
clientType
(
win
,
settings
=
{})
{
function
clientType
(
win
,
settings
=
{})
{
...
@@ -65,9 +64,18 @@ function clientType(win, settings = {}) {
...
@@ -65,9 +64,18 @@ function clientType(win, settings = {}) {
return
type
;
return
type
;
}
}
/**
* @typedef Analytics
* @prop {() => any} sendPageView
* @prop {(action: string, label?: string, value?: number) => void} track
* @prop {Object.<string, string>} events
*/
/**
/**
* Analytics service for tracking page views and user interactions with the
* Analytics service for tracking page views and user interactions with the
* application.
* application.
* @param {Window} $window - Test seam
* @return {Analytics}
*/
*/
// @ngInject
// @ngInject
export
default
function
analytics
(
$window
,
settings
)
{
export
default
function
analytics
(
$window
,
settings
)
{
...
@@ -78,6 +86,7 @@ export default function analytics($window, settings) {
...
@@ -78,6 +86,7 @@ export default function analytics($window, settings) {
// is replaced when analytics.js fully loads.
// is replaced when analytics.js fully loads.
//
//
// See https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference
// See https://developers.google.com/analytics/devguides/collection/analyticsjs/command-queue-reference
// @ts-ignore The window interface needs to be expanded to include this property
const
commandQueue
=
()
=>
$window
.
ga
||
noop
;
const
commandQueue
=
()
=>
$window
.
ga
||
noop
;
return
{
return
{
...
...
src/sidebar/services/annotations.js
View file @
86382c83
/** @typedef {import('../../types/api').Annotation} Annotation */
/** @typedef {import('../../types/annotator').AnnotationData} AnnotationData */
/**
/**
* A service for creating, manipulating and persisting annotations and their
* A service for creating, manipulating and persisting annotations and their
* application-store representations. Interacts with API services as needed.
* application-store representations. Interacts with API services as needed.
...
@@ -17,6 +20,8 @@ export default function annotationsService(api, store) {
...
@@ -17,6 +20,8 @@ export default function annotationsService(api, store) {
/**
/**
* Apply changes for the given `annotation` from its draft in the store (if
* Apply changes for the given `annotation` from its draft in the store (if
* any) and return a new object with those changes integrated.
* any) and return a new object with those changes integrated.
*
* @param {Annotation} annotation
*/
*/
function
applyDraftChanges
(
annotation
)
{
function
applyDraftChanges
(
annotation
)
{
const
changes
=
{};
const
changes
=
{};
...
@@ -36,6 +41,10 @@ export default function annotationsService(api, store) {
...
@@ -36,6 +41,10 @@ export default function annotationsService(api, store) {
/**
/**
* Extend new annotation objects with defaults and permissions.
* Extend new annotation objects with defaults and permissions.
*
* @param {AnnotationData} annotationData
* @param {Date} now
* @return {Annotation}
*/
*/
function
initialize
(
annotationData
,
now
=
new
Date
())
{
function
initialize
(
annotationData
,
now
=
new
Date
())
{
const
defaultPrivacy
=
store
.
getDefault
(
'annotationPrivacy'
);
const
defaultPrivacy
=
store
.
getDefault
(
'annotationPrivacy'
);
...
@@ -50,27 +59,29 @@ export default function annotationsService(api, store) {
...
@@ -50,27 +59,29 @@ export default function annotationsService(api, store) {
// as it has not been persisted to the service.
// as it has not been persisted to the service.
const
$tag
=
generateHexString
(
8
);
const
$tag
=
generateHexString
(
8
);
let
permissions
=
defaultPermissions
(
userid
,
groupid
,
defaultPrivacy
);
/** @type {Annotation} */
const
annotation
=
Object
.
assign
(
// Highlights are peculiar in that they always have private permissions
if
(
metadata
.
isHighlight
(
annotationData
))
{
permissions
=
privatePermissions
(
userid
);
}
return
Object
.
assign
(
{
{
created
:
now
.
toISOString
(),
created
:
now
.
toISOString
(),
group
:
groupid
,
group
:
groupid
,
permissions
,
permissions
:
defaultPermissions
(
userid
,
groupid
,
defaultPrivacy
)
,
tags
:
[],
tags
:
[],
text
:
''
,
text
:
''
,
updated
:
now
.
toISOString
(),
updated
:
now
.
toISOString
(),
user
:
userid
,
user
:
userid
,
user_info
:
userInfo
,
user_info
:
userInfo
,
$tag
:
$tag
,
$tag
:
$tag
,
hidden
:
false
,
links
:
{},
},
},
annotationData
annotationData
);
);
// Highlights are peculiar in that they always have private permissions
if
(
metadata
.
isHighlight
(
annotation
))
{
annotation
.
permissions
=
privatePermissions
(
userid
);
}
return
annotation
;
}
}
/**
/**
...
...
src/sidebar/services/api.js
View file @
86382c83
...
@@ -19,6 +19,8 @@ function translateResponseToError(response, data) {
...
@@ -19,6 +19,8 @@ function translateResponseToError(response, data) {
/**
/**
* Return a shallow clone of `obj` with all client-only properties removed.
* Return a shallow clone of `obj` with all client-only properties removed.
* Client-only properties are marked by a '$' prefix.
* Client-only properties are marked by a '$' prefix.
*
* @param {Object} obj
*/
*/
function
stripInternalProperties
(
obj
)
{
function
stripInternalProperties
(
obj
)
{
const
result
=
{};
const
result
=
{};
...
...
src/sidebar/util/copy-to-clipboard.js
View file @
86382c83
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
* @throws {Error}
* @throws {Error}
* This function may throw an exception if the browser rejects the attempt
* This function may throw an exception if the browser rejects the attempt
* to copy text.
* to copy text.
* @param {string} text
*/
*/
export
function
copyText
(
text
)
{
export
function
copyText
(
text
)
{
const
temp
=
document
.
createElement
(
'pre'
);
const
temp
=
document
.
createElement
(
'pre'
);
...
...
src/sidebar/util/dom.js
View file @
86382c83
...
@@ -31,7 +31,7 @@ export function getElementHeightWithMargins(element) {
...
@@ -31,7 +31,7 @@ export function getElementHeightWithMargins(element) {
* @param {string[]} events
* @param {string[]} events
* @param {EventListener} listener
* @param {EventListener} listener
* @param {Object} options
* @param {Object} options
* @param {boolean} [options.useCapture]
*
@param {boolean} [options.useCapture]
* @return {function} Function which removes the event listeners.
* @return {function} Function which removes the event listeners.
*/
*/
export
function
listen
(
element
,
events
,
listener
,
{
useCapture
=
false
}
=
{})
{
export
function
listen
(
element
,
events
,
listener
,
{
useCapture
=
false
}
=
{})
{
...
...
src/sidebar/util/group-list-item-common.js
View file @
86382c83
...
@@ -9,7 +9,3 @@
...
@@ -9,7 +9,3 @@
export
function
orgName
(
group
)
{
export
function
orgName
(
group
)
{
return
group
.
organization
&&
group
.
organization
.
name
;
return
group
.
organization
&&
group
.
organization
.
name
;
}
}
export
function
trackViewGroupActivity
(
analytics
)
{
analytics
.
track
(
analytics
.
events
.
GROUP_VIEW_ACTIVITY
);
}
src/sidebar/util/test/group-list-item-common-test.js
View file @
86382c83
import
{
events
}
from
'../../services/analytics'
;
import
*
as
groupListItemCommon
from
'../group-list-item-common'
;
import
*
as
groupListItemCommon
from
'../group-list-item-common'
;
describe
(
'sidebar/util/groupListItemCommon'
,
()
=>
{
describe
(
'sidebar/util/groupListItemCommon'
,
()
=>
{
describe
(
'trackViewGroupActivity'
,
()
=>
{
it
(
'triggers the GROUP_VIEW_ACTIVITY event when called'
,
()
=>
{
const
fakeAnalytics
=
{
track
:
sinon
.
stub
(),
events
,
};
groupListItemCommon
.
trackViewGroupActivity
(
fakeAnalytics
);
assert
.
calledWith
(
fakeAnalytics
.
track
,
fakeAnalytics
.
events
.
GROUP_VIEW_ACTIVITY
);
});
});
describe
(
'orgName'
,
()
=>
{
describe
(
'orgName'
,
()
=>
{
it
(
'returns the organization name if it exists'
,
()
=>
{
it
(
'returns the organization name if it exists'
,
()
=>
{
const
fakeGroup
=
{
id
:
'groupid'
,
organization
:
{
name
:
'org'
}
};
const
fakeGroup
=
{
id
:
'groupid'
,
organization
:
{
name
:
'org'
}
};
...
...
src/tsconfig.json
View file @
86382c83
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
"sidebar/store/create-store.js"
,
"sidebar/store/create-store.js"
,
"sidebar/store/debug-middleware.js"
,
"sidebar/store/debug-middleware.js"
,
"sidebar/store/use-store.js"
,
"sidebar/store/use-store.js"
,
"sidebar/store/utils.js"
,
],
],
"exclude"
:
[
"exclude"
:
[
...
...
src/types/annotator.js
0 → 100644
View file @
86382c83
/**
* Type definitions for objects passed between the annotator and sidebar.
*/
/** @typedef {import("./api").Target} Target */
/**
* @typedef AnnotationData
* @prop {string} uri
* @prop {Target[]} target
* @prop {string} $tag
* @prop {boolean} [$highlight]
* @prop {DocumentMetadata} document
*/
/**
* @typedef DocumentMetadata
* @prop {string} title
* @prop {Object[]} link
* @prop {string} link.rel
* @prop {string} link.type
* // html pages
* @prop {Object.<string, string[]>} [dc]
* @prop {Object.<string, string[]>} [eprints]
* @prop {Object.<string, string[]>} [facebook]
* @prop {Object.<string, string[]>} [highwire]
* @prop {Object.<string, string[]>} [prism]
* @prop {Object.<string, string[]>} [twitter]
* // pdf files
* @prop {string} [documentFingerprint]
*/
// Make TypeScript treat this file as a module.
export
const
unused
=
{};
src/types/api.js
View file @
86382c83
...
@@ -33,6 +33,12 @@
...
@@ -33,6 +33,12 @@
* @typedef {TextQuoteSelector | TextPositionSelector | RangeSelector} Selector
* @typedef {TextQuoteSelector | TextPositionSelector | RangeSelector} Selector
*/
*/
/**
* @typedef Target
* @prop {string} source
* @prop {Selector[]} [selector]
*
/**
/**
* TODO - Fill out remaining properties
* TODO - Fill out remaining properties
*
*
...
@@ -58,9 +64,7 @@
...
@@ -58,9 +64,7 @@
* @prop {string[]} permissions.update
* @prop {string[]} permissions.update
* @prop {string[]} permissions.delete
* @prop {string[]} permissions.delete
*
*
* @prop {Object[]} target
* @prop {Target[]} target
* @prop {string} target.source
* @prop {Selector[]} [target.selector]
*
*
* @prop {Object} [moderation]
* @prop {Object} [moderation]
* @prop {number} moderation.flagCount
* @prop {number} moderation.flagCount
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment