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
d6a2e965
Commit
d6a2e965
authored
Jun 12, 2019
by
Lyza Danger Gardner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert `help-link` component to preact
- Add tests
parent
7c539fc1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
17 deletions
+132
-17
help-link.js
src/sidebar/components/help-link.js
+50
-12
help-link-test.js
src/sidebar/components/test/help-link-test.js
+78
-0
index.js
src/sidebar/index.js
+4
-1
help-link.html
src/sidebar/templates/help-link.html
+0
-4
No files found.
src/sidebar/components/help-link.js
View file @
d6a2e965
'use strict'
;
module
.
exports
=
{
controllerAs
:
'vm'
,
template
:
require
(
'../templates/help-link.html'
),
controller
:
function
()
{},
scope
:
{
version
:
'<'
,
userAgent
:
'<'
,
url
:
'<'
,
documentFingerprint
:
'<'
,
auth
:
'<'
,
dateTime
:
'<'
,
},
const
propTypes
=
require
(
'prop-types'
);
const
{
createElement
}
=
require
(
'preact'
);
/**
* Render an HTML link for sending an email to Hypothes.is support. This link
* pre-populates the email body with various details about the app's state.
*/
function
HelpLink
({
auth
,
dateTime
,
documentFingerprint
=
'-'
,
url
,
userAgent
,
version
,
})
{
const
toAddress
=
'support@hypothes.is'
;
const
subject
=
encodeURIComponent
(
'Hypothesis Support'
);
const
username
=
auth
.
username
?
auth
.
username
:
'-'
;
// URL-encode informational key-value pairs for the email's body content
const
bodyAttrs
=
[
`Version:
${
version
}
`
,
`User Agent:
${
userAgent
}
`
,
`URL:
${
url
}
`
,
`PDF Fingerprint:
${
documentFingerprint
}
`
,
`Date:
${
dateTime
}
`
,
`Username:
${
username
}
`
,
].
map
(
x
=>
encodeURIComponent
(
x
));
// Create a pre-populated email body with each key-value pair on its own line
const
body
=
bodyAttrs
.
join
(
encodeURIComponent
(
'
\
r
\
n'
));
const
href
=
`mailto:
${
toAddress
}
?subject=
${
subject
}
&body=
${
body
}
`
;
return
(
<
a
className
=
"help-panel-content__link"
href
=
{
href
}
>
Send
us
an
email
<
/a
>
);
}
HelpLink
.
propTypes
=
{
auth
:
propTypes
.
object
.
isRequired
,
dateTime
:
propTypes
.
object
.
isRequired
,
documentFingerprint
:
propTypes
.
string
,
url
:
propTypes
.
string
,
userAgent
:
propTypes
.
string
.
isRequired
,
version
:
propTypes
.
string
.
isRequired
,
};
module
.
exports
=
HelpLink
;
src/sidebar/components/test/help-link-test.js
0 → 100644
View file @
d6a2e965
'use strict'
;
const
{
createElement
}
=
require
(
'preact'
);
const
{
shallow
}
=
require
(
'enzyme'
);
const
HelpLink
=
require
(
'../help-link'
);
describe
(
'Help (mailto) Link'
,
()
=>
{
let
fakeAuth
;
let
fakeDateTime
;
let
fakeDocumentFingerprint
;
let
fakeUrl
;
let
fakeUserAgent
;
let
fakeVersion
;
const
createHelpLink
=
()
=>
{
return
shallow
(
<
HelpLink
auth
=
{
fakeAuth
}
dateTime
=
{
fakeDateTime
}
documentFingerprint
=
{
fakeDocumentFingerprint
}
url
=
{
fakeUrl
}
userAgent
=
{
fakeUserAgent
}
version
=
{
fakeVersion
}
/
>
);
};
beforeEach
(()
=>
{
fakeAuth
=
{
username
:
'fiona.user'
,
};
fakeDateTime
=
new
Date
();
fakeDocumentFingerprint
=
'fingerprint'
;
fakeUrl
=
'http://www.example.com'
;
fakeUserAgent
=
'Some User Agent'
;
fakeVersion
=
'1.0.0'
;
});
it
(
'sets required props as part of formatted email body'
,
()
=>
{
const
wrapper
=
createHelpLink
();
const
href
=
wrapper
.
find
(
'a'
).
prop
(
'href'
);
[
{
label
:
'Version'
,
value
:
fakeVersion
},
{
label
:
'User Agent'
,
value
:
fakeUserAgent
},
{
label
:
'URL'
,
value
:
fakeUrl
},
{
label
:
'PDF Fingerprint'
,
value
:
fakeDocumentFingerprint
},
{
label
:
'Date'
,
value
:
fakeDateTime
},
{
label
:
'Username'
,
value
:
fakeAuth
.
username
},
].
forEach
(
helpInfo
=>
{
const
emailBodyPart
=
encodeURIComponent
(
`
${
helpInfo
.
label
}
:
${
helpInfo
.
value
}
`
);
assert
.
include
(
href
,
emailBodyPart
);
});
});
it
(
'sets a default value for PDF document fingerprint if not provided'
,
()
=>
{
fakeDocumentFingerprint
=
undefined
;
const
wrapper
=
createHelpLink
();
const
href
=
wrapper
.
find
(
'a'
).
prop
(
'href'
);
const
emailBodyPart
=
encodeURIComponent
(
'PDF Fingerprint: -'
);
assert
.
include
(
href
,
emailBodyPart
);
});
it
(
'sets a default value for username if no authenticated user'
,
()
=>
{
fakeAuth
=
{};
const
wrapper
=
createHelpLink
();
const
href
=
wrapper
.
find
(
'a'
).
prop
(
'href'
);
const
emailBodyPart
=
encodeURIComponent
(
'Username: -'
);
assert
.
include
(
href
,
emailBodyPart
);
});
});
src/sidebar/index.js
View file @
d6a2e965
...
...
@@ -163,7 +163,10 @@ function startAngularApp(config) {
'groupListV2'
,
wrapReactComponent
(
require
(
'./components/group-list-v2'
))
)
.
component
(
'helpLink'
,
require
(
'./components/help-link'
))
.
component
(
'helpLink'
,
wrapReactComponent
(
require
(
'./components/help-link'
))
)
.
component
(
'helpPanel'
,
require
(
'./components/help-panel'
))
.
component
(
'loggedoutMessage'
,
require
(
'./components/loggedout-message'
))
.
component
(
'loginControl'
,
require
(
'./components/login-control'
))
...
...
src/sidebar/templates/help-link.html
deleted
100644 → 0
View file @
7c539fc1
<a
class=
"help-panel-content__link"
href=
"mailto:support@hypothes.is?subject=Hypothesis%20support&body=Version:%20{{ vm.version }}%0D%0AUser%20Agent:%20{{vm.userAgent}}%0D%0AURL:%20{{ vm.url }}%0D%0APDF%20fingerprint:%20{{ vm.documentFingerprint ? vm.documentFingerprint : '-' }}%0D%0AUsername:%20{{ vm.auth.username ? vm.auth.username : '-' }}%0D%0ADate:%20{{ vm.dateTime | date:'dd MMM yyyy HH:mm:ss Z' }} "
>
Send us an email
</a>
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