|
1 | 1 | // @flow |
2 | | -import React from 'react'; |
| 2 | +import * as React from 'react'; |
3 | 3 |
|
4 | 4 | import type { Sandbox } from 'common/types'; |
5 | 5 |
|
@@ -40,6 +40,20 @@ type Props = { |
40 | 40 | }; |
41 | 41 |
|
42 | 42 | function Sidebar({ sandbox, setCurrentModule, currentModule }: Props) { |
| 43 | + const packageJSON = sandbox.modules.find( |
| 44 | + m => m.title === 'package.json' && m.directoryShortid == null |
| 45 | + ); |
| 46 | + |
| 47 | + let npmDependencies = sandbox.npmDependencies; |
| 48 | + |
| 49 | + if (packageJSON) { |
| 50 | + try { |
| 51 | + npmDependencies = JSON.parse(packageJSON.code).dependencies; |
| 52 | + } catch (e) { |
| 53 | + console.error(e); |
| 54 | + } |
| 55 | + } |
| 56 | + |
43 | 57 | return ( |
44 | 58 | <Container> |
45 | 59 | <Item> |
@@ -70,22 +84,30 @@ function Sidebar({ sandbox, setCurrentModule, currentModule }: Props) { |
70 | 84 | <Item> |
71 | 85 | <Title>Dependencies</Title> |
72 | 86 |
|
73 | | - <Subtitle>NPM Dependencies</Subtitle> |
74 | | - {Object.keys(sandbox.npmDependencies).map(dep => ( |
| 87 | + <Subtitle>npm Dependencies</Subtitle> |
| 88 | + {Object.keys(npmDependencies).map(dep => ( |
75 | 89 | <EntryContainer key={dep}> |
76 | 90 | {dep} |
77 | | - <Version>{sandbox.npmDependencies[dep]}</Version> |
| 91 | + <Version>{npmDependencies[dep]}</Version> |
78 | 92 | </EntryContainer> |
79 | 93 | ))} |
80 | 94 |
|
81 | | - <Subtitle>External Resources</Subtitle> |
82 | | - {sandbox.externalResources.map(dep => ( |
83 | | - <EntryContainer key={dep}> |
84 | | - <a href={dep} rel="nofollow noopener noreferrer" target="_blank"> |
85 | | - {getName(dep)} |
86 | | - </a> |
87 | | - </EntryContainer> |
88 | | - ))} |
| 95 | + {sandbox.externalResources.length > 0 && ( |
| 96 | + <React.Fragment> |
| 97 | + <Subtitle>External Resources</Subtitle> |
| 98 | + {sandbox.externalResources.map(dep => ( |
| 99 | + <EntryContainer key={dep}> |
| 100 | + <a |
| 101 | + href={dep} |
| 102 | + rel="nofollow noopener noreferrer" |
| 103 | + target="_blank" |
| 104 | + > |
| 105 | + {getName(dep)} |
| 106 | + </a> |
| 107 | + </EntryContainer> |
| 108 | + ))} |
| 109 | + </React.Fragment> |
| 110 | + )} |
89 | 111 | </Item> |
90 | 112 |
|
91 | 113 | <Item hover> |
|
0 commit comments