Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows opening tests by default with share link #959

Merged
merged 5 commits into from
Jul 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,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 @@ -49,4 +49,6 @@ Thanks goes to these wonderful people
| [<img src="https://avatars0.githubusercontent.com/u/1820292?v=4" width="100px;"/><br /><sub><b>Michel Weststrate</b></sub>](https://twitter.com/mweststrate)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=mweststrate "Code") | [<img src="https://avatars0.githubusercontent.com/u/52824?v=4" width="100px;"/><br /><sub><b>Oleg</b></sub>](https://kof.github.io)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=kof "Code") | [<img src="https://avatars0.githubusercontent.com/u/1127037?v=4" width="100px;"/><br /><sub><b>Paul Sherman</b></sub>](https://www.pshrmn.com)<br />[🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3Apshrmn "Bug reports") [💻](https://github.com/CompuIves/codesandbox-client/commits?author=pshrmn "Code") | [<img src="https://avatars2.githubusercontent.com/u/9244507?v=4" width="100px;"/><br /><sub><b>Ro Savage</b></sub>](https://github.com/ro-savage)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=ro-savage "Code") | [<img src="https://avatars3.githubusercontent.com/u/13242392?v=4" width="100px;"/><br /><sub><b>Sam Denty</b></sub>](https://samdd.me)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=samdenty99 "Code") | [<img src="https://avatars1.githubusercontent.com/u/3087225?v=4" width="100px;"/><br /><sub><b>Zephraph</b></sub>](https://github.com/zephraph)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=zephraph "Code") | [<img src="https://avatars1.githubusercontent.com/u/1900735?v=4" width="100px;"/><br /><sub><b>Josh Waller</b></sub>](https://www.joshwaller.me)<br />[🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3Amdxprograms "Bug reports") [💻](https://github.com/CompuIves/codesandbox-client/commits?author=mdxprograms "Code") [📖](https://github.com/CompuIves/codesandbox-client/commits?author=mdxprograms "Documentation") |
| [<img src="https://avatars0.githubusercontent.com/u/1195863?v=4" width="100px;"/><br /><sub><b>Joe Ng'ethe</b></sub>](http://joey.co.ke)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=joeynimu "Code") | [<img src="https://avatars0.githubusercontent.com/u/576935?v=4" width="100px;"/><br /><sub><b>Carles Codony</b></sub>](https://github.com/bitblitter)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=bitblitter "Code") | [<img src="https://avatars2.githubusercontent.com/u/468006?v=4" width="100px;"/><br /><sub><b>Vytenis</b></sub>](https://github.com/FDiskas)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=FDiskas "Code") | [<img src="https://avatars1.githubusercontent.com/u/894149?v=4" width="100px;"/><br /><sub><b>Manuel Dugué</b></sub>](http://manueldugue.de)<br />[🐛](https://github.com/CompuIves/codesandbox-client/issues?q=author%3Amdugue "Bug reports") [💻](https://github.com/CompuIves/codesandbox-client/commits?author=mdugue "Code") | [<img src="https://avatars2.githubusercontent.com/u/5346497?v=4" width="100px;"/><br /><sub><b>Demian Dekoninck</b></sub>](https://dem.be)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=DemianD "Code") | [<img src="https://avatars2.githubusercontent.com/u/3144549?v=4" width="100px;"/><br /><sub><b>Drake Costa</b></sub>](http://www.saeris.io)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=Saeris "Code") | [<img src="https://avatars2.githubusercontent.com/u/433394?v=4" width="100px;"/><br /><sub><b>Marko Stijak</b></sub>](https://cxjs.io/)<br />[💻](https://github.com/CompuIves/codesandbox-client/commits?author=mstijak "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