Skip to content

Commit b85fe40

Browse files
committed
Revert "Allow Writing Cloud Code"
This reverts commit d7454a1.
1 parent e6a9ac4 commit b85fe40

File tree

4 files changed

+19
-55
lines changed

4 files changed

+19
-55
lines changed

src/components/SaveButton/SaveButton.example.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ export const demos = [
5555
<div style={{padding: 10}}>
5656
<SaveButton state={SaveButton.States.FAILED} />
5757
</div>
58-
<div style={{padding: 10}}>
59-
<SaveButton state={SaveButton.States.WAITING} />
60-
</div>
6158
</div>
6259
)
6360
}, {

src/components/SaveButton/SaveButton.react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ let SaveButton = ({
5252
</span>;
5353
};
5454

55-
SaveButton.States = keyMirror(['SAVING', 'SUCCEEDED', 'FAILED', 'WAITING']);
55+
SaveButton.States = keyMirror(['SAVING', 'SUCCEEDED', 'FAILED']);
5656

5757
let {...forwardedButtonProps} = Button.propTypes;
5858
delete forwardedButtonProps.value;

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

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
* This source code is licensed under the license found in the LICENSE file in
66
* the root directory of this source tree.
77
*/
8-
import CodeEditor from 'components/CodeEditor/CodeEditor.react';
8+
import CodeSnippet from 'components/CodeSnippet/CodeSnippet.react';
99
import DashboardView from 'dashboard/DashboardView.react';
1010
import EmptyState from 'components/EmptyState/EmptyState.react';
1111
import FileTree from 'components/FileTree/FileTree.react';
1212
import history from 'dashboard/history';
1313
import React from 'react';
1414
import styles from 'dashboard/Data/CloudCode/CloudCode.scss';
1515
import Toolbar from 'components/Toolbar/Toolbar.react';
16-
import SaveButton from 'components/SaveButton/SaveButton.react';
1716

1817
function getPath(params) {
1918
const last = params.location.pathname.split('cloud_code/')[1]
@@ -28,9 +27,7 @@ export default class CloudCode extends DashboardView {
2827

2928
this.state = {
3029
files: undefined,
31-
source: undefined,
32-
saveState: SaveButton.States.WAITING,
33-
saveError: '',
30+
source: undefined
3431
};
3532
}
3633

@@ -59,14 +56,8 @@ export default class CloudCode extends DashboardView {
5956
history.replace(this.context.generatePath(`cloud_code/${Object.keys(release.files)[0]}`))
6057
} else {
6158
// Means we can load /cloud_code/<fileName>
62-
this.setState({ source: undefined })
6359
app.getSource(fileName).then(
64-
(source) => {
65-
this.setState({ source: source })
66-
if (this.editor) {
67-
this.editor.value = source;
68-
}
69-
},
60+
(source) => this.setState({ source: source }),
7061
() => this.setState({ source: undefined })
7162
);
7263
}
@@ -96,23 +87,7 @@ export default class CloudCode extends DashboardView {
9687
</div>
9788
);
9889
}
99-
async getCode() {
100-
if (!this.editor) {
101-
return;
102-
}
103-
this.setState({ saveState: SaveButton.States.SAVING });
104-
let fileName = getPath(this.props);
105-
try {
106-
await this.context.currentApp.saveSource(fileName,this.editor.value);
107-
this.setState({ saveState: SaveButton.States.SUCCEEDED });
108-
setTimeout(()=> {
109-
this.setState({ saveState: SaveButton.States.WAITING });
110-
},2000);
111-
} catch (e) {
112-
this.setState({ saveState: SaveButton.States.FAILED });
113-
this.setState({ saveError: e.message || e });
114-
}
115-
}
90+
11691
renderContent() {
11792
let toolbar = null;
11893
let content = null;
@@ -136,20 +111,10 @@ export default class CloudCode extends DashboardView {
136111
subsection={fileName} />;
137112

138113
let source = this.state.files[fileName];
139-
if ((source && source.source) || this.state.source) {
114+
if (source && source.source) {
140115
content = (
141116
<div className={styles.content}>
142-
<CodeEditor
143-
placeHolder={this.state.source || source.source}
144-
ref={editor => (this.editor = editor)}
145-
fontSize={'14px'}
146-
/>
147-
<SaveButton
148-
state={this.state.saveState}
149-
waitingText={this.state.submitText}
150-
savingText={this.state.inProgressText}
151-
failedText={this.state.saveError}
152-
onClick={() => this.getCode(this)}></SaveButton>
117+
<CodeSnippet source={source.source} language='javascript' />
153118
</div>
154119
);
155120
}

src/lib/ParseApp.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,6 @@ export default class ParseApp {
119119
return this.apiRequest('GET', path, {}, { useMasterKey: true });
120120
}
121121

122-
/**
123-
* Saves source of a Cloud Code hosted file from api.parse.com
124-
* fileName - the name of the file to be fetched
125-
* data - the text to save to the cloud file
126-
*/
127-
saveSource(fileName,data) {
128-
return this.apiRequest('POST', `scripts/${fileName}`, {data}, { useMasterKey: true });
129-
}
130-
131122
/**
132123
* Fetches source of a Cloud Code hosted file from api.parse.com
133124
* fileName - the name of the file to be fetched
@@ -138,11 +129,22 @@ export default class ParseApp {
138129
// No release yet
139130
return Promise.resolve(null);
140131
}
141-
return this.apiRequest('GET', `scripts/${fileName}`, {}, { useMasterKey: true });
132+
133+
let fileMetaData = release.files[fileName];
134+
if (fileMetaData && fileMetaData.source) {
135+
return Promise.resolve(fileMetaData.source);
136+
}
137+
138+
let params = {
139+
version: fileMetaData.version,
140+
checksum: fileMetaData.checksum
141+
}
142+
return this.apiRequest('GET', `scripts/${fileName}`, params, { useMasterKey: true });
142143
}).then((source) => {
143144
if (this.latestRelease.files) {
144145
this.latestRelease.files[fileName].source = source;
145146
}
147+
146148
return Promise.resolve(source);
147149
});
148150
}

0 commit comments

Comments
 (0)