Skip to content

Commit bd288ad

Browse files
committed
Support VSCode actions in new notification system
1 parent 626828d commit bd288ad

File tree

12 files changed

+56
-27
lines changed

12 files changed

+56
-27
lines changed

packages/app/config/webpack.common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ module.exports = {
479479
[
480480
{
481481
from: '../../standalone-packages/vscode-editor/release/min/vs',
482-
to: 'public/vscode20/vs',
482+
to: 'public/vscode21/vs',
483483
force: true,
484484
},
485485
{

packages/app/config/webpack.prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ module.exports = merge(commonConfig, {
150150
},
151151
},
152152
{
153-
urlPattern: /\/vscode20/,
153+
urlPattern: /\/vscode21/,
154154
handler: 'cacheFirst',
155155
options: {
156156
cache: {

packages/app/src/app/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@
6868
}
6969
</script>
7070

71-
<link data-name="/public/vscode20/vs/editor/editor.main"
71+
<link data-name="/public/vscode21/vs/editor/editor.main"
7272
rel="preload"
7373
as="style"
74-
href="/public/vscode20/vs/editor/codesandbox.editor.main.css">
74+
href="/public/vscode21/vs/editor/codesandbox.editor.main.css">
7575
</link>
76-
<link rel="preload" as="script" href="/public/vscode20/vs/editor/codesandbox.editor.main.js"></link>
76+
<link rel="preload" as="script" href="/public/vscode21/vs/editor/codesandbox.editor.main.js"></link>
7777
</head>
7878
<body style="margin: 0; padding: 0;">
7979
<!-- Google Tag Manager (noscript) -->

packages/app/src/app/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ function boot() {
9898
'We just installed a new version of CodeSandbox, refresh to update!',
9999
status: NotificationStatus.SUCCESS,
100100
sticky: true,
101-
actions: [
102-
{
103-
primary: {
101+
actions: {
102+
primary: [
103+
{
104104
run: () => document.location.reload(),
105-
title: 'Reload Page',
105+
label: 'Reload Page',
106106
},
107-
},
108-
],
107+
],
108+
},
109109
});
110110
},
111111
onInstalled: () => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { when, push, unset, set, equals } from 'cerebral/operators';
33
import { state, props } from 'cerebral/tags';
44

55
import getTemplateDefinition from '@codesandbox/common/lib/templates';
6+
import {
7+
notificationState,
8+
convertTypeToStatus,
9+
} from '@codesandbox/common/lib/utils/notifications';
610

711
import * as actions from './actions';
812
import * as factories from './factories';

packages/app/src/app/vscode/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { KeyCode, KeyMod } from './keyCodes';
22
import bootstrap from './dev-bootstrap';
33
import { MenuId } from './menus';
4+
import {
5+
notificationState,
6+
convertTypeToStatus,
7+
} from '@codesandbox/common/lib/utils/notifications';
8+
import { NotificationMessage } from '@codesandbox/notifications/lib/state';
49

510
interface IServiceCache {
611
[serviceName: string]: any;
@@ -303,6 +308,18 @@ class VSCodeManager {
303308
});
304309
}
305310

311+
addNotification(
312+
message: string,
313+
type: 'warning' | 'notice' | 'error' | 'success',
314+
notification: NotificationMessage
315+
) {
316+
notificationState.addNotification({
317+
message,
318+
status: convertTypeToStatus(type),
319+
...notification,
320+
});
321+
}
322+
306323
/**
307324
* Initialize the base VSCode editor, this includes registering all the services in VSCode.
308325
*/
@@ -364,7 +381,7 @@ class VSCodeManager {
364381
container,
365382
{
366383
codesandboxService: i =>
367-
new SyncDescriptor(CodeSandboxService, [this.controller]),
384+
new SyncDescriptor(CodeSandboxService, [this.controller, this]),
368385
codesandboxConfigurationUIService: i =>
369386
new SyncDescriptor(CodeSandboxConfigurationUIService, [
370387
customEditorAPI,

packages/app/src/app/vscode/metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const VSCODE_METADATA = {
22
CORE: {
33
paths: {
4-
src: process.env.VSCODE ? '/vscode/out/vs' : '/public/vscode20/vs',
4+
src: process.env.VSCODE ? '/vscode/out/vs' : '/public/vscode21/vs',
55
'npm/dev': 'node_modules/monaco-editor-core/dev/vs',
66
'npm/min': 'node_modules/monaco-editor-core/min/vs',
77
built: '/vscode/out-monaco-editor-core/min/vs',

packages/notifications/src/component/Toast.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,33 +137,32 @@ export function Toast({ toast, removeToast, getRef }: Props) {
137137
<Button
138138
small
139139
onClick={() => {
140-
toast.notification.actions[0].primary.run();
141140
removeToast(toast.id);
141+
toast.notification.actions.primary[0].run();
142142
}}
143143
style={{
144144
marginTop: '1rem',
145145
marginRight: '0.75rem',
146146
lineHeight: 1,
147147
}}
148148
>
149-
{toast.notification.actions[0].primary.title}
149+
{toast.notification.actions.primary[0].label}
150150
</Button>
151151

152-
{toast.notification.actions[0].secondary && (
152+
{toast.notification.actions.secondary[0] && (
153153
<Button
154154
secondary
155155
small
156156
onClick={() => {
157-
toast.notification.actions[0].secondary.run();
158-
removeToast(toast.id);
157+
toast.notification.actions.secondary[0].run();
159158
}}
160159
style={{
161160
marginTop: '1rem',
162161
marginLeft: '0.5rem',
163162
lineHeight: 1,
164163
}}
165164
>
166-
{toast.notification.actions[0].secondary.title}
165+
{toast.notification.actions.secondary[0].label}
167166
</Button>
168167
)}
169168
</div>

packages/notifications/src/state.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as uuid from 'uuid';
22
import { Emitter } from './utils/events';
33

44
export interface NotificationAction {
5-
title: string;
6-
run: () => void;
5+
label: string;
6+
run: (event?: any) => void;
77
}
88

99
export enum NotificationStatus {
@@ -19,9 +19,18 @@ export interface NotificationMessage {
1919
sticky?: boolean;
2020
message: string;
2121
actions?: {
22-
primary: NotificationAction;
23-
secondary?: NotificationAction;
24-
}[];
22+
/**
23+
* Primary actions show up as buttons as part of the message and will close
24+
* the notification once clicked.
25+
*/
26+
primary: NotificationAction[];
27+
/**
28+
* Secondary actions are meant to provide additional configuration or context
29+
* for the notification and will show up less prominent. A notification does not
30+
* close automatically when invoking a secondary action.
31+
*/
32+
secondary?: NotificationAction[];
33+
};
2534
timeAlive?: number;
2635
status: NotificationStatus;
2736
}

standalone-packages/vscode

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 67ef4def0da69156281b6356a476d472e0f597d9
1+
Subproject commit 1d81933e2cb4db4cea549aadcfa8919aeabb46df

0 commit comments

Comments
 (0)