Skip to content

Commit 687952f

Browse files
committed
Improve UX of handling templates and add static
- Allow people to switch templates of a sandbox - Enable new SSE templates - Ember - Sapper - Nest - Add static template - Has no bundling - Allow editing of the main file - Disable React Typescript, has been replaced with CRA
1 parent 3dccb96 commit 687952f

File tree

22 files changed

+177
-48
lines changed

22 files changed

+177
-48
lines changed

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"circular-json": "^0.4.0",
145145
"codemirror": "^5.27.4",
146146
"codesandbox-api": "^0.0.18",
147-
"codesandbox-import-utils": "^1.3.3",
147+
"codesandbox-import-utils": "1.3.5",
148148
"color": "^0.11.4",
149149
"compare-versions": "^3.1.0",
150150
"console-feed": "^2.8.0",

packages/app/src/app/components/CodeEditor/Configuration/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default class Configuration extends React.PureComponent<Props>
8585
};
8686

8787
render() {
88-
const { config, width, height } = this.props;
88+
const { config, width, height, sandbox } = this.props;
8989
const currentModule = this.currentModule;
9090

9191
const { ConfigWizard } = getUI(config.type);
@@ -117,7 +117,11 @@ export default class Configuration extends React.PureComponent<Props>
117117
</a>
118118
</Description>
119119

120-
<ConfigWizard updateFile={this.updateFile} file={currentModule.code} />
120+
<ConfigWizard
121+
sandbox={sandbox}
122+
updateFile={this.updateFile}
123+
file={currentModule.code}
124+
/>
121125
</Container>
122126
);
123127
}

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/DirectoryChildren/ModuleEntry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class ModuleEntry extends React.Component {
4646
depth={depth + 1}
4747
active={isActive}
4848
type={type || 'function'}
49-
rename={isMainModule ? undefined : renameModule}
50-
deleteEntry={isMainModule ? undefined : deleteEntry}
49+
rename={renameModule}
50+
deleteEntry={deleteEntry}
5151
isNotSynced={isNotSynced}
5252
renameValidator={this.validateTitle}
5353
setCurrentModule={setCurrentModule}

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/elements.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import styled from 'styled-components';
22
import NotSyncedIcon from 'react-icons/lib/go/primitive-dot';
33

44
export const Right = styled.div`
5+
display: flex;
6+
align-items: center;
57
position: absolute;
68
right: 1rem;
79
`;

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/index.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,29 @@ class Entry extends React.PureComponent {
185185
{isNotSynced && !state && <NotSyncedIconWithMargin />}
186186
{state === '' && (
187187
<Right>
188-
{isMainModule ? (
189-
<span style={{ opacity: hovering ? 1 : 0 }}>main</span>
190-
) : (
191-
<EditIcons
192-
hovering={hovering}
193-
onCreateFile={onCreateModuleClick}
194-
onCreateDirectory={onCreateDirectoryClick}
195-
onUploadFile={onUploadFileClick}
196-
onDelete={deleteEntry && this.delete}
197-
onEdit={rename && this.rename}
198-
active={active}
199-
forceShow={window.__isTouch && type === 'directory-open'}
200-
/>
188+
{isMainModule && (
189+
<span
190+
style={{
191+
fontSize: '.75rem',
192+
fontWeight: 600,
193+
opacity: hovering ? 0.6 : 0,
194+
marginTop: 3,
195+
marginRight: 3,
196+
}}
197+
>
198+
entry
199+
</span>
201200
)}
201+
<EditIcons
202+
hovering={hovering}
203+
onCreateFile={onCreateModuleClick}
204+
onCreateDirectory={onCreateDirectoryClick}
205+
onUploadFile={onUploadFileClick}
206+
onDelete={deleteEntry && this.delete}
207+
onEdit={rename && this.rename}
208+
active={active}
209+
forceShow={window.__isTouch && type === 'directory-open'}
210+
/>
202211
</Right>
203212
)}
204213
</EntryContainer>
@@ -209,7 +218,7 @@ class Entry extends React.PureComponent {
209218
}
210219

211220
const entrySource = {
212-
canDrag: props => !!props.id && !props.isMainModule,
221+
canDrag: props => !!props.id,
213222
beginDrag: props => {
214223
if (props.closeTree) props.closeTree();
215224

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/ConfigurationFiles/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ const ConfigurationFiles = ({ store, signals }) => {
121121

122122
return (
123123
<FileConfig
124+
key={path}
124125
openModule={id => {
125126
signals.editor.moduleSelected({ id });
126127
}}
@@ -137,6 +138,7 @@ const ConfigurationFiles = ({ store, signals }) => {
137138

138139
return (
139140
<FileConfig
141+
key={path}
140142
createModule={title => {
141143
signals.files.moduleCreated({ title });
142144
}}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { sandboxUrl } from 'common/utils/url-generator';
44

55
import NewSandboxModal from '../../../Dashboard/Content/CreateNewSandbox/Modal';
66

7-
export default () => (
7+
export default ({ closeModal }) => (
88
<NewSandboxModal
99
createSandbox={template => {
1010
history.push(sandboxUrl({ id: template.shortid }));
11+
closeModal();
1112
}}
13+
closeOnCreate
1214
width={925}
1315
/>
1416
);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ function Modals({ store, signals }) {
105105
width={modal && modal.width}
106106
onClose={(isKeyDown: boolean) => signals.modalClosed({ isKeyDown })}
107107
>
108-
{modal ? React.createElement(modal.Component) : null}
108+
{modal
109+
? React.createElement(modal.Component, {
110+
closeModal: () => signals.modalClosed({ isKeyDown: false }),
111+
})
112+
: null}
109113
</Modal>
110114
);
111115
}

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fromPairs, toPairs, sortBy } from 'lodash-es';
1+
import { fromPairs, toPairs, sortBy, mapValues } from 'lodash-es';
22
import slugify from 'common/utils/slugify';
33
import { clone } from 'mobx-state-tree';
44

@@ -434,14 +434,38 @@ export function updateTemplateIfSSE({ state, api }) {
434434
const currentTemplate = state.get('editor.currentSandbox.template');
435435
const templateDefinition = getTemplate(currentTemplate);
436436

437-
if (templateDefinition.isServer) {
437+
const shouldUpdateTemplate = (() => {
438+
// We always want to be able to update server template based on its detection.
439+
// We only want to update the client template when it's explicitly specified
440+
// in the sandbox configuration.
441+
442+
if (templateDefinition.isServer) {
443+
return true;
444+
}
445+
446+
const sandboxConfig = state.get('editor.parsedConfigurations.sandbox');
447+
448+
if (sandboxConfig.parsed.template) {
449+
return true;
450+
}
451+
452+
return false;
453+
})();
454+
455+
if (shouldUpdateTemplate) {
438456
const { parsed } = state.get('editor.parsedConfigurations.package');
439457

440-
const newTemplate = computeTemplate(parsed, {}) || 'node';
458+
const a = Date.now();
459+
const modulesByPath = mapValues(state.get('editor.modulesByPath'), m => ({
460+
content: m.code,
461+
isBinary: m.isBinary,
462+
}));
463+
464+
const newTemplate = computeTemplate(parsed, modulesByPath) || 'node';
441465

442466
if (
443467
newTemplate !== currentTemplate &&
444-
getTemplate(newTemplate).isServer
468+
templateDefinition.isServer === getTemplate(newTemplate).isServer
445469
) {
446470
state.set('editor.currentSandbox.template', newTemplate);
447471
api.put(`/sandboxes/${state.get('editor.currentSandbox.id')}/`, {

packages/common/components/Preference/PreferenceDropdown.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ export default class PreferenceInput extends React.PureComponent {
99
};
1010

1111
render() {
12-
const { value, options } = this.props;
12+
const { value, options, mapName } = this.props;
1313

1414
return (
1515
<Select onChange={this.handleChange} value={value}>
16-
{options.map(op => <option key={op}>{op}</option>)}
16+
{options.map(op => (
17+
<option key={op} value={op}>
18+
{mapName ? mapName(op) : op}
19+
</option>
20+
))}
1721
</Select>
1822
);
1923
}

0 commit comments

Comments
 (0)