Skip to content

Commit 4525c1c

Browse files
Satya RohithCompuIves
Satya Rohith
authored andcommitted
Allows opening tests by default with share link (#959)
* Share TestsView works 🎉 * Add docs for previewWindow * Add satyarohith to contributors * Support Embed * Update 2-embedding.md
1 parent 5480144 commit 4525c1c

File tree

9 files changed

+55
-3
lines changed

9 files changed

+55
-3
lines changed

.all-contributorsrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,16 @@
593593
"bug",
594594
"code"
595595
]
596+
},
597+
{
598+
"login": "satyarohith",
599+
"name": "Satya Rohith",
600+
"avatar_url": "https://avatars2.githubusercontent.com/u/29819102?v=4",
601+
"profile": "https://satya.tech",
602+
"contributions": [
603+
"code",
604+
"doc"
605+
]
596606
}
597607
],
598608
"repoType": "github"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ Thanks goes to these wonderful people
5151
| [<img src="https://avatars2.githubusercontent.com/u/10588170?v=4" width="100px;"/><br /><sub><b>Ilya</b></sub>](https://twitter.com/ilya_komar0ff)<br />[💬](#question-Komar0ff "Answering Questions") [🤔](#ideas-Komar0ff "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/10627086?v=4" width="100px;"/><br /><sub><b>Emerson Laurentino</b></sub>](https://twitter.com/elaurent_)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=emersonlaurentino "Code") [🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3Aemersonlaurentino "Bug reports") | [<img src="https://avatars3.githubusercontent.com/u/180963?v=4" width="100px;"/><br /><sub><b>Aaron Reisman</b></sub>](https://github.com/lifeiscontent)<br />[🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3Alifeiscontent "Bug reports") [💻](https://github.com/CompuIves/codesandbox-client/commits?author=lifeiscontent "Code") [📦](#platform-lifeiscontent "Packaging/porting to new platform") |
5252
| [<img src="https://avatars2.githubusercontent.com/u/10588170?v=4" width="100px;"/><br /><sub><b>Ilya</b></sub>](https://twitter.com/ilya_komar0ff)<br />[💬](#question-Komar0ff "Answering Questions") [🤔](#ideas-Komar0ff "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/10627086?v=4" width="100px;"/><br /><sub><b>Emerson Laurentino</b></sub>](https://twitter.com/elaurent_)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=emersonlaurentino "Code") [🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3Aemersonlaurentino "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/19484365?v=4" width="100px;"/><br /><sub><b>Colton Colcleasure</b></sub>](https://github.com/colshacol)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=colshacol "Code") |
5353
| [<img src="https://avatars2.githubusercontent.com/u/10588170?v=4" width="100px;"/><br /><sub><b>Ilya</b></sub>](https://twitter.com/ilya_komar0ff)<br />[💬](#question-Komar0ff "Answering Questions") [🤔](#ideas-Komar0ff "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/10627086?v=4" width="100px;"/><br /><sub><b>Emerson Laurentino</b></sub>](https://twitter.com/elaurent_)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=emersonlaurentino "Code") [🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3Aemersonlaurentino "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/19484365?v=4" width="100px;"/><br /><sub><b>Colton Colcleasure</b></sub>](https://github.com/colshacol)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=colshacol "Code") [🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3Acolshacol "Bug reports") | [<img src="https://avatars0.githubusercontent.com/u/497242?v=4" width="100px;"/><br /><sub><b>PJ Walker</b></sub>](https://github.com/PJWalker)<br />[🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3APJWalker "Bug reports") [💻](https://github.com/CompuIves/codesandbox-client/commits?author=PJWalker "Code") |
54+
| [<img src="https://avatars2.githubusercontent.com/u/10588170?v=4" width="100px;"/><br /><sub><b>Ilya</b></sub>](https://twitter.com/ilya_komar0ff)<br />[💬](#question-Komar0ff "Answering Questions") [🤔](#ideas-Komar0ff "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/10627086?v=4" width="100px;"/><br /><sub><b>Emerson Laurentino</b></sub>](https://twitter.com/elaurent_)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=emersonlaurentino "Code") [🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3Aemersonlaurentino "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/19484365?v=4" width="100px;"/><br /><sub><b>Colton Colcleasure</b></sub>](https://github.com/colshacol)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=colshacol "Code") |
55+
| [<img src="https://avatars2.githubusercontent.com/u/10588170?v=4" width="100px;"/><br /><sub><b>Ilya</b></sub>](https://twitter.com/ilya_komar0ff)<br />[💬](#question-Komar0ff "Answering Questions") [🤔](#ideas-Komar0ff "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/10627086?v=4" width="100px;"/><br /><sub><b>Emerson Laurentino</b></sub>](https://twitter.com/elaurent_)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=emersonlaurentino "Code") [🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3Aemersonlaurentino "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/29819102?v=4" width="100px;"/><br /><sub><b>Satya Rohith</b></sub>](https://satya.tech)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=satyarohith "Code") [📖](https://github.com/CompuIves/codesandbox-client/commits?author=satyarohith "Documentation") |
5456
<!-- ALL-CONTRIBUTORS-LIST:END -->

packages/app/src/app/pages/common/Modals/ShareModal/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ShareView extends React.Component {
3434
state = {
3535
showEditor: true,
3636
showPreview: true,
37+
testsView: false,
3738
defaultModule: null,
3839
autoResize: false,
3940
hideNavigation: false,
@@ -78,6 +79,7 @@ class ShareView extends React.Component {
7879
defaultModule,
7980
showEditor,
8081
showPreview,
82+
testsView,
8183
autoResize,
8284
hideNavigation,
8385
isCurrentModuleView,
@@ -107,10 +109,13 @@ class ShareView extends React.Component {
107109
options.view = 'preview';
108110
}
109111

112+
if (testsView) {
113+
options.previewwindow = 'tests';
114+
}
115+
110116
if (autoResize) {
111117
options.autoresize = 1;
112118
}
113-
114119
if (hideNavigation) {
115120
options.hidenavigation = 1;
116121
}
@@ -208,13 +213,18 @@ class ShareView extends React.Component {
208213

209214
setFontSize = (fontSize: number) => [this.setState({ fontSize })];
210215

216+
setTestsView = (testsView: boolean) => {
217+
this.setState({ testsView });
218+
};
219+
211220
render() {
212221
const sandbox = this.props.store.editor.currentSandbox;
213222
const mainModule = this.props.store.editor.mainModule;
214223

215224
const {
216225
showEditor,
217226
showPreview,
227+
testsView,
218228
autoResize,
219229
hideNavigation,
220230
isCurrentModuleView,
@@ -274,6 +284,12 @@ class ShareView extends React.Component {
274284
value={isCurrentModuleView}
275285
setValue={this.setIsCurrentModuleView}
276286
/>
287+
<PaddedPreference
288+
title="Show Tests (instead of browser preview)"
289+
type="boolean"
290+
value={testsView}
291+
setValue={this.setTestsView}
292+
/>
277293
<PaddedPreference
278294
title="Font size"
279295
type="number"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ export function setUrlOptions({ state, router, utils }) {
101101
state.set('preferences.showDevtools', options.expandDevTools);
102102
if (options.runOnClick)
103103
state.set(`preferences.runOnClick`, options.runOnClick);
104+
if (options.previewWindow) {
105+
state.set('editor.previewWindow.content', options.previewWindow);
106+
}
104107
}
105108

106109
export const setSandboxConfigOptions = ({ state }) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ export const setSandbox = [
297297
actions.setCurrentModuleShortid,
298298
actions.setMainModuleShortid,
299299
actions.setInitialTab,
300-
actions.setUrlOptions,
301300
actions.setSandboxConfigOptions,
301+
actions.setUrlOptions,
302302
actions.setWorkspace,
303303
];
304304

packages/app/src/embed/components/App/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type State = {
3030
fontSize: number,
3131
showEditor: boolean,
3232
showPreview: boolean,
33+
previewWindow: string,
3334
isInProjectView: boolean,
3435
currentModule: string,
3536
initialPath: string,
@@ -65,6 +66,7 @@ export default class App extends React.PureComponent<{}, State> {
6566
isInProjectView,
6667
isPreviewScreen,
6768
isEditorScreen,
69+
previewWindow,
6870
isSplitScreen,
6971
autoResize,
7072
hideNavigation,
@@ -85,6 +87,7 @@ export default class App extends React.PureComponent<{}, State> {
8587
fontSize: fontSize || 16,
8688
showEditor: isSplitScreen || isEditorScreen,
8789
showPreview: isSplitScreen || isPreviewScreen,
90+
previewWindow,
8891
isInProjectView,
8992
currentModule,
9093
initialPath,
@@ -216,6 +219,7 @@ export default class App extends React.PureComponent<{}, State> {
216219
showEditor,
217220
verticalMode,
218221
showPreview,
222+
previewWindow,
219223
isInProjectView,
220224
runOnClick,
221225
} = this.state;
@@ -239,6 +243,7 @@ export default class App extends React.PureComponent<{}, State> {
239243
<Content
240244
showEditor={showEditor}
241245
showPreview={showPreview}
246+
previewWindow={previewWindow}
242247
isInProjectView={isInProjectView}
243248
setProjectView={this.setProjectView}
244249
sandbox={sandbox}

packages/app/src/embed/components/Content/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type EmbedError = {
3434
type Props = {
3535
showEditor: boolean,
3636
showPreview: boolean,
37+
previewWindow: string,
3738
isInProjectView: boolean,
3839
setProjectView: (sandboxId?: ?string, isOpen: boolean, cb: Function) => void,
3940
sandbox: Sandbox,
@@ -298,6 +299,7 @@ export default class Content extends React.PureComponent<Props, State> {
298299
sandbox,
299300
showEditor,
300301
showPreview,
302+
previewWindow,
301303
currentModule,
302304
hideNavigation,
303305
isInProjectView,
@@ -315,8 +317,11 @@ export default class Content extends React.PureComponent<Props, State> {
315317
const sandboxConfig = sandbox.modules.find(
316318
x => x.directoryShortid == null && x.title === 'sandbox.config.json'
317319
);
320+
318321
let view = 'browser';
319-
if (sandboxConfig) {
322+
if (previewWindow) {
323+
view = previewWindow;
324+
} else if (sandboxConfig) {
320325
try {
321326
view = JSON.parse(sandboxConfig.code || '').view || 'browser';
322327
} catch (e) {

packages/common/url.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ export const getSandboxOptions = (url: string) => {
3535
result.isEditorScreen = url.includes('view=editor');
3636
result.isSplitScreen = url.includes('view=split');
3737

38+
result.isTestPreviewWindow = url.includes('previewwindow=tests');
39+
result.isConsolePreviewWindow = url.includes('previewwindow=console');
40+
41+
if (result.isTestPreviewWindow && !result.isConsolePreviewWindow) {
42+
result.previewWindow = 'tests';
43+
}
44+
45+
if (!result.isTestPreviewWindow && result.isConsolePreviewWindow) {
46+
result.previewWindow = 'console';
47+
}
3848
// If there is no view specified and the width of the window is <800 we want
3949
// to default to preview
4050
if (

packages/homepage/content/docs/2-embedding.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ find them here.
4242
| `expanddevtools` | Start with the devtools (console) open. | `0`/`1` | `0` |
4343
| `runonclick` | Only load the preview when the user says so. | `0`/`1` | `0` |
4444
| `view` | Which view to open by default | `editor`/`split`/`preview` | `split`, `preview` for small screens |
45+
| `previewwindow` | Which preview window to open by default | `console`/`tests`/`browser` | `browser` |
4546
| `module` | Which module to open by default | path to module (starting with `/`) | entry path |
4647
| `initialpath` | Which url to initially load in address bar | string | `/` |
4748
| `fontsize` | Font size of editor | number (in px) | `14` |

0 commit comments

Comments
 (0)