Skip to content

Commit 9d582e4

Browse files
authored
Merge pull request #277 from zbynek/dependencies-tab
Put dependencies in their own tab
2 parents 1007d43 + 8f6fc75 commit 9d582e4

File tree

4 files changed

+51
-53
lines changed

4 files changed

+51
-53
lines changed

src/components/PluginDependencies.jsx

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import {Link} from 'gatsby';
44
import {Modal, ModalHeader, ModalBody} from 'reactstrap';
5-
const sortFunc = (a, b) => a.implied === b.implied ? (a.optional === b.optional ? 0 : a.optional ? 1 : -1 ) : (a.implied ? 1 : -1);
65

76
function PluginDependencies({dependencies} ) {
87
const [isShowImplied, setShowImplied] = React.useState(false);
@@ -14,10 +13,24 @@ function PluginDependencies({dependencies} ) {
1413
if (!dependencies || dependencies.length === 0) {
1514
return (<div className="empty">No dependencies found</div>);
1615
}
17-
16+
const optionalDependencies = dependencies.filter(dep => dep.optional);
17+
const impliedDependencies = dependencies.filter(dep => dep.implied && !dep.optional);
18+
const requiredDependencies = dependencies.filter(dep => !dep.implied && !dep.optional);
19+
const dependencyLink = (dependency) => {
20+
return (
21+
<div key={dependency.name} className="implied">
22+
<Link to={`/${dependency.name}/`}>
23+
{dependency.title}
24+
{' ≥ '}
25+
{dependency.version}
26+
</Link>
27+
</div>
28+
);
29+
};
1830
return (
1931
<>
20-
<Modal placement="bottom" isOpen={isShowImplied} target="pluginDependancies" toggle={toggleShowImplied}>
32+
<h1>Dependencies</h1>
33+
<Modal placement="bottom" isOpen={isShowImplied} target="pluginDependencies" toggle={toggleShowImplied}>
2134
<ModalHeader toggle={toggleShowImplied}>About Implied Plugin Dependencies</ModalHeader >
2235
<ModalBody>
2336
<div>
@@ -39,47 +52,34 @@ function PluginDependencies({dependencies} ) {
3952
</div>
4053
</ModalBody>
4154
</Modal>
42-
<div id="pluginDependancies">
55+
<div id="pluginDependencies">
56+
{
57+
!(optionalDependencies.length + impliedDependencies.length) ? '' : (
58+
<h2>Required</h2>
59+
)
60+
}
61+
{
62+
requiredDependencies.map(dependencyLink)
63+
}
64+
{
65+
!optionalDependencies.length ? '' : (
66+
<h2>Optional</h2>
67+
)
68+
}
69+
{
70+
optionalDependencies.map(dependencyLink)
71+
}
72+
{
73+
!impliedDependencies.length ? '' : (
74+
<h2>
75+
Implied
76+
{' '}
77+
<a href="#" onClick={toggleShowImplied}><span className="req">(what&apos;s this?)</span></a>
78+
</h2>
79+
)
80+
}
4381
{
44-
dependencies.sort(sortFunc).map((dependency) => {
45-
const kind = !dependency.optional ? (dependency.implied ? 'implied' : 'required') : 'optional';
46-
if (kind === 'implied') {
47-
return (
48-
<div key={dependency.name} className={kind}>
49-
<Link to={`/${dependency.name}/`}>
50-
{dependency.title}
51-
{' '}
52-
v.
53-
{dependency.version}
54-
{' '}
55-
<span className="req">
56-
(
57-
{kind}
58-
)
59-
</span>
60-
</Link>
61-
<a href="#" onClick={toggleShowImplied}><span className="req">(what&apos;s this?)</span></a>
62-
</div>
63-
);
64-
}
65-
return (
66-
<div key={dependency.name} className={kind}>
67-
<Link to={`/${dependency.name}/`}>
68-
{dependency.title}
69-
{' '}
70-
71-
{' '}
72-
{dependency.version}
73-
{' '}
74-
{kind === 'required' ? '' : <span className="req">
75-
(
76-
{kind}
77-
)
78-
</span>}
79-
</Link>
80-
</div>
81-
);
82-
})
82+
impliedDependencies.map(dependencyLink)
8383
}
8484
</div>
8585
</>

src/components/PluginReleases.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import axios from 'axios';
44
import ReactTimeAgo from 'react-time-ago/tooltip';
55
import './PluginReleases.css';
66

7-
function PluginIssues({pluginId}) {
7+
function PluginReleases({pluginId}) {
88
const [isLoading, setIsLoading] = useState(false);
99
const [releases, setReleases] = useState([]);
1010

@@ -52,7 +52,7 @@ function PluginIssues({pluginId}) {
5252
);
5353
}
5454

55-
PluginIssues.propTypes = {
55+
PluginReleases.propTypes = {
5656
pluginId: PropTypes.string.isRequired
5757
};
58-
export default PluginIssues;
58+
export default PluginReleases;

src/styles/base.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ body .showResults #plugin-search-form:before {display:none}
4646
}
4747
.isFiltered .filters .show-all {display: inline-block}
4848

49-
.dependencies .req{
50-
font-size: .67rem;
51-
opacity: .67;
49+
#pluginDependencies h2{
50+
font-size: 1.2rem;
51+
margin-top: .7rem;
5252
}
5353

5454
.empty {opacity:.33}

src/templates/plugin.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const tabs = [
3030
{id: 'documentation', label: 'Documentation'},
3131
{id: 'releases', label: 'Releases'},
3232
{id: 'issues', label: 'Issues'},
33+
{id: 'dependencies', label: 'Dependencies'},
3334
];
3435

3536
function getDefaultTab() {
@@ -85,10 +86,6 @@ function PluginPage({data: {jenkinsPlugin: plugin}}) {
8586
<h5>Maintainers</h5>
8687
<PluginMaintainers maintainers={plugin.maintainers} />
8788
</div>
88-
<div className="col-md-4 dependencies">
89-
<h5>Dependencies</h5>
90-
<PluginDependencies dependencies={plugin.dependencies} />
91-
</div>
9289
</div>
9390

9491
<PluginGovernanceStatus plugin={plugin} />
@@ -97,6 +94,7 @@ function PluginPage({data: {jenkinsPlugin: plugin}}) {
9794
</>)}
9895
{state.selectedTab === 'releases' && <PluginReleases pluginId={plugin.id} />}
9996
{state.selectedTab === 'issues' && <PluginIssues pluginId={plugin.id} />}
97+
{state.selectedTab === 'dependencies' && <PluginDependencies dependencies={plugin.dependencies} />}
10098
</div>
10199
</div>
102100
<div className="col-md-3 gutter">

0 commit comments

Comments
 (0)