-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathrecord-key.jsx
142 lines (121 loc) · 3.44 KB
/
record-key.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { action, observable } from 'mobx'
import { observer } from 'mobx-react'
import React, { Component } from 'react'
import ipc from '../lib/ipc'
import authStore from '../auth/auth-store'
import projectsApi from '../projects/projects-api'
const openDashboardProject = (project) => (e) => {
e.preventDefault()
ipc.externalOpen(`https://on.cypress.io/dashboard/projects/${project.id}`)
}
const openDashboardProjectSettings = (project) => (e) => {
e.preventDefault()
ipc.externalOpen(`https://on.cypress.io/dashboard/projects/${project.id}/settings`)
}
const openRecordKeyGuide = (e) => {
e.preventDefault()
ipc.externalOpen('https://on.cypress.io/what-is-a-record-key')
}
const showLogin = () => {
authStore.openLogin()
}
@observer
class RecordKey extends Component {
@observable key = null
@observable isLoading = false
componentDidMount () {
this.wasAuthenticated = authStore.isAuthenticated
this._loadKeys()
}
componentDidUpdate () {
// try to load keys again if not already loading, not already loading,
// and if user went from not authenticated to authenticated
if (
!this.isLoading &&
!this.key &&
(!this.wasAuthenticated && authStore.isAuthenticated)
) {
this._loadKeys()
}
this.wasAuthenticated = authStore.isAuthenticated
}
_loadKeys () {
this._setLoading(true)
projectsApi.getRecordKeys().then((keys = []) => {
this._setKey(keys[0])
this._setLoading(false)
})
}
@action _setLoading (isLoading) {
this.isLoading = isLoading
}
@action _setKey (key) {
if (key) this.key = key
}
render () {
const { project } = this.props
if (!project.isSetupForRecording) return null
return (
<div>
<a href='#' className='learn-more' onClick={openRecordKeyGuide}>
<i className='fa fa-info-circle'></i>{' '}
Learn More
</a>
<p className='text-muted'>
A Record Key sends your failing tests, screenshots, and videos to your{' '}
<a href='#' onClick={openDashboardProject(project)}>
Dashboard.
</a>
</p>
{this._key()}
</div>
)
}
_key () {
if (!authStore.isAuthenticated) {
return (
<p className='empty-well'>
You must be logged in to view the record key.<br />
<button
className='btn btn-primary'
onClick={showLogin}
>
<i className='fa fa-user'></i>{' '}
Log In
</button>
</p>
)
}
if (this.isLoading) {
return (
<p className='loading-record-keys'>
<i className='fa fa-spinner fa-spin'></i>{' '}
Loading Keys...
</p>
)
}
if (!this.key) {
return (
<p className='empty-well'>
This project has no record keys. <a href='#' onClick={openDashboardProjectSettings(this.props.project)}>Create one</a> on your Dashboard.
</p>
)
}
return (
<div>
<p className='text-muted'>
To record, run this command:
</p>
<p>
<pre><code>cypress run --record --key {this.key.id}</code></pre>
</p>
<p className='text-muted manage-btn'>
<a href='#' onClick={openDashboardProjectSettings(this.props.project)}>
<i className='fa fa-key'></i> You can change this key in the Dashboard
</a>
</p>
</div>
)
}
}
export default RecordKey