Skip to content

Commit 312c4ff

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

File tree

2 files changed

+13
-44
lines changed

2 files changed

+13
-44
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;
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
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

test/unit/util/cloud-manager-hoc.test.jsx

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -364,40 +364,13 @@ describe('CloudManagerHOC', () => {
364364
});
365365

366366
// Editor Mode Connection/Disconnection Tests
367-
test('Entering editor mode and can\'t save project should disconnect cloud provider # 1', () => {
368-
const Component = () => <div />;
369-
const WrappedComponent = cloudManagerHOC(Component);
370-
const mounted = mount(
371-
<WrappedComponent
372-
canSave
373-
hasCloudPermission
374-
cloudHost="nonEmpty"
375-
store={store}
376-
username="user"
377-
vm={vm}
378-
/>
379-
);
380-
381-
expect(CloudProvider).toHaveBeenCalled();
382-
const requestCloseConnection = mockCloudProviderInstance.requestCloseConnection;
383-
384-
mounted.setProps({
385-
canSave: false,
386-
hasEverEnteredEditor: true
387-
});
388-
389-
expect(vm.setCloudProvider.mock.calls.length).toBe(2);
390-
expect(vm.setCloudProvider).toHaveBeenCalledWith(null);
391-
expect(requestCloseConnection).toHaveBeenCalledTimes(1);
392-
});
393-
394-
test('Entering editor mode and can\'t save project should disconnect cloud provider # 2', () => {
367+
test('Entering editor mode and can\'t save project should disconnect cloud provider', () => {
395368
const Component = () => <div />;
396369
const WrappedComponent = cloudManagerHOC(Component);
397370
const mounted = mount(
398371
<WrappedComponent
372+
canModifyCloudData
399373
hasCloudPermission
400-
canSave={false}
401374
cloudHost="nonEmpty"
402375
store={store}
403376
username="user"
@@ -409,7 +382,7 @@ describe('CloudManagerHOC', () => {
409382
const requestCloseConnection = mockCloudProviderInstance.requestCloseConnection;
410383

411384
mounted.setProps({
412-
hasEverEnteredEditor: true
385+
canModifyCloudData: false
413386
});
414387

415388
expect(vm.setCloudProvider.mock.calls.length).toBe(2);

0 commit comments

Comments
 (0)