11import React , { Component } from 'react' ;
22import { inject , observer } from 'mobx-react' ;
3+
34import LinkIcon from 'react-icons/lib/fa/external-link' ;
45import Cogs from 'react-icons/lib/fa/cogs' ;
6+ import LightningIcon from 'react-icons/lib/md/flash-on' ;
57import NetlifyLogo from 'app/components/NetlifyLogo' ;
68import DeploymentIntegration from 'app/components/DeploymentIntegration' ;
79import getTemplate from '@codesandbox/common/lib/templates' ;
810import { Button } from '@codesandbox/common/lib/components/Button' ;
11+ import { resolveDirectory } from '@codesandbox/common/lib/sandbox/modules' ;
12+ import getNetlifyConfig from 'app/utils/getNetlifyConfig' ;
913import { WorkspaceInputContainer , WorkspaceSubtitle } from '../../elements' ;
1014import {
1115 Deploys ,
@@ -17,6 +21,18 @@ import {
1721 ButtonContainer ,
1822} from './Elements' ;
1923
24+ const getFunctionDir = sandbox => {
25+ try {
26+ return resolveDirectory (
27+ getNetlifyConfig ( sandbox ) . functions ,
28+ sandbox . modules ,
29+ sandbox . directories
30+ ) ;
31+ } catch ( e ) {
32+ return [ ] ;
33+ }
34+ } ;
35+
2036class NetlifyDeployment extends Component {
2137 state = { show : false } ;
2238
@@ -37,6 +53,11 @@ class NetlifyDeployment extends Component {
3753
3854 const template = getTemplate ( editor . currentSandbox . template ) ;
3955 const { show } = this . state ;
56+ const functionDirectory = getFunctionDir ( editor . currentSandbox ) ;
57+
58+ const functions = editor . currentSandbox . modules . filter (
59+ m => m . directoryShortid === functionDirectory . shortid
60+ ) ;
4061 return (
4162 template . netlify !== false && (
4263 < Wrapper loading = { deployment . deploying } >
@@ -77,11 +98,59 @@ class NetlifyDeployment extends Component {
7798 < Deploy key = { deployment . netlifySite . uid } >
7899 < Name light > { deployment . netlifySite . name } </ Name >
79100 { ! deployment . building && < div > Building</ div > }
101+ { functions . length ? (
102+ < >
103+ < WorkspaceSubtitle
104+ css = { `
105+ padding-left: 0;
106+ ` }
107+ >
108+ Functions
109+ </ WorkspaceSubtitle >
110+ < section
111+ css = { `
112+ display: flex;
113+ margin-bottom: 0.5rem;
114+ ` }
115+ >
116+ { functions . map ( file => (
117+ < Link
118+ disabled = { deployment . building }
119+ href = { `${
120+ deployment . netlifySite . url
121+ } /.netlify/functions/${
122+ file . title . split ( '.js' ) [ 0 ]
123+ } `}
124+ css = { `
125+ margin-top: 0;
126+ margin-right: 0.5rem;
127+ ` }
128+ target = "_blank"
129+ rel = "noreferrer noopener"
130+ >
131+ < LightningIcon />
132+ < span > { file . title . split ( '.js' ) [ 0 ] } </ span >
133+ </ Link >
134+ ) ) }
135+ </ section >
136+ </ >
137+ ) : null }
138+
139+ < WorkspaceSubtitle
140+ css = { `
141+ padding-left: 0;
142+ ` }
143+ >
144+ Actions
145+ </ WorkspaceSubtitle >
80146 < ButtonContainer >
81147 < Link
82148 disabled = { deployment . building }
83149 href = { deployment . netlifySite . url }
84150 target = "_blank"
151+ css = { `
152+ margin-top: 0;
153+ ` }
85154 rel = "noreferrer noopener"
86155 >
87156 { deployment . building ? (
@@ -100,6 +169,9 @@ class NetlifyDeployment extends Component {
100169 disabled = { deployment . building }
101170 href = { deployment . netlifyClaimUrl }
102171 target = "_blank"
172+ css = { `
173+ margin-top: 0;
174+ ` }
103175 rel = "noreferrer noopener"
104176 >
105177 < span > Claim Site</ span >
0 commit comments