Skip to content

Commit f97e7c3

Browse files
committed
make function shouldNotModifyCloudData into prop canModifyCloudData
1 parent 9e8aaa5 commit f97e7c3

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/lib/cloud-manager-hoc.jsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ const cloudManagerHOC = function (WrappedComponent) {
5454
canUseCloud (props) {
5555
return !!(props.cloudHost && props.username && props.vm && props.projectId && props.hasCloudPermission);
5656
}
57-
shouldNotModifyCloudData (props) {
58-
return (props.hasEverEnteredEditor && !props.canSave);
59-
}
6057
shouldConnect (props) {
6158
return !this.isConnected() && this.canUseCloud(props) &&
6259
props.isShowingWithId && props.vm.runtime.hasCloudData() &&
63-
!this.shouldNotModifyCloudData(props);
60+
props.canModifyCloudData(props);
6461
}
6562
shouldDisconnect (props, prevProps) {
6663
return this.isConnected() &&
@@ -70,7 +67,7 @@ const cloudManagerHOC = function (WrappedComponent) {
7067
(props.projectId !== prevProps.projectId) ||
7168
(props.username !== prevProps.username) ||
7269
// Editing someone else's project
73-
this.shouldNotModifyCloudData(props)
70+
!props.canModifyCloudData(props)
7471
);
7572
}
7673
isConnected () {
@@ -102,11 +99,11 @@ const cloudManagerHOC = function (WrappedComponent) {
10299
render () {
103100
const {
104101
/* eslint-disable no-unused-vars */
102+
canModifyCloudData,
105103
cloudHost,
106104
projectId,
107105
username,
108106
hasCloudPermission,
109-
hasEverEnteredEditor,
110107
isShowingWithId,
111108
onShowCloudInfo,
112109
/* eslint-enable no-unused-vars */
@@ -124,31 +121,30 @@ const cloudManagerHOC = function (WrappedComponent) {
124121
}
125122

126123
CloudManager.propTypes = {
127-
canSave: PropTypes.bool.isRequired,
124+
canModifyCloudData: PropTypes.bool.isRequired,
128125
cloudHost: PropTypes.string,
129-
hasCloudPermission: PropTypes.bool.isRequired,
130-
hasEverEnteredEditor: PropTypes.bool.isRequired,
126+
hasCloudPermission: PropTypes.bool,
131127
isShowingWithId: PropTypes.bool.isRequired,
132-
onShowCloudInfo: PropTypes.func.isRequired,
128+
onShowCloudInfo: PropTypes.func,
133129
projectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
134130
username: PropTypes.string,
135131
vm: PropTypes.instanceOf(VM).isRequired
136132
};
137133

138134
CloudManager.defaultProps = {
139-
canSave: false,
140135
cloudHost: null,
141136
hasCloudPermission: false,
142137
onShowCloudInfo: () => {},
143138
username: null
144139
};
145140

146-
const mapStateToProps = state => {
141+
const mapStateToProps = (state, ownProps) => {
147142
const loadingState = state.scratchGui.projectState.loadingState;
148143
return {
149-
hasEverEnteredEditor: state.scratchGui.mode.hasEverEnteredEditor,
150144
isShowingWithId: getIsShowingWithId(loadingState),
151-
projectId: state.scratchGui.projectState.projectId
145+
projectId: state.scratchGui.projectState.projectId,
146+
// if you're editing someone else's project, you can't modify cloud data
147+
canModifyCloudData: (!state.scratchGui.mode.hasEverEnteredEditor || ownProps.canSave)
152148
};
153149
};
154150

0 commit comments

Comments
 (0)