@@ -2,7 +2,6 @@ import React from 'react';
22import PropTypes from 'prop-types' ;
33import { Link } from 'gatsby' ;
44import { 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
76function 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'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'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 </ >
0 commit comments