1
+ import { Icon } from 'office-ui-fabric-react/lib/Icon' ;
2
+ import { Link } from 'office-ui-fabric-react' ;
1
3
import { config } from '../config' ;
2
4
import * as React from 'react' ;
3
5
6
+ import './Dependents.css'
7
+
4
8
interface IDependentsProps {
5
9
packageId : string ;
6
10
}
7
11
8
12
interface IDependentsState {
9
13
totalHits : number | undefined ;
10
- data : string [ ] | undefined ;
14
+ data : IDependentState [ ] | undefined ;
15
+ }
16
+
17
+ interface IDependentState {
18
+ id : string | undefined ;
19
+ description : string | undefined ;
20
+ totalDownloads : number | undefined ;
11
21
}
12
22
13
23
class Dependents extends React . Component < IDependentsProps , IDependentsState > {
@@ -40,6 +50,21 @@ class Dependents extends React.Component<IDependentsProps, IDependentsState> {
40
50
} ) . catch ( ( e ) => console . log ( "Failed to load dependents." , e ) ) ;
41
51
}
42
52
53
+ private getDependentsMessage ( ) {
54
+ const hits = this . state . totalHits ?? - 1 ;
55
+ const packageId = this . props . packageId ;
56
+
57
+ if ( hits < 0 ) {
58
+ return ""
59
+ }
60
+
61
+ if ( hits === 0 ) {
62
+ return `No packages depend on ${ packageId } .` ;
63
+ }
64
+
65
+ return `Showing the top 20 packages that depend on ${ packageId } .` ;
66
+ }
67
+
43
68
public render ( ) {
44
69
if ( ! this . state . data ) {
45
70
return (
@@ -49,19 +74,37 @@ class Dependents extends React.Component<IDependentsProps, IDependentsState> {
49
74
50
75
if ( this . state . totalHits === 0 ) {
51
76
return (
52
- < div > No packages depend on { this . props . packageId } . </ div >
77
+ < div > { this . getDependentsMessage ( ) } </ div >
53
78
) ;
54
79
}
55
80
56
81
return (
57
82
< div >
58
- < p > { this . state . totalHits } { this . state . totalHits === 1 ? 'package depends' : 'packages depend' } on { this . props . packageId } : </ p >
83
+ < p > { this . getDependentsMessage ( ) } </ p >
59
84
< div >
60
- < ul >
61
- { this . state . data . map ( dependent => (
62
- < li key = { dependent } > { dependent } </ li >
63
- ) ) }
64
- </ ul >
85
+ < table >
86
+ < thead >
87
+ < tr >
88
+ < th className = "col-sm-10" > Package</ th >
89
+ < th className = "col-sm-2" > Downloads</ th >
90
+ </ tr >
91
+ </ thead >
92
+ < tbody >
93
+ { this . state . data . map ( dependent => (
94
+ < tr key = { dependent . id } >
95
+ < td >
96
+ < Link to = { `/packages/${ dependent . id } ` } > { dependent . id } </ Link >
97
+ < div > { dependent . description } </ div >
98
+ </ td >
99
+ < td >
100
+ < Icon iconName = "Download" className = "ms-Icon" />
101
+ < span > { dependent . totalDownloads ?. toLocaleString ( ) } </ span >
102
+ </ td >
103
+ </ tr >
104
+
105
+ ) ) }
106
+ </ tbody >
107
+ </ table >
65
108
</ div >
66
109
</ div >
67
110
) ;
0 commit comments