Commit afa82e46 authored by Robert Knight's avatar Robert Knight

Display document segment information in Help panel

parent c82457bf
...@@ -70,6 +70,11 @@ function VersionInfo({ toastMessenger, versionData }) { ...@@ -70,6 +70,11 @@ function VersionInfo({ toastMessenger, versionData }) {
<VersionInfoItem label="Fingerprint"> <VersionInfoItem label="Fingerprint">
{versionData.fingerprint} {versionData.fingerprint}
</VersionInfoItem> </VersionInfoItem>
{versionData.segment && (
<VersionInfoItem label="Segment">
{versionData.segment}
</VersionInfoItem>
)}
<VersionInfoItem label="Account">{versionData.account}</VersionInfoItem> <VersionInfoItem label="Account">{versionData.account}</VersionInfoItem>
<VersionInfoItem label="Date">{versionData.timestamp}</VersionInfoItem> <VersionInfoItem label="Date">{versionData.timestamp}</VersionInfoItem>
</dl> </dl>
......
...@@ -61,7 +61,20 @@ describe('VersionInfo', () => { ...@@ -61,7 +61,20 @@ describe('VersionInfo', () => {
assert.include(componentText, 'fakeFingerprint'); assert.include(componentText, 'fakeFingerprint');
assert.include(componentText, 'fakeAccount'); assert.include(componentText, 'fakeAccount');
assert.include(componentText, 'fakeTimestamp'); 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', () => { describe('copy version info to clipboard', () => {
it('copies version info to clipboard when copy button clicked', () => { it('copies version info to clipboard when copy button clicked', () => {
const wrapper = createComponent(); const wrapper = createComponent();
......
...@@ -80,6 +80,18 @@ describe('sidebar/helpers/version-data', () => { ...@@ -80,6 +80,18 @@ describe('sidebar/helpers/version-data', () => {
]); ]);
assert.equal(versionData.fingerprint, 'DEADBEEF'); 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);
});
}); });
}); });
......
/**
* @typedef {import('../../types/annotator').SegmentInfo} SegmentInfo
*/
/** /**
* @typedef AuthState * @typedef AuthState
* @prop {string|null} [userid] * @prop {string|null} [userid]
...@@ -17,6 +21,7 @@ ...@@ -17,6 +21,7 @@
* @typedef DocumentInfo * @typedef DocumentInfo
* @prop {string=} [uri] - Current document URL * @prop {string=} [uri] - Current document URL
* @prop {DocMetadata} [metadata] - Document metadata * @prop {DocMetadata} [metadata] - Document metadata
* @prop {SegmentInfo} [segment]
*/ */
export class VersionData { export class VersionData {
...@@ -47,6 +52,21 @@ export class VersionData { ...@@ -47,6 +52,21 @@ export class VersionData {
this.account = accountString; this.account = accountString;
this.timestamp = new Date().toString(); 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(', ');
}
} }
/** /**
......
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