Skip to content

Commit e2f44b3

Browse files
authored
Merge pull request #94 from back4app/add-cloud-code-page
Track cloud code events
2 parents 799abfd + 65d682e commit e2f44b3

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/components/B4ACodeTree/B4ACodeTree.react.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ import B4ATreeActions from 'components/B4ACodeTree/B4ATreeActions';
99
import 'jstree/dist/themes/default/style.css'
1010
import 'components/B4ACodeTree/B4AJsTree.css'
1111

12+
const cloudFolderPlaceholder = "// The first deployed file must be named main.js and must be placed on the root of the cloud folder.\n" +
13+
"// The example below shows you how a cloud code function looks like.\n\n" +
14+
"/*\n* Parse.Cloud.define(\"hello\", function(request, response){\n" +
15+
"* \tresponse.success(\"Hello world!\");\n" +
16+
"* });\n*/\n" +
17+
"\n// If you have set a function in another cloud code file, called \"test.js\" (for example)\n" +
18+
"// you need to refer it in your main.js, as you can see below:\n" +
19+
"\n/* require(\"./test.js\"); */"
20+
21+
const publicFolderPlaceholder = "// Public folder can be used to deploy public static content as html, images, css, etc.\n" +
22+
"\n" +
23+
"// You have to setup a custom domain or subdomain at Back4App to access the public static content"
24+
1225
export default class B4ACodeTree extends React.Component {
1326
constructor(props){
1427
super(props);
@@ -72,6 +85,9 @@ export default class B4ACodeTree extends React.Component {
7285
selectedFile = selected.text
7386
nodeId = selected.id
7487
extension = B4ATreeActions.getExtension(selectedFile)
88+
} else {
89+
if (selected.text === 'cloud') source = cloudFolderPlaceholder
90+
else if (selected.text === 'public') source = publicFolderPlaceholder
7591
}
7692
}
7793
this.setState({ source, selectedFile, nodeId, extension, isImage })

src/components/B4ACodeTree/B4ATreeActions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const customMenu = node => {
159159

160160
// Return the jstree config
161161
const getConfig = (files) => {
162+
if (files[0] && files[0].state) files[0].state.selected = true
162163
return {
163164
plugins: ['contextmenu', 'dnd', 'sort', 'types', 'unique', 'changed'],
164165
core: {

src/dashboard/Data/CloudCode/B4ACloudCode.react.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class B4ACloudCode extends CloudCode {
6262
}
6363

6464
async componentWillMount() {
65+
back4AppNavigation && back4AppNavigation.atCloudCodePageEvent()
6566
await this.fetchSource()
6667
// define the parameters to show unsaved changes warning modal
6768
const unbindHook = this.props.router.setRouteLeaveHook(this.props.route, nextLocation => {
@@ -101,10 +102,11 @@ class B4ACloudCode extends CloudCode {
101102
if (file.children && file.children.length > 0) {
102103
currentFile.children = [];
103104
// If is a folder, call formatFiles recursively
104-
this.formatFiles(file.children, currentFile.children);
105+
currentFile.children = this.formatFiles(file.children, currentFile.children);
105106
} else {
106107
currentFile.data = file.data;
107108
}
109+
return currentFile
108110
})
109111
}
110112

@@ -136,6 +138,7 @@ class B4ACloudCode extends CloudCode {
136138
data: { tree },
137139
withCredentials: true
138140
})
141+
back4AppNavigation && back4AppNavigation.deployCloudCodeEvent()
139142
await this.fetchSource()
140143
// force jstree component to upload
141144
await updateTreeContent(this.state.files)
@@ -193,14 +196,14 @@ class B4ACloudCode extends CloudCode {
193196
let alertTips = null;
194197

195198
let alertTipsMessage = <div>
196-
<p><b></b> Using the Cloud Code tool you can deploy and run your Node.js functions on the Back4App cloud via SDK or calling the <a href="https://www.back4app.com/docs/platform/command-line-tool/how-to-use" target="_blank">REST API</a></p>
197-
<p><b></b> To upload your code you should first click on <b>ADD</b> button and choose what files and folders you want to upload.</p>
198-
<p><b></b> The first file MUST BE called <b>main.js</b> and any other file or folder MUST BE referenced more in this file.</p>
199-
<p><b></b> After ADD and REMOVE all files you want, click on the <b>DEPLOY</b> button and commit your operation;</p>
199+
<p><b></b> To deploy your Cloud Code Functions you can use the Dashboard bellow or the <a href="https://www.back4app.com/docs/platform/command-line-tool/parse-server-setup" target="_blank">Back4App CLI.</a></p>
200+
<p><b></b> To upload your code you should first click on ADD button and choose what files you want to upload.</p>
201+
<p><b></b> The first file MUST BE called main.js and any other file or folder MUST BE referenced more in this file.</p>
202+
<p><b></b> After ADD and REMOVE all files you want, click on the DEPLOY button and commit your operation;</p>
200203
</div>
201204

202205
let alertWhatIsMessage = <div>
203-
<p>To make long short, Cloud code isn’t anything else than a script that runs on the server side instead of the device that is running your app. It is more commonly used on Apps that need of a little more of complexity to its execution but isn’t mandatory.</p>
206+
<p>Cloud code functions is a tool that lets you run a NodeJS function in Back4App Cloud. Back4App executes your code only when you call the function via API or via SDK. It is also possible to create functions that are triggered by your app events. When you update your Cloud Code Functions, it becomes available to all mobile/web/IoT environments instantly. You don’t have to wait for a new release of your application. This lets you change app behavior on the fly and add new features faster.</p>
204207
</div>
205208

206209
// Show loading page before fetch data

0 commit comments

Comments
 (0)