11import { graphql } from 'gatsby' ;
2- import React from 'react' ;
2+ import React , { useState } from 'react' ;
33import PropTypes from 'prop-types' ;
44
55import { cleanTitle } from '../commons/helper' ;
@@ -15,7 +15,8 @@ import PluginInactiveWarnings from '../components/PluginInactiveWarnings';
1515import PluginGovernanceStatus from '../components/PluginGovernanceStatus' ;
1616import PluginMaintainers from '../components/PluginMaintainers' ;
1717import PluginReadableInstalls from '../components/PluginReadableInstalls' ;
18-
18+ import PluginIssues from '../components/PluginIssues' ;
19+ import PluginReleases from '../components/PluginReleases' ;
1920
2021function shouldShowWikiUrl ( { url} ) {
2122 return url && ( url . startsWith ( 'https://wiki.jenkins-ci.org' ) || url . startsWith ( 'https://wiki.jenkins.io' ) ) ;
@@ -25,50 +26,77 @@ function shouldShowGitHubUrl({url}) {
2526 return url && url . startsWith ( 'https://github.com' ) ;
2627}
2728
29+ const tabs = [
30+ { id : 'documentation' , label : 'Documentation' } ,
31+ { id : 'releases' , label : 'Releases' } ,
32+ { id : 'issues' , label : 'Issues' } ,
33+ ] ;
34+
35+ function getDefaultTab ( ) {
36+ const tabName = ( typeof window !== 'undefined' && window . location . hash . replace ( '#' , '' ) ) || tabs [ 0 ] . id ;
37+ if ( tabs . find ( tab => tab . id === tabName ) ) {
38+ return tabName ;
39+ }
40+ return tabs [ 0 ] . id ;
41+ }
42+
2843function PluginPage ( { data : { jenkinsPlugin : plugin } } ) {
44+ const [ state , setState ] = useState ( { selectedTab : getDefaultTab ( ) } ) ;
2945 const pluginPage = 'templates/plugin.jsx' ;
3046
3147 return (
3248 < Layout id = "pluginPage" reportProblemRelativeSourcePath = { pluginPage } reportProblemUrl = { `/${ plugin . name } ` } reportProblemTitle = { plugin . title } >
3349 < SEO title = { cleanTitle ( plugin . title ) } description = { plugin . excerpt } pathname = { `/${ plugin . id } ` } />
50+
3451 < div className = "row flex" >
3552 < div className = "col-md-9 main" >
53+ < ul className = "nav nav-tabs" >
54+ { tabs . map ( tab => (
55+ < li className = "nav-item" key = { tab . id } >
56+ < a className = { `nav-link ${ state . selectedTab === tab . id ? 'active' : '' } ` } href = { `#${ tab . id } ` } onClick = { ( ) => setState ( { selectedTab : tab . id } ) } > { tab . label } </ a >
57+ </ li >
58+ ) ) }
59+ </ ul >
3660 < div className = "padded" >
37- < h1 className = "title" >
38- { cleanTitle ( plugin . title ) }
39- < PluginActiveWarnings securityWarnings = { plugin . securityWarnings } />
40- < span className = "v" > { plugin . version } </ span >
41- < span className = "sub" >
42- { 'Minimum Jenkins requirement: ' }
43- { plugin . requiredCore }
44- </ span >
45- < span className = "sub" >
46- { 'ID: ' }
47- { plugin . name }
48- </ span >
49- </ h1 >
50- < div className = "row flex" >
51- < div className = "col-md-4" >
52- { plugin . stats && < div >
53- { 'Installs: ' }
54- < PluginReadableInstalls currentInstalls = { plugin . stats . currentInstalls } />
55- </ div > }
56- { plugin . scm && plugin . scm . link && < div > < a href = { plugin . scm . link } > GitHub →</ a > </ div > }
57- < PluginLastReleased plugin = { plugin } />
58- </ div >
59- < div className = "col-md-4 maintainers" >
60- < h5 > Maintainers</ h5 >
61- < PluginMaintainers maintainers = { plugin . maintainers } />
61+ { state . selectedTab === 'documentation' && ( < >
62+ < h1 className = "title" >
63+ { cleanTitle ( plugin . title ) }
64+ < PluginActiveWarnings securityWarnings = { plugin . securityWarnings } />
65+ < span className = "v" > { plugin . version } </ span >
66+ < span className = "sub" >
67+ { 'Minimum Jenkins requirement: ' }
68+ { plugin . requiredCore }
69+ </ span >
70+ < span className = "sub" >
71+ { 'ID: ' }
72+ { plugin . name }
73+ </ span >
74+ </ h1 >
75+ < div className = "row flex" >
76+ < div className = "col-md-4" >
77+ { plugin . stats && < div >
78+ { 'Installs: ' }
79+ < PluginReadableInstalls currentInstalls = { plugin . stats . currentInstalls } />
80+ </ div > }
81+ { plugin . scm && plugin . scm . link && < div > < a href = { plugin . scm . link } > GitHub →</ a > </ div > }
82+ < PluginLastReleased plugin = { plugin } />
83+ </ div >
84+ < div className = "col-md-4 maintainers" >
85+ < h5 > Maintainers</ h5 >
86+ < PluginMaintainers maintainers = { plugin . maintainers } />
87+ </ div >
88+ < div className = "col-md-4 dependencies" >
89+ < h5 > Dependencies</ h5 >
90+ < PluginDependencies dependencies = { plugin . dependencies } />
91+ </ div >
6292 </ div >
63- < div className = "col-md-4 dependencies" >
64- < h5 > Dependencies</ h5 >
65- < PluginDependencies dependencies = { plugin . dependencies } />
66- </ div >
67- </ div >
6893
69- < PluginGovernanceStatus plugin = { plugin } />
94+ < PluginGovernanceStatus plugin = { plugin } />
7095
71- { plugin . wiki . content && < div className = "content" dangerouslySetInnerHTML = { { __html : plugin . wiki . content } } /> }
96+ { plugin . wiki . content && < div className = "content" dangerouslySetInnerHTML = { { __html : plugin . wiki . content } } /> }
97+ </ > ) }
98+ { state . selectedTab === 'releases' && < PluginReleases pluginId = { plugin . id } /> }
99+ { state . selectedTab === 'issues' && < PluginIssues pluginId = { plugin . id } /> }
72100 </ div >
73101 </ div >
74102 < div className = "col-md-3 gutter" >
0 commit comments