-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
project.jsx
88 lines (69 loc) · 2.28 KB
/
project.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
import React, { Component } from 'react'
import { observer } from 'mobx-react'
import Loader from 'react-loader'
import C from '../lib/constants'
import projectsApi from '../projects/projects-api'
import appStore from '../lib/app-store'
import viewStore from '../lib/view-store'
import ipc from '../lib/ipc'
import Settings from '../settings/settings'
import OnBoarding from './onboarding'
import ProjectNav from '../project-nav/project-nav'
import RunsList from '../runs/runs-list'
import SpecsList from '../specs/specs-list'
import ErrorMessage from './error-message'
import WarningMessage from './warning-message'
@observer
class Project extends Component {
componentDidMount () {
const { project } = this.props
project.setLoading(true)
document.title = appStore.isGlobalMode ? project.displayName : project.path
projectsApi.openProject(project)
}
componentWillUnmount () {
document.title = 'Cypress'
projectsApi.closeProject(this.props.project)
}
render () {
if (this.props.project.isLoading) return <Loader color='#888' scale={0.5}/>
if (this.props.project.error) return <ErrorMessage error={this.props.project.error} onTryAgain={this._reopenProject}/>
return (
<div>
<ProjectNav project={this.props.project}/>
<div className='project-content'>
{this._renderWarnings()}
{this._currentView()}
</div>
<OnBoarding project={this.props.project}/>
</div>
)
}
_externalOpen (e) {
e.preventDefault()
return ipc.externalOpen(e.target.href)
}
_currentView () {
switch (viewStore.currentView.name) {
case C.PROJECT_RUNS:
return <RunsList project={this.props.project} />
case C.PROJECT_SETTINGS:
return <Settings project={this.props.project} app={this.props.app}/>
default:
return <SpecsList project={this.props.project} />
}
}
_renderWarnings = () => {
const { warnings } = this.props.project
return warnings.map((warning, i) =>
(<WarningMessage key={i} warning={warning} onClearWarning={() => this._removeWarning(warning)}/>)
)
}
_removeWarning = (warning) => {
this.props.project.clearWarning(warning)
}
_reopenProject = () => {
projectsApi.reopenProject(this.props.project)
}
}
export default Project