Skip to content

Commit

Permalink
Allows opening tests by default with share link (#959)
Browse files Browse the repository at this point in the history
* Share TestsView works 🎉

* Add docs for previewWindow

* Add satyarohith to contributors

* Support Embed

* Update 2-embedding.md
  • Loading branch information
Satya Rohith authored and CompuIves committed Jul 21, 2018
1 parent 5480144 commit 4525c1c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,16 @@
"bug",
"code"
]
},
{
"login": "satyarohith",
"name": "Satya Rohith",
"avatar_url": "https://avatars2.githubusercontent.com/u/29819102?v=4",
"profile": "https://satya.tech",
"contributions": [
"code",
"doc"
]
}
],
"repoType": "github"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ Thanks goes to these wonderful people
| [<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") |
| [<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") |
| [<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") |
| [<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") |
| [<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") |
<!-- ALL-CONTRIBUTORS-LIST:END -->
18 changes: 17 additions & 1 deletion packages/app/src/app/pages/common/Modals/ShareModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ShareView extends React.Component {
state = {
showEditor: true,
showPreview: true,
testsView: false,
defaultModule: null,
autoResize: false,
hideNavigation: false,
Expand Down Expand Up @@ -78,6 +79,7 @@ class ShareView extends React.Component {
defaultModule,
showEditor,
showPreview,
testsView,
autoResize,
hideNavigation,
isCurrentModuleView,
Expand Down Expand Up @@ -107,10 +109,13 @@ class ShareView extends React.Component {
options.view = 'preview';
}

if (testsView) {
options.previewwindow = 'tests';
}

if (autoResize) {
options.autoresize = 1;
}

if (hideNavigation) {
options.hidenavigation = 1;
}
Expand Down Expand Up @@ -208,13 +213,18 @@ class ShareView extends React.Component {

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

setTestsView = (testsView: boolean) => {
this.setState({ testsView });
};

render() {
const sandbox = this.props.store.editor.currentSandbox;
const mainModule = this.props.store.editor.mainModule;

const {
showEditor,
showPreview,
testsView,
autoResize,
hideNavigation,
isCurrentModuleView,
Expand Down Expand Up @@ -274,6 +284,12 @@ class ShareView extends React.Component {
value={isCurrentModuleView}
setValue={this.setIsCurrentModuleView}
/>
<PaddedPreference
title="Show Tests (instead of browser preview)"
type="boolean"
value={testsView}
setValue={this.setTestsView}
/>
<PaddedPreference
title="Font size"
type="number"
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/app/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export function setUrlOptions({ state, router, utils }) {
state.set('preferences.showDevtools', options.expandDevTools);
if (options.runOnClick)
state.set(`preferences.runOnClick`, options.runOnClick);
if (options.previewWindow) {
state.set('editor.previewWindow.content', options.previewWindow);
}
}

export const setSandboxConfigOptions = ({ state }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/app/store/sequences.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ export const setSandbox = [
actions.setCurrentModuleShortid,
actions.setMainModuleShortid,
actions.setInitialTab,
actions.setUrlOptions,
actions.setSandboxConfigOptions,
actions.setUrlOptions,
actions.setWorkspace,
];

Expand Down
5 changes: 5 additions & 0 deletions packages/app/src/embed/components/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type State = {
fontSize: number,
showEditor: boolean,
showPreview: boolean,
previewWindow: string,
isInProjectView: boolean,
currentModule: string,
initialPath: string,
Expand Down Expand Up @@ -65,6 +66,7 @@ export default class App extends React.PureComponent<{}, State> {
isInProjectView,
isPreviewScreen,
isEditorScreen,
previewWindow,
isSplitScreen,
autoResize,
hideNavigation,
Expand All @@ -85,6 +87,7 @@ export default class App extends React.PureComponent<{}, State> {
fontSize: fontSize || 16,
showEditor: isSplitScreen || isEditorScreen,
showPreview: isSplitScreen || isPreviewScreen,
previewWindow,
isInProjectView,
currentModule,
initialPath,
Expand Down Expand Up @@ -216,6 +219,7 @@ export default class App extends React.PureComponent<{}, State> {
showEditor,
verticalMode,
showPreview,
previewWindow,
isInProjectView,
runOnClick,
} = this.state;
Expand All @@ -239,6 +243,7 @@ export default class App extends React.PureComponent<{}, State> {
<Content
showEditor={showEditor}
showPreview={showPreview}
previewWindow={previewWindow}
isInProjectView={isInProjectView}
setProjectView={this.setProjectView}
sandbox={sandbox}
Expand Down
7 changes: 6 additions & 1 deletion packages/app/src/embed/components/Content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type EmbedError = {
type Props = {
showEditor: boolean,
showPreview: boolean,
previewWindow: string,
isInProjectView: boolean,
setProjectView: (sandboxId?: ?string, isOpen: boolean, cb: Function) => void,
sandbox: Sandbox,
Expand Down Expand Up @@ -298,6 +299,7 @@ export default class Content extends React.PureComponent<Props, State> {
sandbox,
showEditor,
showPreview,
previewWindow,
currentModule,
hideNavigation,
isInProjectView,
Expand All @@ -315,8 +317,11 @@ export default class Content extends React.PureComponent<Props, State> {
const sandboxConfig = sandbox.modules.find(
x => x.directoryShortid == null && x.title === 'sandbox.config.json'
);

let view = 'browser';
if (sandboxConfig) {
if (previewWindow) {
view = previewWindow;
} else if (sandboxConfig) {
try {
view = JSON.parse(sandboxConfig.code || '').view || 'browser';
} catch (e) {
Expand Down
10 changes: 10 additions & 0 deletions packages/common/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ export const getSandboxOptions = (url: string) => {
result.isEditorScreen = url.includes('view=editor');
result.isSplitScreen = url.includes('view=split');

result.isTestPreviewWindow = url.includes('previewwindow=tests');
result.isConsolePreviewWindow = url.includes('previewwindow=console');

if (result.isTestPreviewWindow && !result.isConsolePreviewWindow) {
result.previewWindow = 'tests';
}

if (!result.isTestPreviewWindow && result.isConsolePreviewWindow) {
result.previewWindow = 'console';
}
// If there is no view specified and the width of the window is <800 we want
// to default to preview
if (
Expand Down
1 change: 1 addition & 0 deletions packages/homepage/content/docs/2-embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ find them here.
| `expanddevtools` | Start with the devtools (console) open. | `0`/`1` | `0` |
| `runonclick` | Only load the preview when the user says so. | `0`/`1` | `0` |
| `view` | Which view to open by default | `editor`/`split`/`preview` | `split`, `preview` for small screens |
| `previewwindow` | Which preview window to open by default | `console`/`tests`/`browser` | `browser` |
| `module` | Which module to open by default | path to module (starting with `/`) | entry path |
| `initialpath` | Which url to initially load in address bar | string | `/` |
| `fontsize` | Font size of editor | number (in px) | `14` |
Expand Down

0 comments on commit 4525c1c

Please sign in to comment.