Skip to content

Commit 4ae72f7

Browse files
committed
Show a message about empty secrets on fork
1 parent 21cc9e2 commit 4ae72f7

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ import { clearCorrectionsFromAction } from 'app/utils/corrections';
1919
import { json } from 'overmind';
2020

2121
import { hasPermission } from '@codesandbox/common/lib/utils/permission';
22+
import { NotificationStatus } from '@codesandbox/notifications';
2223
import eventToTransform from '../../utils/event-to-transform';
2324
import * as internalActions from './internalActions';
25+
import { SERVER } from '../../utils/items';
2426

2527
export const internal = internalActions;
2628

@@ -627,6 +629,44 @@ export const deleteEnvironmentVariable: AsyncAction<{
627629
effects.codesandboxApi.restartSandbox();
628630
};
629631

632+
/**
633+
* This will let the user know on fork that some secrets need to be set if there are any empty ones
634+
*/
635+
export const showEnvironmentVariablesNotification: AsyncAction = async ({
636+
state,
637+
actions,
638+
effects,
639+
}) => {
640+
const sandbox = state.editor.currentSandbox;
641+
642+
if (!sandbox) {
643+
return;
644+
}
645+
646+
await actions.editor.fetchEnvironmentVariables();
647+
648+
const emptyVarCount = Object.keys(sandbox.environmentVariables).filter(
649+
key => !sandbox.environmentVariables[key]
650+
).length;
651+
if (emptyVarCount > 0) {
652+
effects.notificationToast.add({
653+
status: NotificationStatus.NOTICE,
654+
title: 'Unset Secrets',
655+
message: `This sandbox has ${emptyVarCount} secrets that need to be set. You can set them in the server tab.`,
656+
actions: {
657+
primary: [
658+
{
659+
label: 'Open Server Tab',
660+
run: () => {
661+
actions.workspace.setWorkspaceItem({ item: SERVER.id });
662+
},
663+
},
664+
],
665+
},
666+
});
667+
}
668+
};
669+
630670
export const toggleEditorPreviewLayout: Action = ({ state, effects }) => {
631671
const currentOrientation = state.editor.previewWindowOrientation;
632672

packages/app/src/app/overmind/namespaces/editor/internalActions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ export const forkSandbox: AsyncAction<{
396396

397397
effects.notificationToast.success('Forked sandbox!');
398398

399+
if (templateDefinition.isServer) {
400+
actions.editor.showEnvironmentVariablesNotification();
401+
}
402+
399403
effects.router.updateSandboxUrl(forkedSandbox, { openInNewWindow });
400404
} catch (error) {
401405
console.error(error);

packages/app/src/app/overmind/utils/items.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,53 @@ export interface INavigationItem {
1313
showAsDisabledIfHidden?: boolean;
1414
}
1515

16-
const PROJECT: INavigationItem = {
16+
export const PROJECT: INavigationItem = {
1717
id: 'project',
1818
name: 'Sandbox Info',
1919
};
2020

21-
const PROJECT_TEMPLATE: INavigationItem = {
21+
export const PROJECT_TEMPLATE: INavigationItem = {
2222
...PROJECT,
2323
name: 'Template Info',
2424
};
2525

26-
const PROJECT_SUMMARY: INavigationItem = {
26+
export const PROJECT_SUMMARY: INavigationItem = {
2727
id: 'project-summary',
2828
name: 'Sandbox Info',
2929
hasCustomHeader: true,
3030
};
3131

32-
const FILES: INavigationItem = {
32+
export const FILES: INavigationItem = {
3333
id: 'files',
3434
name: 'Explorer',
3535
hasCustomHeader: true,
3636
defaultOpen: true,
3737
};
3838

39-
const GITHUB: INavigationItem = {
39+
export const GITHUB: INavigationItem = {
4040
id: 'github',
4141
name: 'GitHub',
4242
showAsDisabledIfHidden: true,
4343
};
4444

45-
const DEPLOYMENT: INavigationItem = {
45+
export const DEPLOYMENT: INavigationItem = {
4646
id: 'deploy',
4747
name: 'Deployment',
4848
showAsDisabledIfHidden: true,
4949
};
5050

51-
const CONFIGURATION: INavigationItem = {
51+
export const CONFIGURATION: INavigationItem = {
5252
id: 'config',
5353
name: 'Configuration Files',
5454
};
5555

56-
const LIVE: INavigationItem = {
56+
export const LIVE: INavigationItem = {
5757
id: 'live',
5858
name: 'Live',
5959
showAsDisabledIfHidden: true,
6060
};
6161

62-
const SERVER: INavigationItem = {
62+
export const SERVER: INavigationItem = {
6363
id: 'server',
6464
name: 'Server Control Panel',
6565
};

0 commit comments

Comments
 (0)