8000 Merge pull request #289 from coderoad/refactor · yunyan523/coderoad-vscode@5f5d70e · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f5d70e

Browse files
authored
Merge pull request coderoad#289 from coderoad/refactor
Refactor
2 parents 078bea0 + 84adae8 commit 5f5d70e

File tree

15 files changed

+48
-53
lines changed
  • stories
  • 15 files changed

    +48
    -53
    lines changed

    src/actions/setupActions.ts

    Lines changed: 0 additions & 8 deletions
    Original file line numberDiff line numberDiff line change
    @@ -6,12 +6,6 @@ import openFiles from './utils/openFiles'
    66
    import runCommands from './utils/runCommands'
    77
    import onError from '../services/sentry/onError'
    88

    9-
    async function wait(ms: number) {
    10-
    return new Promise((resolve) => {
    11-
    setTimeout(resolve, ms)
    12-
    })
    13-
    }
    14-
    159
    interface SetupActions {
    1610
    actions: TT.StepActions
    1711
    send: (action: T.Action) => void // send messages to client
    @@ -35,8 +29,6 @@ export const setupActions = async ({ actions, send, path }: SetupActions): Promi
    3529
    // 3. start file watchers
    3630
    loadWatchers(watchers || [])
    3731

    38-
    await wait(1000)
    39-
    4032
    // 4. run command
    4133
    await runCommands({ commands: commands || [], send, path }).catch(onError)
    4234
    }

    src/channel/index.ts

    Lines changed: 19 additions & 18 deletions
    Original file line numberDiff line numberDiff line change
    @@ -76,30 +76,31 @@ class Channel implements Channel {
    7676
    const tutorial: TT.Tutorial | null = this.context.tutorial.get()
    7777

    7878
    // new tutorial
    79-
    if (!tutorial || !tutorial.id) {
    80-
    this.send({ type: 'START_NEW_TUTORIAL', payload: { env } })
    81-
    return
    82-
    }
    79+
    this.send({ type: 'START_NEW_TUTORIAL', payload: { env } })
    80+
    return
    8381

    84-
    // set tutorial
    85-
    const { position, progress } = await this.context.setTutorial(this.workspaceState, tutorial)
    82+
    // disable continue until fixed
    8683

    87-
    if (progress.complete) {
    88-
    // tutorial is already complete
    89-
    this.send({ type: 'TUTORIAL_ALREADY_COMPLETE', payload: { env } })
    90-
    return
    91-
    }
    92-
    // communicate to client the tutorial & stepProgress state
    93-
    this.send({ type: 'LOAD_STORED_TUTORIAL', payload: { env, tutorial, progress, position } })
    84+
    // // set tutorial
    85+
    // const { position, progress } = await this.context.setTutorial(this.workspaceState, tutorial)
    9486

    95-
    return
    87+
    // if (progress.complete) {
    88+
    // // tutorial is already complete
    89+
    // this.send({ type: 'TUTORIAL_ALREADY_COMPLETE', payload: { env } })
    90+
    // return
    91+
    // }
    92+
    // // communicate to client the tutorial & stepProgress state
    93+
    // this.send({ type: 'LOAD_STORED_TUTORIAL', payload: { env, tutorial, progress, position } })
    94+
    95+
    // return
    9696
    } catch (e) {
    9797
    const error = {
    9898
    type: 'UnknownError',
    9999
    message: `Location: Editor startup\n\n${e.message}`,
    100100
    }
    101101
    this.send({ type: 'EDITOR_STARTUP_FAILED', payload: { error } })
    102102
    }
    103+
    return
    103104

    104105
    // clear tutorial local storage
    105106
    case 'TUTORIAL_CLEAR':
    @@ -203,14 +204,14 @@ class Channel implements Channel {
    203204

    204205
    // report back to the webview that setup is complete
    205206
    this.send({ type: 'TUTORIAL_CONFIGURED' })
    206-
    return
    207207
    } catch (e) {
    208208
    const error = {
    209209
    type: 'UnknownError',
    210210
    message: `Location: EditorTutorialConfig.\n\n ${e.message}`,
    211211
    }
    212212
    this.send({ type: 'TUTORIAL_CONFIGURE_FAIL', payload: { error } })
    213213
    }
    214+
    return
    214215
    case 'EDITOR_TUTORIAL_CONTINUE_CONFIG':
    215216
    try {
    216217
    const tutorialContinue: TT.Tutorial | null = this.context.tutorial.get()
    @@ -224,14 +225,14 @@ class Channel implements Channel {
    224225
    })
    225226
    // update the current stepId on startup
    226227
    vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
    227-
    return
    228228
    } catch (e) {
    229229
    const error = {
    230230
    type: 'UnknownError',
    231231
    message: `Location: Editor tutorial continue config.\n\n ${e.message}`,
    232232
    }
    233233
    this.send({ type: 'CONTINUE_FAILED', payload: { error } })
    234234
    }
    235+
    return
    235236
    case 'EDITOR_VALIDATE_SETUP':
    236237
    try {
    237238
    // check workspace is selected
    @@ -272,14 +273,14 @@ class Channel implements Channel {
    272273
    return
    273274
    }
    274275
    this.send({ type: 'SETUP_VALIDATED' })
    275-
    return
    276276
    } catch (e) {
    277277
    const error = {
    278278
    type: 'UknownError',
    279279
    message: e.message,
    280280
    }
    281281
    this.send({ type: 'VALIDATE_SETUP_FAILED', payload: { error } })
    282282
    }
    283+
    return
    283284
    case 'EDITOR_REQUEST_WORKSPACE':
    284285
    openWorkspace()
    285286
    return
    @@ -329,7 +330,7 @@ class Channel implements Channel {
    329330
    case 'TEST_PASS':
    330331
    const tutorial = this.context.tutorial.get()
    331332
    if (!tutorial) {
    332-
    throw new Error('Error with current tutorial')
    333+
    throw new Error('Error with current tutorial. Tutorial may be missing an id.')
    333334
    }
    334335
    // update local storage stepProgress
    335336
    const progress = this.context.progress.setStepComplete(tutorial, action.payload.stepId)

    src/editor/commands.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -20,7 +20,7 @@ interface CreateCommandProps {
    2020
    export const createCommands = ({ extensionPath, workspaceState }: CreateCommandProps) => {
    2121
    // React panel webview
    2222
    let webview: any
    23-
    let currentStepId = ''
    23+
    let currentStepId: string | null = ''
    2424
    let testRunner: any
    2525

    2626
    return {
    @@ -79,7 +79,7 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
    7979
    },
    8080
    [COMMANDS.RUN_TEST]: (current: Payload | undefined, onSuccess: () => void) => {
    8181
    // use stepId from client, or last set stepId
    82-
    const payload: Payload = { stepId: current && current.stepId.length ? current.stepId : currentStepId }
    82+
    const payload: Payload = { stepId: current && current.stepId?.length ? current.stepId : currentStepId }
    8383
    testRunner(payload, onSuccess)
    8484
    },
    8585
    }

    src/environment.ts

    Lines changed: 1 addition & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -14,8 +14,7 @@ export type Env = 'test' | 'local' | 'development' | 'production'
    1414
    export const NODE_ENV: Env = process.env.NODE_ENV || 'production'
    1515

    1616
    // toggle logging in development
    17-
    export const LOG: boolean =
    18-
    (process.env.REACT_APP_LOG || '').toLowerCase() === 'true' && process.env.NODE_ENV !== 'production'
    17+
    export const LOG: boolean = (process.env.REACT_APP_LOG || '').toLowerCase() === 'true'
    1918

    2019
    // error logging tool
    2120
    export const SENTRY_DSN: string | null = process.env.SENTRY_DSN || null

    src/services/logger/index.ts

    Lines changed: 11 additions & 5 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,13 +1,19 @@
    11
    import { LOG } from '../../environment'
    22

    3-
    const logger = (message: string | string[]) => {
    3+
    export type Log = string | object | null
    4+
    5+
    const logger = (...messages: Log[]): void => {
    46
    if (!LOG) {
    57
    return
    68
    }
    7-
    if (Array.isArray(message)) {
    8-
    message.forEach(console.log)
    9-
    } else {
    10-
    console.log(message)
    9+
    // Inside vscode, you console.log does not allow more than 1 param
    10+
    // to get around it, we can log with multiple log statements
    11+
    for (const message of messages) {
    12+
    if (typeof message === 'object') {
    13+
    console.log(JSON.stringify(message))
    14+
    } else {
    15+
    console.log(message)
    16+
    }
    1117
    }
    1218
    }
    1319

    src/services/testRunner/index.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@ import { clearOutput, displayOutput } from './output'
    88
    import { formatFailOutput } from './formatOutput'
    99

    1010
    export interface Payload {
    11-
    stepId: string
    11+
    stepId: string | null
    1212
    }
    1313

    1414
    interface Callbacks {

    typings/index.d.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -65,11 +65,11 @@ export interface MachineStateSchema {
    6565
    Setup: {
    6666
    states: {
    6767
    Startup: {}
    68-
    Start: {}
    6968
    ValidateSetup: {}
    69+
    Start: {}
    7070
    SelectTutorial: {}
    7171
    SetupNewTutorial: {}
    72-
    StartNewTutorial: {}
    72+
    StartTutorial: {}
    7373
    }
    7474
    }
    7575
    Tutorial: {

    web-app/src/Routes.tsx

    Lines changed: 3 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -6,7 +6,7 @@ import LoadingPage from './containers/Loading'
    66
    import StartPage from './containers/Start'
    77
    import SelectTutorialPage from './containers/SelectTutorial'
    88
    import CompletedPage from './containers/Tutorial/CompletedPage'
    9-
    import LevelSummaryPage from './containers/Tutorial/LevelPage'
    9+
    import TutorialPage from './containers/Tutorial'
    1010

    1111
    const Routes = () => {
    1212
    const { context, send, Router, Route } = useRouter()
    @@ -30,21 +30,18 @@ const Routes = () => {
    3030
    <Route path="Setup.Start">
    3131
    <StartPage send={send} context={context} />
    3232
    </Route>
    33-
    <Route path={['Setup.LoadTutorialSummary', 'Setup.LoadTutorialData', 'Setup.SetupNewTutorial']}>
    34-
    <LoadingPage text="Loading Tutorial..." processes={context.processes} />]
    35-
    </Route>
    3633
    <Route path="Setup.SelectTutorial">
    3734
    <SelectTutorialPage send={send} context={context} />
    3835
    </Route>
    39-
    <Route path={['Setup.SetupNewTutorial', 'Setup.StartNewTutorial']}>
    36+
    <Route path={['Setup.SetupNewTutorial', 'Setup.StartTutorial']}>
    4037
    <LoadingPage text="Configuring tutorial..." />
    4138
    </Route>
    4239
    {/* Tutorial */}
    4340
    <Route path={['Tutorial.LoadNext', 'Tutorial.Level.Load']}>
    4441
    <LoadingPage text="Loading Level..." processes={context.processes} />
    4542
    </Route>
    4643
    <Route path="Tutorial.Level">
    47-
    <LevelSummaryPage send={send} context={context} />
    44+
    <TutorialPage send={send} context={context} />
    4845
    </Route>
    4946
    {/* Completed */}
    5047
    <Route path="Tutorial.Completed">

    web-app/src/containers/Tutorial/LevelPage/index.tsx renamed to web-app/src/containers/Tutorial/index.tsx

    Lines changed: 4 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,15 +1,15 @@
    11
    import * as React from 'react'
    22
    import * as T from 'typings'
    33
    import * as TT from 'typings/tutorial'
    4-
    import * as selectors from '../../../services/selectors'
    5-
    import Level from './Level'
    4+
    import * as selectors from '../../services/selectors'
    5+
    import Level from './components/Level'
    66

    77
    interface PageProps {
    88
    context: T.MachineContext
    99
    send(action: T.Action): void
    1010
    }
    1111

    12-
    const LevelSummaryPageContainer = (props: PageProps) => {
    12+
    const TutorialPage = (props: PageProps) => {
    1313
    const { position, progress, processes, testStatus } = props.context
    1414

    1515
    const tutorial = selectors.currentTutorial(props.context)
    @@ -59,4 +59,4 @@ const LevelSummaryPageContainer = (props: PageProps) => {
    5959
    )
    6060
    }
    6161

    62-
    export default LevelSummaryPageContainer
    62+
    export default TutorialPage

    web-app/src/services/state/machine.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -123,10 +123,10 @@ export const createMachine = (options: any) => {
    123123
    actions: ['setError'],
    124124
    },
    125125
    TRY_AGAIN: 'SetupNewTutorial',
    126-
    TUTORIAL_CONFIGURED: 'StartNewTutorial',
    126+
    TUTORIAL_CONFIGURED: 'StartTutorial',
    127127
    },
    128128
    },
    129-
    StartNewTutorial: {
    129+
    StartTutorial: {
    130130
    onEntry: ['startNewTutorial'],
    131131
    after: {
    132132
    0: '#tutorial',

    web-app/stories/Completed.stories.tsx

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -6,4 +6,4 @@ import SideBarDecorator from './utils/SideBarDecorator'
    66

    77
    storiesOf('Completed', module)
    88
    .addDecorator(SideBarDecorator)
    9-
    .add('Page', () => <CompletedPage context={{}} send={action('send')} />)
    9+
    .add('Page', () => <CompletedPage context={{}} />)

    web-app/stories/Level.stories.tsx

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -4,7 +4,7 @@ import { storiesOf } from '@storybook/react'
    44
    import React from 'react'
    55
    import * as T from '../../typings'
    66
    import * as TT from '../../typings/tutorial'
    7-
    import Level from '../src/containers/Tutorial/LevelPage/Level'
    7+
    import Level from '../src/containers/Tutorial/components/Level'
    88
    import SideBarDecorator from './utils/SideBarDecorator'
    99

    1010
    type ModifiedLevel = TT.Level & {

    web-app/stories/Step.stories.tsx

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -2,7 +2,7 @@ import { action } from '@storybook/addon-actions'
    22
    import { select, text, withKnobs } from '@storybook/addon-knobs'
    33
    import { storiesOf } from '@storybook/react'
    44
    import React from 'react'
    5-
    import Step from '../src/containers/Tutorial/LevelPage/Step'
    5+
    import Step from '../src/containers/Tutorial/components/Step'
    66
    import SideBarDecorator from './utils/SideBarDecorator'
    77

    88
    const stepText =

    0 commit comments

    Comments
     (0)
    0