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
afa82e46
Commit
afa82e46
authored
Nov 02, 2022
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display document segment information in Help panel
parent
c82457bf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
0 deletions
+50
-0
VersionInfo.js
src/sidebar/components/VersionInfo.js
+5
-0
VersionInfo-test.js
src/sidebar/components/test/VersionInfo-test.js
+13
-0
version-data-test.js
src/sidebar/helpers/test/version-data-test.js
+12
-0
version-data.js
src/sidebar/helpers/version-data.js
+20
-0
No files found.
src/sidebar/components/VersionInfo.js
View file @
afa82e46
...
...
@@ -70,6 +70,11 @@ function VersionInfo({ toastMessenger, versionData }) {
<
VersionInfoItem
label
=
"Fingerprint"
>
{
versionData
.
fingerprint
}
<
/VersionInfoItem
>
{
versionData
.
segment
&&
(
<
VersionInfoItem
label
=
"Segment"
>
{
versionData
.
segment
}
<
/VersionInfoItem
>
)}
<
VersionInfoItem
label
=
"Account"
>
{
versionData
.
account
}
<
/VersionInfoItem
>
<
VersionInfoItem
label
=
"Date"
>
{
versionData
.
timestamp
}
<
/VersionInfoItem
>
<
/dl
>
...
...
src/sidebar/components/test/VersionInfo-test.js
View file @
afa82e46
...
...
@@ -61,7 +61,20 @@ describe('VersionInfo', () => {
assert
.
include
(
componentText
,
'fakeFingerprint'
);
assert
.
include
(
componentText
,
'fakeAccount'
);
assert
.
include
(
componentText
,
'fakeTimestamp'
);
// No `segment` property is set on the `versionData` prop by default, so
// the "Segment" field should not be displayed.
assert
.
notInclude
(
componentText
,
'Segment'
);
});
it
(
'renders segment info if `versionData.segment` is set'
,
()
=>
{
fakeVersionData
.
segment
=
'CFI: /2, URL: /chapters/foo.xhtml'
;
const
wrapper
=
createComponent
();
const
componentText
=
wrapper
.
text
();
assert
.
include
(
componentText
,
'Segment'
);
assert
.
include
(
componentText
,
'CFI: /2, URL: /chapters/foo.xhtml'
);
});
describe
(
'copy version info to clipboard'
,
()
=>
{
it
(
'copies version info to clipboard when copy button clicked'
,
()
=>
{
const
wrapper
=
createComponent
();
...
...
src/sidebar/helpers/test/version-data-test.js
View file @
afa82e46
...
...
@@ -80,6 +80,18 @@ describe('sidebar/helpers/version-data', () => {
]);
assert
.
equal
(
versionData
.
fingerprint
,
'DEADBEEF'
);
});
it
(
'sets `segment` property if `segment` is present in frame details'
,
()
=>
{
const
versionData
=
new
VersionData
({},
[
{
segment
:
{
cfi
:
'/2'
,
url
:
'/chapters/02.xhtml'
}
},
]);
assert
.
equal
(
versionData
.
segment
,
'CFI: /2, URL: /chapters/02.xhtml'
);
});
it
(
'does not set `segment` property if `segment` is not present in frame details'
,
()
=>
{
const
versionData
=
new
VersionData
({},
[]);
assert
.
isUndefined
(
versionData
.
segment
);
});
});
});
...
...
src/sidebar/helpers/version-data.js
View file @
afa82e46
/**
* @typedef {import('../../types/annotator').SegmentInfo} SegmentInfo
*/
/**
* @typedef AuthState
* @prop {string|null} [userid]
...
...
@@ -17,6 +21,7 @@
* @typedef DocumentInfo
* @prop {string=} [uri] - Current document URL
* @prop {DocMetadata} [metadata] - Document metadata
* @prop {SegmentInfo} [segment]
*/
export
class
VersionData
{
...
...
@@ -47,6 +52,21 @@ export class VersionData {
this
.
account
=
accountString
;
this
.
timestamp
=
new
Date
().
toString
();
const
segmentInfo
=
documentInfo
[
0
]?.
segment
;
if
(
segmentInfo
)
{
const
segmentFields
=
[];
if
(
segmentInfo
.
cfi
)
{
segmentFields
.
push
([
'CFI'
,
segmentInfo
.
cfi
]);
}
if
(
segmentInfo
.
url
)
{
segmentFields
.
push
([
'URL'
,
segmentInfo
.
url
]);
}
this
.
segment
=
segmentFields
.
map
(([
field
,
value
])
=>
`
${
field
}
:
${
value
}
`
)
.
join
(
', '
);
}
}
/**
...
...
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