Skip to content

Feature/workspace empty #150

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

Merged
merged 3 commits into from
Mar 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import tutorialConfig from '../actions/tutorialConfig'
import { COMMANDS } from '../editor/commands'
import logger from '../services/logger'
import Context from './context'
import { openWorkspace, checkWorkspaceEmpty } from '../services/workspace'

interface Channel {
receive(action: T.Action): Promise<void>
Expand Down Expand Up @@ -108,6 +109,18 @@ class Channel implements Channel {
// update the current stepId on startup
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
return
case 'EDITOR_CHECK_WORKSPACE':
const isEmptyWorkspace = await checkWorkspaceEmpty(this.workspaceRoot.uri.path)
if (isEmptyWorkspace) {
this.send({ type: 'IS_EMPTY_WORKSPACE' })
} else {
this.send({ type: 'NOT_EMPTY_WORKSPACE' })
}
return
case 'EDITOR_REQUEST_WORKSPACE':
console.log('request workspace')
openWorkspace()
return
// load step actions (git commits, commands, open files)
case 'SETUP_ACTIONS':
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
Expand Down
4 changes: 2 additions & 2 deletions src/services/testRunner/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import node from '../../services/node'
import logger from '../../services/logger'
import node from '../node'
import logger from '../logger'
import parser from './parser'
import { debounce, throttle } from './throttle'
import onError from '../sentry/onError'
Expand Down
17 changes: 17 additions & 0 deletions src/services/workspace/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as vscode from 'vscode'
import * as fs from 'fs'

export const openWorkspace = () => {
const openInNewWindow = false
vscode.commands.executeCommand('vscode.openFolder', undefined, openInNewWindow)
}

export const checkWorkspaceEmpty = async (dirname: string) => {
let files
try {
files = await fs.promises.readdir(dirname)
} catch (error) {
throw new Error('Failed to check workspace')
}
return files.length === 0
}
2 changes: 2 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export interface MachineStateSchema {
Error: {}
LoadStoredTutorial: {}
Start: {}
CheckEmptyWorkspace: {}
NonEmptyWorkspace: {}
SelectTutorial: {}
LoadTutorialSummary: {}
Summary: {}
Expand Down
6 changes: 5 additions & 1 deletion web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import SelectTutorialPage from './containers/SelectTutorial'
import OverviewPage from './containers/Overview'
import CompletedPage from './containers/Tutorial/CompletedPage'
import LevelSummaryPage from './containers/Tutorial/LevelPage'
import SelectEmptyWorkspace from './containers/Check/SelectWorkspace'

const Routes = () => {
const { context, send, Router, Route } = useRouter()
return (
<Workspace>
<Router>
{/* Setup */}
<Route path={['Setup.Startup', 'Setup.Authenticate', 'Setup.LoadStoredTutorial']}>
<Route path={['Setup.Startup', 'Setup.Authenticate', 'Setup.LoadStoredTutorial', 'Setup.CheckEmptyWorkspace']}>
<LoadingPage text="Launching..." context={context} />
</Route>
<Route path="Setup.Start">
Expand All @@ -23,6 +24,9 @@ const Routes = () => {
<Route path={['Setup.LoadTutorialSummary', 'Setup.LoadTutorialData', 'Setup.SetupNewTutorial']}>
<LoadingPage text="Loading Tutorial..." context={context} />
</Route>
<Route path={['Setup.NonEmptyWorkspace', 'Setup.RequestEmptyWorkspace']}>
<SelectEmptyWorkspace send={send} />
</Route>
<Route path="Setup.Error">
<LoadingPage text="Error" context={context} />
</Route>
Expand Down
31 changes: 31 additions & 0 deletions web-app/src/containers/Check/SelectWorkspace.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react'
import * as T from 'typings'
import { css, jsx } from '@emotion/core'
import Button from '../../components/Button'

const styles = {
container: {
padding: '1rem',
},
}

type Props = {
send: (action: T.Action) => void
}

const SelectWorkspace = (props: Props) => {
const onOpenWorkspace = () => props.send({ type: 'REQUEST_WORKSPACE' })
return (
<div css={styles.container}>
<h3>Select An Empty VSCode Workspace</h3>
<p>Start a project in an empty folder.</p>
<p>Once selected, the extension will close and need to be re-started.</p>
<br />
<Button type="secondary" onClick={onOpenWorkspace}>
Open a Workspace
</Button>
</div>
)
}

export default SelectWorkspace
10 changes: 10 additions & 0 deletions web-app/src/services/state/actions/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ export default (editorSend: any) => ({
clearStorage(): void {
editorSend({ type: 'TUTORIAL_CLEAR' })
},
checkEmptyWorkspace() {
editorSend({
type: 'EDITOR_CHECK_WORKSPACE',
})
},
requestWorkspaceSelect() {
editorSend({
type: 'EDITOR_REQUEST_WORKSPACE',
})
},
})
18 changes: 17 additions & 1 deletion web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,29 @@ export const createMachine = (options: any) => {
},
Start: {
on: {
NEW_TUTORIAL: 'SelectTutorial',
NEW_TUTORIAL: 'CheckEmptyWorkspace',
CONTINUE_TUTORIAL: {
target: '#tutorial-level',
actions: ['continueConfig'],
},
},
},
CheckEmptyWorkspace: {
onEntry: ['checkEmptyWorkspace'],
on: {
IS_EMPTY_WORKSPACE: 'SelectTutorial',
NOT_EMPTY_WORKSPACE: 'NonEmptyWorkspace',
},
},
NonEmptyWorkspace: {
on: {
REQUEST_WORKSPACE: {
target: 'NonEmptyWorkspace',
actions: 'requestWorkspaceSelect',
},
WORKSPACE_LOADED: 'CheckEmptyWorkspace',
},
},
SelectTutorial: {
onEntry: ['clearStorage'],
id: 'select-new-tutorial',
Expand Down
21 changes: 21 additions & 0 deletions web-app/stories/Check.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'
import React from 'react'
import { css, jsx } from '@emotion/core'
import SelectWorkspace from '../src/containers/Check/SelectWorkspace'
import SideBarDecorator from './utils/SideBarDecorator'

const styles = {
container: {
display: 'flex' as 'flex',
flexDirection: 'column' as 'column',
},
}

storiesOf('Check', module)
.addDecorator(SideBarDecorator)
.add('Select Workspace', () => (
<div css={styles.container}>
<SelectWorkspace send={action('send')} />
</div>
))