Skip to content

Commit 642ebea

Browse files
SaraVieiraCompuIves
authored andcommitted
Alert frozen (codesandbox#1716)
* Added alert when saving frozen sandbox (codesandbox#1232) * Fix minor spelling error * Added alert when attempting to save frozen sandbox * add to contribs * add johnn as a contrib * add alert on frozen sandbox * fix readme * flip statemnet
1 parent 8fda397 commit 642ebea

File tree

9 files changed

+90
-15
lines changed

9 files changed

+90
-15
lines changed

.all-contributorsrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,18 @@
654654
"design"
655655
]
656656
},
657+
{
658+
"login": "JonShort",
659+
"name": "Jon Short",
660+
"avatar_url": "https://avatars2.githubusercontent.com/u/21317379?v=4",
661+
"profile": "https://jonshort.me/",
662+
"contributions": [
663+
"code"
664+
]
665+
},
666+
667+
668+
657669
{
658670
"login": "dv297",
659671
"name": "Daniel Vu",

README.md

Lines changed: 19 additions & 3 deletions
Large diffs are not rendered by default.

packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/elements.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const PrivacyContainer = styled.span`
3535
margin-bottom: 1rem;
3636
`;
3737

38-
export const FreezeConatainer = styled.span`
38+
export const FreezeContainer = styled.span`
3939
display: flex;
4040
justify-content: flex-end;
4141
`;

packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
PropertyValue,
3333
PropertyName,
3434
Icon,
35-
FreezeConatainer,
35+
FreezeContainer,
3636
} from './elements';
3737

3838
class Project extends React.Component {
@@ -278,15 +278,15 @@ class Project extends React.Component {
278278
</Tooltip>
279279
</PropertyName>
280280
<PropertyValue>
281-
<FreezeConatainer>
281+
<FreezeContainer>
282282
<Switch
283283
small
284284
right={sandbox.isFrozen}
285285
onClick={this.updateFrozenState}
286286
offMode
287287
secondary
288288
/>
289-
</FreezeConatainer>
289+
</FreezeContainer>
290290
</PropertyValue>
291291
</Item>
292292
) : null}

packages/app/src/app/store/errors.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ export class AuthenticationError extends CerebralError {
66
this.name = 'AuthenticationError';
77
}
88
}
9+
10+
export class CancelError extends CerebralError {
11+
constructor(message) {
12+
super(message);
13+
this.name = 'CancelError';
14+
}
15+
}

packages/app/src/app/store/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ export default Module({
104104
refetchSandboxInfo: sequences.refetchSandboxInfo,
105105
track: sequences.track,
106106
},
107-
catch: [[errors.AuthenticationError, sequences.showAuthenticationError]],
107+
catch: [
108+
[errors.CancelError, []],
109+
[errors.AuthenticationError, sequences.showAuthenticationError],
110+
],
108111
modules: {
109112
dashboard,
110113
patron,

packages/app/src/app/store/modules/editor/actions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ export function confirmForkingOwnSandbox({ browser, path }) {
349349
: path.cancelled();
350350
}
351351

352+
export function alertForkingFrozenSandbox({ browser, path }) {
353+
return browser.confirm(
354+
'This sandbox is frozen, and will be forked. Do you want to continue?'
355+
)
356+
? path.confirmed()
357+
: path.cancelled();
358+
}
359+
352360
export function unlikeSandbox({ api, props }) {
353361
return api.request({
354362
method: 'DELETE',

packages/app/src/app/store/providers/Browser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export default Provider({
2525
setTitle(title) {
2626
document.title = title;
2727
},
28+
alert(message) {
29+
return alert(message); // eslint-disable-line no-alert
30+
},
2831
confirm(message) {
2932
return confirm(message); // eslint-disable-line no-alert
3033
},

packages/app/src/app/store/sequences.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import getTemplateDefinition from '@codesandbox/common/lib/templates';
77
import * as actions from './actions';
88
import * as factories from './factories';
99
import { connectToChannel as setupNotifications } from './modules/user-notifications/actions';
10+
import { CancelError } from './errors';
1011

1112
import {
1213
saveNewModule,
@@ -18,6 +19,7 @@ import {
1819
} from './modules/files/actions';
1920

2021
import { disconnect, clearUserSelections } from './modules/live/actions';
22+
import { alertForkingFrozenSandbox } from './modules/editor/actions';
2123
import { initializeLive } from './modules/live/common-sequences';
2224

2325
export const unloadApp = actions.stopListeningToConnectionChange;
@@ -32,6 +34,10 @@ const whenPackageJSONExists = when(props`sandbox.modules`, modules =>
3234
modules.find(m => m.directoryShortid == null && m.title === 'package.json')
3335
);
3436

37+
function stopFrozenSandboxFromEdit() {
38+
throw new CancelError("You can't save a frozen sandbox", {});
39+
}
40+
3541
export const ensurePackageJSON = [
3642
when(props`sandbox.owned`),
3743
{
@@ -172,18 +178,38 @@ export const forkSandbox = sequence('forkSandbox', [
172178
},
173179
]);
174180

175-
export const ensureOwnedEditable = sequence('ensureOwnedEditable', [
176-
when(
177-
state`editor.currentSandbox.owned`,
178-
state`editor.currentSandbox.isFrozen`,
179-
(owned, frozen) => !owned || frozen
180-
),
181+
export const forkFrozenSandbox = sequence('forkFrozenSandbox', [
182+
when(state`editor.currentSandbox.isFrozen`),
181183
{
182-
true: forkSandbox,
184+
true: [
185+
alertForkingFrozenSandbox,
186+
{
187+
confirmed: forkSandbox,
188+
cancelled: [
189+
set(props`message`, "Can't save a frozen sandbox"),
190+
actions.callVSCodeCallbackError,
191+
stopFrozenSandboxFromEdit,
192+
],
193+
},
194+
],
183195
false: [],
184196
},
185197
]);
186198

199+
export const ensureOwnedEditable = sequence('ensureOwnedEditable', [
200+
when(state`editor.currentSandbox.owned`, owned => owned),
201+
{
202+
true: [
203+
when(state`editor.currentSandbox.isFrozen`, isFrozen => isFrozen),
204+
{
205+
true: forkFrozenSandbox,
206+
false: [],
207+
},
208+
],
209+
false: forkSandbox,
210+
},
211+
]);
212+
187213
export const fetchGitChanges = [
188214
set(state`git.isFetching`, true),
189215
actions.getGitChanges,

0 commit comments

Comments
 (0)