-
Notifications
You must be signed in to change notification settings - Fork 636
/
project-dashboard.jsx
85 lines (79 loc) · 3.58 KB
/
project-dashboard.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
/**
* @license Copyright 2019 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
import {h} from 'preact';
import {route} from 'preact-router';
import _ from '@lhci/utils/src/lodash.js';
import {useProjectBuilds, useProjectBySlug} from '../../hooks/use-api-data';
import {AsyncLoader, combineLoadingStates, combineAsyncData} from '../../components/async-loader';
import {ProjectGettingStarted} from './getting-started.jsx';
import {Page} from '../../layout/page.jsx';
import {ProjectGraphs} from './project-graphs.jsx';
import './project-dashboard.css';
import {Pill} from '../../components/pill';
import {DocumentTitle} from '../../components/document-title';
/** @param {{project: LHCI.ServerCommand.Project, builds: Array<LHCI.ServerCommand.Build>, runUrl?: string, branch?: string}} props */
const ProjectDashboard_ = props => {
const {project, builds} = props;
return (
<div className="dashboard">
<DocumentTitle title={`${project.name} Dashboard`} />
<div className="dashboard__recent-activity">
<h2>{project.name}</h2>
<div className="dashboard__build-list-scroll-container">
<table className="dashboard__build-list">
{builds.slice(0, 5).map(build => {
return (
<tr
key={build.id}
onClick={() =>
route(`/app/projects/${project.slug}/compare/${_.shortId(build.id)}`)
}
>
<td className="build-list__hash" data-tooltip={build.author}>
<Pill avatar={build}>{build.hash.slice(0, 8)}</Pill>
</td>
<td className="build-list__commit">{build.commitMessage}</td>
<td className="build-list__branch">
<div className="flex-row">
<i className="material-icons">call_split</i>
{build.branch}
</div>
</td>
<td className="build-list__date">
{new Date(build.runAt).toDateString().replace(/\w+ (.*) \d{4}/, '$1')}{' '}
{new Date(build.runAt).toLocaleTimeString().replace(/:\d{2} /, ' ')}
</td>
</tr>
);
})}
</table>
</div>
</div>
<ProjectGraphs {...props} />
</div>
);
};
/** @param {{projectSlug: string, runUrl?: string, branch?: string}} props */
export const ProjectDashboard = props => {
const projectApiData = useProjectBySlug(props.projectSlug);
const projectId = projectApiData[1] && projectApiData[1].id;
const projectBuildData = useProjectBuilds(projectId);
return (
<Page>
<AsyncLoader
loadingState={combineLoadingStates(projectApiData, projectBuildData)}
asyncData={combineAsyncData(projectApiData, projectBuildData)}
render={([project, builds]) =>
builds.length ? (
<ProjectDashboard_ project={project} builds={builds} {...props} />
) : (
<ProjectGettingStarted project={project} />
)
}
/>
</Page>
);
};