From 9a17558226ca37097a0d6ccbd9b19854f601feaf Mon Sep 17 00:00:00 2001 From: Chee Yuan Date: Thu, 1 Aug 2019 17:00:58 +0800 Subject: [PATCH 1/4] Expose ExternaLibrary outside of Playground, Record ExternaLibrary change --- src/actions/__tests__/sourcecast.ts | 3 +++ src/actions/__tests__/sourcereel.ts | 23 +++++++++++----- src/actions/actionTypes.ts | 2 +- src/actions/sourcereel.ts | 8 +++--- src/actions/workspaces.ts | 5 ++-- src/components/sourcecast/Sourcecast.tsx | 13 ++++++++- .../sourcecast/SourcecastControlbar.tsx | 5 ++++ src/components/sourcecast/Sourcereel.tsx | 27 +++++++++++++++++-- .../sourcecast/SourcereelControlbar.tsx | 6 ++--- src/components/sourcecast/sourcecastShape.ts | 5 ++++ .../sourcecast/SourcecastContainer.ts | 7 ++++- .../sourcecast/SourcereelContainer.ts | 10 ++++--- src/reducers/__tests__/sourcecast.ts | 5 ++++ src/reducers/__tests__/sourcereel.ts | 25 ++++++++++------- src/reducers/sourcereel.ts | 8 +++--- src/reducers/states.ts | 14 +++++----- src/reducers/workspaces.ts | 4 +-- src/sagas/__tests__/workspaces.ts | 2 +- src/sagas/workspaces.ts | 4 +-- 19 files changed, 126 insertions(+), 50 deletions(-) diff --git a/src/actions/__tests__/sourcecast.ts b/src/actions/__tests__/sourcecast.ts index 9e15671a50..588da25322 100644 --- a/src/actions/__tests__/sourcecast.ts +++ b/src/actions/__tests__/sourcecast.ts @@ -1,3 +1,4 @@ +import { ExternalLibraryNames } from '../../components/assessment/assessmentShape'; import { ICodeDelta, Input, @@ -102,6 +103,8 @@ test('setSourcecastData generates correct action object', () => { }; const playbackData: IPlaybackData = { init: { + chapter: 1, + externalLibrary: ExternalLibraryNames.NONE, editorValue: '' }, inputs: [input] diff --git a/src/actions/__tests__/sourcereel.ts b/src/actions/__tests__/sourcereel.ts index d0890d4e4f..6a536da85c 100644 --- a/src/actions/__tests__/sourcereel.ts +++ b/src/actions/__tests__/sourcereel.ts @@ -1,7 +1,8 @@ +import { ExternalLibraryNames } from '../../components/assessment/assessmentShape'; import { ICodeDelta, Input, IPlaybackData } from '../../components/sourcecast/sourcecastShape'; import * as actionTypes from '../actionTypes'; import { - recordEditorInitValue, + recordInit, recordInput, saveSourcecastData, timerPause, @@ -18,13 +19,17 @@ function dateIsCloseEnough(dateA: number, dateB: number) { return Math.abs(dateA - dateB) <= 1000; } -test('recordEditorInitValue generates correct action object', () => { - const editorValue = 'Init Value'; - const action = recordEditorInitValue(editorValue, sourcereelWorkspace); +test('recordInit generates correct action object', () => { + const initData: IPlaybackData['init'] = { + editorValue: 'Init Value', + chapter: 1, + externalLibrary: ExternalLibraryNames.NONE + }; + const action = recordInit(initData, sourcereelWorkspace); expect(action).toEqual({ - type: actionTypes.RECORD_EDITOR_INIT_VALUE, + type: actionTypes.RECORD_INIT, payload: { - editorValue, + initData, workspaceLocation: sourcereelWorkspace } }); @@ -66,7 +71,11 @@ test('saveSourcecastData generates correct action object', () => { const description = 'Test Description'; const audio = new Blob(); const playbackData: IPlaybackData = { - init: { editorValue: 'Editor Init Value' }, + init: { + editorValue: 'Editor Init Value', + chapter: 1, + externalLibrary: ExternalLibraryNames.NONE + }, inputs: [] }; const action = saveSourcecastData(title, description, audio, playbackData, sourcereelWorkspace); diff --git a/src/actions/actionTypes.ts b/src/actions/actionTypes.ts index 0fec33aed0..e105c3ad2d 100755 --- a/src/actions/actionTypes.ts +++ b/src/actions/actionTypes.ts @@ -76,7 +76,7 @@ export const UPDATE_SOURCECAST_INDEX = 'UPDATE_SOURCECAST_INDEX'; /** Sourcereel */ export const RECORD_INPUT = 'RECORD_INPUT'; -export const RECORD_EDITOR_INIT_VALUE = 'RECORD_EDITOR_INIT_VALUE'; +export const RECORD_INIT = 'RECORD_INIT'; export const SAVE_SOURCECAST_DATA = 'SAVE_SOURCECAST_DATA'; export const TIMER_PAUSE = 'TIMER_PAUSE'; export const TIMER_RESET = 'TIMER_RESET'; diff --git a/src/actions/sourcereel.ts b/src/actions/sourcereel.ts index 10868475c8..80d4a965f5 100644 --- a/src/actions/sourcereel.ts +++ b/src/actions/sourcereel.ts @@ -2,13 +2,13 @@ import { Input, IPlaybackData } from '../components/sourcecast/sourcecastShape'; import * as actionTypes from './actionTypes'; import { WorkspaceLocation } from './workspaces'; -export const recordEditorInitValue = ( - editorValue: string, +export const recordInit = ( + initData: IPlaybackData['init'], workspaceLocation: WorkspaceLocation ) => ({ - type: actionTypes.RECORD_EDITOR_INIT_VALUE, + type: actionTypes.RECORD_INIT, payload: { - editorValue, + initData, workspaceLocation } }); diff --git a/src/actions/workspaces.ts b/src/actions/workspaces.ts index bfa996cfce..25512d8f79 100755 --- a/src/actions/workspaces.ts +++ b/src/actions/workspaces.ts @@ -39,10 +39,11 @@ export const browseReplHistoryUp: ActionCreator = ( }); export const changePlaygroundExternal: ActionCreator = ( - newExternal: string + newExternal: string, + workspaceLocation: WorkspaceLocation ) => ({ type: actionTypes.CHANGE_PLAYGROUND_EXTERNAL, - payload: { newExternal } + payload: { newExternal, workspaceLocation } }); export const changeEditorHeight: ActionCreator = ( diff --git a/src/components/sourcecast/Sourcecast.tsx b/src/components/sourcecast/Sourcecast.tsx index f507b595e3..fecffa4ba1 100755 --- a/src/components/sourcecast/Sourcecast.tsx +++ b/src/components/sourcecast/Sourcecast.tsx @@ -4,6 +4,7 @@ import * as classNames from 'classnames'; import * as React from 'react'; import { InterpreterOutput } from '../../reducers/states'; +import { ExternalLibraryName } from '../assessment/assessmentShape'; import Workspace, { WorkspaceProps } from '../workspace'; import { SideContentTab } from '../workspace/side-content'; import EnvVisualizer from '../workspace/side-content/EnvVisualizer'; @@ -25,6 +26,7 @@ export interface IStateProps { editorValue: string; editorHeight?: number; editorWidth: string; + externalLibraryName: string; breakpoints: string[]; highlightedLines: number[][]; isEditorAutorun: boolean; @@ -55,6 +57,7 @@ export interface IDispatchProps { handleEditorValueChange: (val: string) => void; handleEditorWidthChange: (widthChange: number) => void; handleEditorUpdateBreakpoints: (breakpoints: string[]) => void; + handleExternalSelect: (externalLibraryName: ExternalLibraryName) => void; handleFetchSourcecastIndex: () => void; handleInterruptEval: () => void; handleReplEval: () => void; @@ -92,6 +95,9 @@ class Sourcecast extends React.Component { case 'chapterSelect': this.props.handleChapterSelect(inputToApply.data); break; + case 'externalLibrarySelect': + this.props.handleExternalSelect(inputToApply.data); + break; } } @@ -114,8 +120,11 @@ class Sourcecast extends React.Component { const workspaceProps: WorkspaceProps = { controlBarProps: { editorValue: this.props.editorValue, + externalLibraryName: this.props.externalLibraryName, handleChapterSelect: ({ chapter }: { chapter: number }, e: any) => this.props.handleChapterSelect(chapter), + handleExternalSelect: ({ name }: { name: ExternalLibraryName }, e: any) => + this.props.handleExternalSelect(name), handleEditorEval: this.props.handleEditorEval, handleEditorValueChange: this.props.handleEditorValueChange, handleInterruptEval: this.props.handleInterruptEval, @@ -190,7 +199,9 @@ class Sourcecast extends React.Component { audioUrl: this.props.audioUrl, duration: this.props.playbackDuration, playbackData: this.props.playbackData, - playbackStatus: this.props.playbackStatus + playbackStatus: this.props.playbackStatus, + handleChapterSelect: this.props.handleChapterSelect, + handleExternalSelect: this.props.handleExternalSelect }; return (
diff --git a/src/components/sourcecast/SourcecastControlbar.tsx b/src/components/sourcecast/SourcecastControlbar.tsx index f7425afce2..b8ae49b1ac 100755 --- a/src/components/sourcecast/SourcecastControlbar.tsx +++ b/src/components/sourcecast/SourcecastControlbar.tsx @@ -2,6 +2,7 @@ import { Slider } from '@blueprintjs/core'; import { IconNames } from '@blueprintjs/icons'; import * as React from 'react'; +import { ExternalLibraryName } from '../assessment/assessmentShape'; import { controlButton } from '../commons'; import { ICodeDelta, @@ -95,6 +96,8 @@ class SourcecastControlbar extends React.PureComponent< const currentRevision = this.state.currentDeltaRevision; let currentTime = this.audio.current!.currentTime * 1000; this.props.handleEditorValueChange(playbackData.init.editorValue); + this.props.handleExternalSelect(playbackData.init.externalLibrary); + this.props.handleChapterSelect(playbackData.init.chapter); const codeDeltasToApply = playbackData.inputs .filter( deltaWithTime => deltaWithTime.time <= currentTime && deltaWithTime.type === 'codeDelta' @@ -189,6 +192,8 @@ export interface ISourcecastControlbarProps { duration: number; playbackData: IPlaybackData; playbackStatus: PlaybackStatus; + handleChapterSelect: (chapter: number) => void; + handleExternalSelect: (name: ExternalLibraryName) => void; } export interface ISourcecastControlbarState { diff --git a/src/components/sourcecast/Sourcereel.tsx b/src/components/sourcecast/Sourcereel.tsx index c4ef234d82..20d38e1124 100755 --- a/src/components/sourcecast/Sourcereel.tsx +++ b/src/components/sourcecast/Sourcereel.tsx @@ -4,6 +4,7 @@ import * as classNames from 'classnames'; import * as React from 'react'; import { InterpreterOutput } from '../../reducers/states'; +import { ExternalLibraryName } from '../assessment/assessmentShape'; import Workspace, { WorkspaceProps } from '../workspace'; import { SideContentTab } from '../workspace/side-content'; import EnvVisualizer from '../workspace/side-content/EnvVisualizer'; @@ -22,6 +23,7 @@ export interface IStateProps { editorValue: string; editorWidth: string; enableDebugging: boolean; + externalLibraryName: string; highlightedLines: number[][]; isDebugging: boolean; isEditorAutorun: boolean; @@ -48,12 +50,13 @@ export interface IDispatchProps { handleEditorValueChange: (val: string) => void; handleEditorWidthChange: (widthChange: number) => void; handleEditorUpdateBreakpoints: (breakpoints: string[]) => void; + handleExternalSelect: (externalLibraryName: ExternalLibraryName) => void; handleInterruptEval: () => void; handleRecordInput: (input: Input) => void; handleReplEval: () => void; handleReplOutputClear: () => void; handleReplValueChange: (newValue: string) => void; - handleRecordEditorInitValue: (editorValue: string) => void; + handleRecordInit: (initData: IPlaybackData['init']) => void; handleSaveSourcecastData: ( title: string, description: string, @@ -93,6 +96,7 @@ class Sourcereel extends React.Component { const workspaceProps: WorkspaceProps = { controlBarProps: { editorValue: this.props.editorValue, + externalLibraryName: this.props.externalLibraryName, handleChapterSelect: ({ chapter }: { chapter: number }, e: any) => { this.props.handleChapterSelect(chapter); if (this.props.recordingStatus !== RecordingStatus.recording) { @@ -104,6 +108,18 @@ class Sourcereel extends React.Component { data: chapter }); }, + handleExternalSelect: ({ name }: { name: ExternalLibraryName }, e: any) => { + this.props.handleExternalSelect(name); + if (this.props.recordingStatus !== RecordingStatus.recording) { + return; + } + this.props.handleRecordInput({ + time: this.getTimerDuration(), + type: 'externalLibrarySelect', + data: name + }); + }, + handleEditorEval: () => { this.props.handleEditorEval(); if (this.props.recordingStatus !== RecordingStatus.recording) { @@ -164,7 +180,7 @@ class Sourcereel extends React.Component { editorValue={this.props.editorValue} getTimerDuration={this.getTimerDuration} playbackData={this.props.playbackData} - handleRecordEditorInitValue={this.props.handleRecordEditorInitValue} + handleRecordInit={this.handleRecordInit} handleSaveSourcecastData={this.props.handleSaveSourcecastData} handleSetEditorReadonly={this.props.handleSetEditorReadonly} handleTimerPause={this.props.handleTimerPause} @@ -192,6 +208,13 @@ class Sourcereel extends React.Component { public getTimerDuration = () => this.props.timeElapsedBeforePause + Date.now() - this.props.timeResumed; + + private handleRecordInit = () => + this.props.handleRecordInit({ + chapter: this.props.sourceChapter, + externalLibrary: this.props.externalLibraryName as ExternalLibraryName, + editorValue: this.props.editorValue + }); } const INTRODUCTION = 'Welcome to Sourcereel!'; diff --git a/src/components/sourcecast/SourcereelControlbar.tsx b/src/components/sourcecast/SourcereelControlbar.tsx index 06c143e22c..9a0058fa37 100755 --- a/src/components/sourcecast/SourcereelControlbar.tsx +++ b/src/components/sourcecast/SourcereelControlbar.tsx @@ -124,8 +124,8 @@ class SourcereelControlbar extends React.PureComponent< }; private handleRecorderStarting = () => { - const { handleRecordEditorInitValue, handleSetEditorReadonly, handleTimerStart } = this.props; - handleRecordEditorInitValue(this.props.editorValue); + const { handleRecordInit, handleSetEditorReadonly, handleTimerStart } = this.props; + handleRecordInit(); handleSetEditorReadonly(false); handleTimerStart(); const updater = setInterval(this.updateTimerDuration, 100); @@ -214,7 +214,7 @@ class SourcereelControlbar extends React.PureComponent< } export interface ISourcereelControlbarProps { - handleRecordEditorInitValue: (editorValue: string) => void; + handleRecordInit: () => void; handleSaveSourcecastData: ( title: string, description: string, diff --git a/src/components/sourcecast/sourcecastShape.ts b/src/components/sourcecast/sourcecastShape.ts index 65b3547f38..999109a568 100755 --- a/src/components/sourcecast/sourcecastShape.ts +++ b/src/components/sourcecast/sourcecastShape.ts @@ -1,7 +1,10 @@ +import { ExternalLibraryName } from '../assessment/assessmentShape'; + export interface IInputTypeShape { chapterSelect: number; cursorPositionChange: IPosition; codeDelta: ICodeDelta; + externalLibrarySelect: ExternalLibraryName; keyboardCommand: KeyboardCommand; selectionRangeData: ISelectionData; } @@ -46,6 +49,8 @@ export type Input = keyof IInputTypeShape extends infer K export interface IPlaybackData { init: { + chapter: number; + externalLibrary: ExternalLibraryName; editorValue: string; }; inputs: Input[]; diff --git a/src/containers/sourcecast/SourcecastContainer.ts b/src/containers/sourcecast/SourcecastContainer.ts index 00b885c24e..31cbe55c17 100755 --- a/src/containers/sourcecast/SourcecastContainer.ts +++ b/src/containers/sourcecast/SourcecastContainer.ts @@ -16,6 +16,7 @@ import { evalEditor, evalRepl, fetchSourcecastIndex, + playgroundExternalSelect, setCodeDeltasToApply, setEditorBreakpoint, setEditorReadonly, @@ -29,6 +30,7 @@ import { updateReplValue, WorkspaceLocation } from '../../actions'; +import { ExternalLibraryName } from '../../components/assessment/assessmentShape'; import Sourcecast, { IDispatchProps, IStateProps } from '../../components/sourcecast/Sourcecast'; import { ICodeDelta, @@ -46,6 +48,7 @@ const mapStateToProps: MapStateToProps = state => ({ editorReadonly: state.workspaces.sourcecast.editorReadonly, editorWidth: state.workspaces.sourcecast.editorWidth, editorValue: state.workspaces.sourcecast.editorValue!, + externalLibraryName: state.workspaces.sourcecast.playgroundExternal, isEditorAutorun: state.workspaces.sourcecast.isEditorAutorun, inputToApply: state.workspaces.sourcecast.inputToApply, breakpoints: state.workspaces.sourcecast.breakpoints, @@ -61,7 +64,7 @@ const mapStateToProps: MapStateToProps = state => ({ sideContentHeight: state.workspaces.sourcecast.sideContentHeight, sourcecastIndex: state.workspaces.sourcecast.sourcecastIndex, sourceChapter: state.workspaces.sourcecast.context.chapter, - websocketStatus: state.workspaces.playground.websocketStatus + websocketStatus: state.workspaces.sourcecast.websocketStatus }); const location: WorkspaceLocation = 'sourcecast'; @@ -78,6 +81,8 @@ const mapDispatchToProps: MapDispatchToProps = (dispatch: Di handleEditorWidthChange: (widthChange: number) => changeEditorWidth(widthChange, location), handleEditorUpdateBreakpoints: (breakpoints: string[]) => setEditorBreakpoint(breakpoints, location), + handleExternalSelect: (externalLibraryName: ExternalLibraryName) => + playgroundExternalSelect(externalLibraryName, location), handleFetchSourcecastIndex: () => fetchSourcecastIndex(location), handleInterruptEval: () => beginInterruptExecution(location), handleReplEval: () => evalRepl(location), diff --git a/src/containers/sourcecast/SourcereelContainer.ts b/src/containers/sourcecast/SourcereelContainer.ts index df530852fd..0fe8096067 100755 --- a/src/containers/sourcecast/SourcereelContainer.ts +++ b/src/containers/sourcecast/SourcereelContainer.ts @@ -15,7 +15,8 @@ import { debuggerResume, evalEditor, evalRepl, - recordEditorInitValue, + playgroundExternalSelect, + recordInit, recordInput, saveSourcecastData, setEditorBreakpoint, @@ -30,6 +31,7 @@ import { updateReplValue, WorkspaceLocation } from '../../actions'; +import { ExternalLibraryName } from '../../components/assessment/assessmentShape'; import { Input, IPlaybackData } from '../../components/sourcecast/sourcecastShape'; import Sourcereel, { IDispatchProps, IStateProps } from '../../components/sourcecast/Sourcereel'; import { IState } from '../../reducers/states'; @@ -40,6 +42,7 @@ const mapStateToProps: MapStateToProps = state => ({ editorValue: state.workspaces.sourcereel.editorValue!, editorWidth: state.workspaces.sourcereel.editorWidth, enableDebugging: state.workspaces.sourcereel.enableDebugging, + externalLibraryName: state.workspaces.sourcereel.playgroundExternal, highlightedLines: state.workspaces.sourcereel.highlightedLines, isDebugging: state.workspaces.sourcereel.isDebugging, isEditorAutorun: state.workspaces.sourcereel.isEditorAutorun, @@ -68,6 +71,8 @@ const mapDispatchToProps: MapDispatchToProps = (dispatch: Di handleEditorWidthChange: (widthChange: number) => changeEditorWidth(widthChange, location), handleEditorUpdateBreakpoints: (breakpoints: string[]) => setEditorBreakpoint(breakpoints, location), + handleExternalSelect: (externalLibraryName: ExternalLibraryName) => + playgroundExternalSelect(externalLibraryName, location), handleInterruptEval: () => beginInterruptExecution(location), handleRecordInput: (input: Input) => recordInput(input, location), handleReplEval: () => evalRepl(location), @@ -80,8 +85,7 @@ const mapDispatchToProps: MapDispatchToProps = (dispatch: Di playbackData: IPlaybackData ) => saveSourcecastData(title, description, audio, playbackData, 'sourcecast'), handleSetEditorReadonly: (readonly: boolean) => setEditorReadonly(location, readonly), - handleRecordEditorInitValue: (editorValue: string) => - recordEditorInitValue(editorValue, location), + handleRecordInit: (initData: IPlaybackData['init']) => recordInit(initData, location), handleSideContentHeightChange: (heightChange: number) => changeSideContentHeight(heightChange, location), handleTimerPause: () => timerPause(location), diff --git a/src/reducers/__tests__/sourcecast.ts b/src/reducers/__tests__/sourcecast.ts index cdb85f2941..5d7a4b0197 100644 --- a/src/reducers/__tests__/sourcecast.ts +++ b/src/reducers/__tests__/sourcecast.ts @@ -8,6 +8,7 @@ import { SET_SOURCECAST_PLAYBACK_STATUS, UPDATE_SOURCECAST_INDEX } from '../../actions/actionTypes'; +import { ExternalLibraryNames } from '../../components/assessment/assessmentShape'; import { ICodeDelta, Input, @@ -46,6 +47,8 @@ describe('SAVE_SOURCECAST_DATA', () => { }; const playbackData: IPlaybackData = { init: { + chapter: 1, + externalLibrary: ExternalLibraryNames.NONE, editorValue: '' }, inputs: [input] @@ -155,6 +158,8 @@ describe('SET_SOURCECAST_DATA', () => { }; const playbackData: IPlaybackData = { init: { + chapter: 1, + externalLibrary: ExternalLibraryNames.NONE, editorValue: '' }, inputs: [input] diff --git a/src/reducers/__tests__/sourcereel.ts b/src/reducers/__tests__/sourcereel.ts index 2dc1a708e1..92f8b8e8d5 100644 --- a/src/reducers/__tests__/sourcereel.ts +++ b/src/reducers/__tests__/sourcereel.ts @@ -1,6 +1,6 @@ import { IAction, - RECORD_EDITOR_INIT_VALUE, + RECORD_INIT, RECORD_INPUT, TIMER_PAUSE, TIMER_RESET, @@ -8,7 +8,13 @@ import { TIMER_START, TIMER_STOP } from '../../actions/actionTypes'; -import { ICodeDelta, Input, RecordingStatus } from '../../components/sourcecast/sourcecastShape'; +import { ExternalLibraryNames } from '../../components/assessment/assessmentShape'; +import { + ICodeDelta, + Input, + IPlaybackData, + RecordingStatus +} from '../../components/sourcecast/sourcecastShape'; import { reducer } from '../sourcereel'; import { defaultWorkspaceManager } from '../states'; @@ -19,19 +25,20 @@ function generateAction(type: string, payload: any = {}): IAction { }; } -describe('RECORD_EDITOR_INIT_VALUE', () => { +describe('RECORD_INIT', () => { test('records editorInitValue correctly', () => { - const editorValue = 'test init value'; - const action: IAction = generateAction(RECORD_EDITOR_INIT_VALUE, { editorValue }); + const initData: IPlaybackData['init'] = { + editorValue: 'test init value', + chapter: 1, + externalLibrary: ExternalLibraryNames.NONE + }; + const action: IAction = generateAction(RECORD_INIT, { initData }); const result = reducer(defaultWorkspaceManager.sourcereel, action); expect(result).toEqual({ ...defaultWorkspaceManager.sourcereel, playbackData: { ...defaultWorkspaceManager.sourcereel.playbackData, - init: { - ...defaultWorkspaceManager.sourcereel.playbackData.init, - editorValue - } + init: initData } }); }); diff --git a/src/reducers/sourcereel.ts b/src/reducers/sourcereel.ts index 74f8fadf75..a210c8dd48 100644 --- a/src/reducers/sourcereel.ts +++ b/src/reducers/sourcereel.ts @@ -3,7 +3,7 @@ import { ISourcereelWorkspace } from './states'; import { IAction, - RECORD_EDITOR_INIT_VALUE, + RECORD_INIT, RECORD_INPUT, TIMER_PAUSE, TIMER_RESET, @@ -18,13 +18,11 @@ export const reducer: Reducer = ( action: IAction ) => { switch (action.type) { - case RECORD_EDITOR_INIT_VALUE: + case RECORD_INIT: return { ...state, playbackData: { - init: { - editorValue: action.payload.editorValue - }, + init: action.payload.initData, inputs: [] } }; diff --git a/src/reducers/states.ts b/src/reducers/states.ts index 7b57dd3922..645a9bdffe 100755 --- a/src/reducers/states.ts +++ b/src/reducers/states.ts @@ -57,9 +57,8 @@ interface IGradingWorkspace extends IWorkspaceState { readonly hasUnsavedChanges: boolean; } -export interface IPlaygroundWorkspace extends IWorkspaceState { - readonly playgroundExternal: ExternalLibraryName; -} +// tslint:disable-next-line: no-empty-interface +export interface IPlaygroundWorkspace extends IWorkspaceState {} export interface ISourcecastWorkspace extends IWorkspaceState { readonly audioUrl: string; @@ -107,6 +106,7 @@ export interface IWorkspaceState { readonly enableDebugging: boolean; readonly isEditorAutorun: boolean; readonly output: InterpreterOutput[]; + readonly playgroundExternal: ExternalLibraryName; readonly replHistory: ReplHistory; readonly replValue: string; readonly sharedbAceInitValue: string; @@ -258,6 +258,7 @@ export const createDefaultWorkspace = (workspaceLocation: WorkspaceLocation): IW editorTestcases: [], editorHeight: 150, editorWidth: '50%', + playgroundExternal: ExternalLibraryNames.NONE, execTime: 1000, highlightedLines: [], output: [], @@ -293,8 +294,7 @@ export const defaultWorkspaceManager: IWorkspaceManagerState = { hasUnsavedChanges: false }, playground: { - ...createDefaultWorkspace(WorkspaceLocations.playground), - playgroundExternal: ExternalLibraryNames.NONE + ...createDefaultWorkspace(WorkspaceLocations.playground) }, sourcecast: { ...createDefaultWorkspace(WorkspaceLocations.sourcecast), @@ -303,7 +303,7 @@ export const defaultWorkspaceManager: IWorkspaceManagerState = { description: null, inputToApply: null, playbackData: { - init: { editorValue: '' }, + init: { editorValue: '', chapter: 1, externalLibrary: ExternalLibraryNames.NONE }, inputs: [] }, playbackDuration: 0, @@ -314,7 +314,7 @@ export const defaultWorkspaceManager: IWorkspaceManagerState = { sourcereel: { ...createDefaultWorkspace(WorkspaceLocations.sourcereel), playbackData: { - init: { editorValue: '' }, + init: { editorValue: '', chapter: 1, externalLibrary: ExternalLibraryNames.NONE }, inputs: [] }, recordingStatus: RecordingStatus.notStarted, diff --git a/src/reducers/workspaces.ts b/src/reducers/workspaces.ts index ea523eeecc..1c5e156ed3 100755 --- a/src/reducers/workspaces.ts +++ b/src/reducers/workspaces.ts @@ -275,8 +275,8 @@ export const reducer: Reducer = ( case CHANGE_PLAYGROUND_EXTERNAL: return { ...state, - playground: { - ...state.playground, + [workspaceLocation]: { + ...state[workspaceLocation], playgroundExternal: action.payload.newExternal } }; diff --git a/src/sagas/__tests__/workspaces.ts b/src/sagas/__tests__/workspaces.ts index ba4b3f9a90..ec2c67e0da 100644 --- a/src/sagas/__tests__/workspaces.ts +++ b/src/sagas/__tests__/workspaces.ts @@ -411,7 +411,7 @@ describe('PLAYGROUND_EXTERNAL_SELECT', () => { return expectSaga(workspaceSaga) .withState(newDefaultState) - .put(actions.changePlaygroundExternal(newExternalLibraryName)) + .put(actions.changePlaygroundExternal(newExternalLibraryName, workspaceLocation)) .put(actions.beginClearContext(library, workspaceLocation)) .put(actions.clearReplOutput(workspaceLocation)) .call(showSuccessMessage, `Switched to ${newExternalLibraryName} library`, 1000) diff --git a/src/sagas/workspaces.ts b/src/sagas/workspaces.ts index 49c45d58df..7e282d4b40 100644 --- a/src/sagas/workspaces.ts +++ b/src/sagas/workspaces.ts @@ -231,7 +231,7 @@ export default function* workspaceSaga(): SagaIterator { ); const newExternalLibraryName = (action as actionTypes.IAction).payload.externalLibraryName; const oldExternalLibraryName = yield select( - (state: IState) => state.workspaces.playground.playgroundExternal + (state: IState) => state.workspaces[workspaceLocation].playgroundExternal ); const symbols = externalLibraries.get(newExternalLibraryName)!; const library = { @@ -243,7 +243,7 @@ export default function* workspaceSaga(): SagaIterator { globals }; if (newExternalLibraryName !== oldExternalLibraryName) { - yield put(actions.changePlaygroundExternal(newExternalLibraryName)); + yield put(actions.changePlaygroundExternal(newExternalLibraryName, workspaceLocation)); yield put(actions.beginClearContext(library, workspaceLocation)); yield put(actions.clearReplOutput(workspaceLocation)); yield call(showSuccessMessage, `Switched to ${newExternalLibraryName} library`, 1000); From e3fce8b879438315e423581a103cd7d063450007 Mon Sep 17 00:00:00 2001 From: Chee Yuan Date: Fri, 2 Aug 2019 01:10:16 +0800 Subject: [PATCH 2/4] Fix variable names --- src/actions/__tests__/workspaces.ts | 17 +++++++++-------- src/actions/actionTypes.ts | 2 +- src/actions/workspaces.ts | 6 +++--- src/components/Application.tsx | 8 ++++---- src/components/__tests__/Application.tsx | 4 ++-- src/components/sourcecast/Sourcecast.tsx | 5 +---- src/containers/ApplicationContainer.ts | 8 ++++---- src/containers/PlaygroundContainer.ts | 6 +++--- .../sourcecast/SourcecastContainer.ts | 12 ++++-------- .../sourcecast/SourcereelContainer.ts | 6 +++--- src/reducers/__tests__/workspaces.ts | 12 ++++++------ src/reducers/states.ts | 4 ++-- src/reducers/workspaces.ts | 6 +++--- src/sagas/__tests__/playground.ts | 6 +++--- src/sagas/__tests__/workspaces.ts | 10 +++++----- src/sagas/playground.ts | 2 +- src/sagas/workspaces.ts | 4 ++-- 17 files changed, 56 insertions(+), 62 deletions(-) diff --git a/src/actions/__tests__/workspaces.ts b/src/actions/__tests__/workspaces.ts index 6635b4da05..008d3d939f 100755 --- a/src/actions/__tests__/workspaces.ts +++ b/src/actions/__tests__/workspaces.ts @@ -8,7 +8,7 @@ import { browseReplHistoryUp, changeEditorHeight, changeEditorWidth, - changePlaygroundExternal, + changeExternalLibrary, changeSideContentHeight, chapterSelect, clearReplInput, @@ -18,8 +18,8 @@ import { evalEditor, evalRepl, evalTestcase, + externalLibrarySelect, highlightEditorLine, - playgroundExternalSelect, resetWorkspace, sendReplInputToOutput, setEditorBreakpoint, @@ -51,13 +51,14 @@ test('browseReplHistoryUp generates correct action object', () => { }); }); -test('changePlaygroundExternal generates correct action object', () => { +test('changeExternalLibrary generates correct action object', () => { const newExternal = 'new-external-test'; - const action = changePlaygroundExternal(newExternal); + const action = changeExternalLibrary(newExternal, playgroundWorkspace); expect(action).toEqual({ - type: actionTypes.CHANGE_PLAYGROUND_EXTERNAL, + type: actionTypes.CHANGE_EXTERNAL_LIBRARY, payload: { - newExternal + newExternal, + workspaceLocation: playgroundWorkspace } }); }); @@ -110,9 +111,9 @@ test('chapterSelect generates correct action object', () => { }); }); -test('playgroundExternalSelect generates correct action object', () => { +test('externalLibrarySelect generates correct action object', () => { const externalLibraryName = 'SOUNDS'; - const action = playgroundExternalSelect(externalLibraryName, assessmentWorkspace); + const action = externalLibrarySelect(externalLibraryName, assessmentWorkspace); expect(action).toEqual({ type: actionTypes.PLAYGROUND_EXTERNAL_SELECT, payload: { diff --git a/src/actions/actionTypes.ts b/src/actions/actionTypes.ts index e105c3ad2d..4119f22d88 100755 --- a/src/actions/actionTypes.ts +++ b/src/actions/actionTypes.ts @@ -35,7 +35,7 @@ export const BROWSE_REPL_HISTORY_UP = 'BROWSE_REPL_HISTORY_UP'; export const CHANGE_EDITOR_HEIGHT = 'CHANGE_EDITOR_HEIGHT'; export const CHANGE_EDITOR_WIDTH = 'CHANGE_EDITOR_WIDTH'; export const CHANGE_EXEC_TIME = 'CHANGE_EXEC_TIME'; -export const CHANGE_PLAYGROUND_EXTERNAL = 'CHANGE_PLAYGROUND_EXTERNAL'; +export const CHANGE_EXTERNAL_LIBRARY = 'CHANGE_EXTERNAL_LIBRARY'; export const CHANGE_SIDE_CONTENT_HEIGHT = 'CHANGE_SIDE_CONTENT_HEIGHT'; export const CHAPTER_SELECT = 'CHAPTER_SELECT'; export const CLEAR_REPL_INPUT = 'CLEAR_REPL_INPUT'; diff --git a/src/actions/workspaces.ts b/src/actions/workspaces.ts index 25512d8f79..614318228f 100755 --- a/src/actions/workspaces.ts +++ b/src/actions/workspaces.ts @@ -38,11 +38,11 @@ export const browseReplHistoryUp: ActionCreator = ( payload: { workspaceLocation } }); -export const changePlaygroundExternal: ActionCreator = ( +export const changeExternalLibrary: ActionCreator = ( newExternal: string, workspaceLocation: WorkspaceLocation ) => ({ - type: actionTypes.CHANGE_PLAYGROUND_EXTERNAL, + type: actionTypes.CHANGE_EXTERNAL_LIBRARY, payload: { newExternal, workspaceLocation } }); @@ -89,7 +89,7 @@ export const chapterSelect: ActionCreator = ( } }); -export const playgroundExternalSelect: ActionCreator = ( +export const externalLibrarySelect: ActionCreator = ( externalLibraryName: ExternalLibraryName, workspaceLocation: WorkspaceLocation ) => ({ diff --git a/src/components/Application.tsx b/src/components/Application.tsx index d7c1a4fe5c..974ec75947 100644 --- a/src/components/Application.tsx +++ b/src/components/Application.tsx @@ -22,7 +22,7 @@ export interface IStateProps { role?: Role; title: string; name?: string; - currentPlaygroundExternalLibrary: ExternalLibraryName; + currentExternalLibraryLibrary: ExternalLibraryName; } export interface IDispatchProps { @@ -31,7 +31,7 @@ export interface IDispatchProps { handleEditorUpdateBreakpoints: (breakpoints: string[]) => void; handleEnsureLibrariesLoaded: () => void; handleLogOut: () => void; - handlePlaygroundExternalSelect: (external: ExternalLibraryName) => void; + handleExternalLibrarySelect: (external: ExternalLibraryName) => void; } const assessmentRegExp = ':assessmentId(-?\\d+)?/:questionId(\\d+)?'; @@ -86,12 +86,12 @@ const toLogin = (props: IApplicationProps) => () => ( const parsePlayground = (props: IApplicationProps) => { const prgrm = parsePrgrm(props); const chapter = parseChapter(props) || props.currentPlaygroundChapter; - const externalLibraryName = parseExternalLibrary(props) || props.currentPlaygroundExternalLibrary; + const externalLibraryName = parseExternalLibrary(props) || props.currentExternalLibraryLibrary; if (prgrm) { props.handleEditorValueChange(prgrm); props.handleEnsureLibrariesLoaded(); props.handleClearContext(chapter, externalLibraryName); - props.handlePlaygroundExternalSelect(externalLibraryName); + props.handleExternalLibrarySelect(externalLibraryName); } }; diff --git a/src/components/__tests__/Application.tsx b/src/components/__tests__/Application.tsx index 0d8ffec207..dc678a1dc9 100644 --- a/src/components/__tests__/Application.tsx +++ b/src/components/__tests__/Application.tsx @@ -11,12 +11,12 @@ test('Application renders correctly', () => { title: 'Cadet', currentPlaygroundChapter: 2, handleLogOut: () => {}, - currentPlaygroundExternalLibrary: ExternalLibraryNames.NONE, + currentExternalLibraryLibrary: ExternalLibraryNames.NONE, handleClearContext: (chapter: number, externalLibraryName: ExternalLibraryName) => {}, handleEditorValueChange: (val: string) => {}, handleEditorUpdateBreakpoints: (breakpoints: string[]) => {}, handleEnsureLibrariesLoaded: () => {}, - handlePlaygroundExternalSelect: (externalLibraryName: ExternalLibraryName) => {} + handleExternalLibrarySelect: (externalLibraryName: ExternalLibraryName) => {} }; const app = ; const tree = shallow(app); diff --git a/src/components/sourcecast/Sourcecast.tsx b/src/components/sourcecast/Sourcecast.tsx index fecffa4ba1..5f2d4afed6 100755 --- a/src/components/sourcecast/Sourcecast.tsx +++ b/src/components/sourcecast/Sourcecast.tsx @@ -42,7 +42,6 @@ export interface IStateProps { sideContentHeight?: number; sourcecastIndex: any; sourceChapter: number; - websocketStatus: number; } export interface IDispatchProps { @@ -74,7 +73,6 @@ export interface IDispatchProps { ) => void; handleSetSourcecastDuration: (duration: number) => void; handleSetSourcecastStatus: (PlaybackStatus: PlaybackStatus) => void; - handleSetWebsocketStatus: (websocketStatus: number) => void; handleSideContentHeightChange: (heightChange: number) => void; handleToggleEditorAutorun: () => void; } @@ -114,8 +112,7 @@ class Sourcecast extends React.Component { isPlaying: this.props.playbackStatus === PlaybackStatus.playing, breakpoints: this.props.breakpoints, highlightedLines: this.props.highlightedLines, - handleEditorUpdateBreakpoints: this.props.handleEditorUpdateBreakpoints, - handleSetWebsocketStatus: this.props.handleSetWebsocketStatus + handleEditorUpdateBreakpoints: this.props.handleEditorUpdateBreakpoints }; const workspaceProps: WorkspaceProps = { controlBarProps: { diff --git a/src/containers/ApplicationContainer.ts b/src/containers/ApplicationContainer.ts index 6beb1e70c1..72706e1d14 100644 --- a/src/containers/ApplicationContainer.ts +++ b/src/containers/ApplicationContainer.ts @@ -4,7 +4,7 @@ import { bindActionCreators, Dispatch } from 'redux'; import { beginClearContext, logOut, setEditorBreakpoint, updateEditorValue } from '../actions'; import { ensureLibrariesLoaded, - playgroundExternalSelect, + externalLibrarySelect, WorkspaceLocations } from '../actions/workspaces'; import Application, { IDispatchProps, IStateProps } from '../components/Application'; @@ -25,7 +25,7 @@ const mapStateToProps: MapStateToProps = state => ({ role: state.session.role, name: state.session.name, currentPlaygroundChapter: state.workspaces.playground.context.chapter, - currentPlaygroundExternalLibrary: state.workspaces.playground.playgroundExternal + currentExternalLibraryLibrary: state.workspaces.playground.externalLibrary }); const workspaceLocation = WorkspaceLocations.playground; @@ -50,8 +50,8 @@ const mapDispatchToProps: MapDispatchToProps = (dispatch: Di setEditorBreakpoint(breakpoints, workspaceLocation), handleEnsureLibrariesLoaded: ensureLibrariesLoaded, handleLogOut: logOut, - handlePlaygroundExternalSelect: (externalLibraryName: ExternalLibraryName) => - playgroundExternalSelect(externalLibraryName, workspaceLocation) + handleExternalLibrarySelect: (externalLibraryName: ExternalLibraryName) => + externalLibrarySelect(externalLibraryName, workspaceLocation) }, dispatch ); diff --git a/src/containers/PlaygroundContainer.ts b/src/containers/PlaygroundContainer.ts index df7dff74ae..e7d974948d 100755 --- a/src/containers/PlaygroundContainer.ts +++ b/src/containers/PlaygroundContainer.ts @@ -17,11 +17,11 @@ import { debuggerResume, evalEditor, evalRepl, + externalLibrarySelect, finishInvite, generateLzString, initInvite, invalidEditorSessionId, - playgroundExternalSelect, setEditorBreakpoint, setEditorSessionId, setWebsocketStatus, @@ -54,7 +54,7 @@ const mapStateToProps: MapStateToProps = state => ({ sideContentHeight: state.workspaces.playground.sideContentHeight, sourceChapter: state.workspaces.playground.context.chapter, websocketStatus: state.workspaces.playground.websocketStatus, - externalLibraryName: state.workspaces.playground.playgroundExternal + externalLibraryName: state.workspaces.playground.externalLibrary }); const workspaceLocation: WorkspaceLocation = WorkspaceLocations.playground; @@ -78,7 +78,7 @@ const mapDispatchToProps: MapDispatchToProps = (dispatch: Di handleInterruptEval: () => beginInterruptExecution(workspaceLocation), handleInvalidEditorSessionId: () => invalidEditorSessionId(), handleExternalSelect: (externalLibraryName: ExternalLibraryName) => - playgroundExternalSelect(externalLibraryName, workspaceLocation), + externalLibrarySelect(externalLibraryName, workspaceLocation), handleInitInvite: (editorValue: string) => initInvite(editorValue, workspaceLocation), handleReplEval: () => evalRepl(workspaceLocation), handleReplOutputClear: () => clearReplOutput(workspaceLocation), diff --git a/src/containers/sourcecast/SourcecastContainer.ts b/src/containers/sourcecast/SourcecastContainer.ts index 31cbe55c17..e26e5392db 100755 --- a/src/containers/sourcecast/SourcecastContainer.ts +++ b/src/containers/sourcecast/SourcecastContainer.ts @@ -15,8 +15,8 @@ import { debuggerResume, evalEditor, evalRepl, + externalLibrarySelect, fetchSourcecastIndex, - playgroundExternalSelect, setCodeDeltasToApply, setEditorBreakpoint, setEditorReadonly, @@ -24,7 +24,6 @@ import { setSourcecastData, setSourcecastDuration, setSourcecastStatus, - setWebsocketStatus, toggleEditorAutorun, updateEditorValue, updateReplValue, @@ -48,7 +47,7 @@ const mapStateToProps: MapStateToProps = state => ({ editorReadonly: state.workspaces.sourcecast.editorReadonly, editorWidth: state.workspaces.sourcecast.editorWidth, editorValue: state.workspaces.sourcecast.editorValue!, - externalLibraryName: state.workspaces.sourcecast.playgroundExternal, + externalLibraryName: state.workspaces.sourcecast.externalLibrary, isEditorAutorun: state.workspaces.sourcecast.isEditorAutorun, inputToApply: state.workspaces.sourcecast.inputToApply, breakpoints: state.workspaces.sourcecast.breakpoints, @@ -63,8 +62,7 @@ const mapStateToProps: MapStateToProps = state => ({ replValue: state.workspaces.sourcecast.replValue, sideContentHeight: state.workspaces.sourcecast.sideContentHeight, sourcecastIndex: state.workspaces.sourcecast.sourcecastIndex, - sourceChapter: state.workspaces.sourcecast.context.chapter, - websocketStatus: state.workspaces.sourcecast.websocketStatus + sourceChapter: state.workspaces.sourcecast.context.chapter }); const location: WorkspaceLocation = 'sourcecast'; @@ -82,7 +80,7 @@ const mapDispatchToProps: MapDispatchToProps = (dispatch: Di handleEditorUpdateBreakpoints: (breakpoints: string[]) => setEditorBreakpoint(breakpoints, location), handleExternalSelect: (externalLibraryName: ExternalLibraryName) => - playgroundExternalSelect(externalLibraryName, location), + externalLibrarySelect(externalLibraryName, location), handleFetchSourcecastIndex: () => fetchSourcecastIndex(location), handleInterruptEval: () => beginInterruptExecution(location), handleReplEval: () => evalRepl(location), @@ -101,8 +99,6 @@ const mapDispatchToProps: MapDispatchToProps = (dispatch: Di handleSetSourcecastDuration: (duration: number) => setSourcecastDuration(duration, location), handleSetSourcecastStatus: (playbackStatus: PlaybackStatus) => setSourcecastStatus(playbackStatus, location), - handleSetWebsocketStatus: (websocketStatus: number) => - setWebsocketStatus(location, websocketStatus), handleSideContentHeightChange: (heightChange: number) => changeSideContentHeight(heightChange, location), handleToggleEditorAutorun: () => toggleEditorAutorun(location), diff --git a/src/containers/sourcecast/SourcereelContainer.ts b/src/containers/sourcecast/SourcereelContainer.ts index 0fe8096067..fc13812e4e 100755 --- a/src/containers/sourcecast/SourcereelContainer.ts +++ b/src/containers/sourcecast/SourcereelContainer.ts @@ -15,7 +15,7 @@ import { debuggerResume, evalEditor, evalRepl, - playgroundExternalSelect, + externalLibrarySelect, recordInit, recordInput, saveSourcecastData, @@ -42,7 +42,7 @@ const mapStateToProps: MapStateToProps = state => ({ editorValue: state.workspaces.sourcereel.editorValue!, editorWidth: state.workspaces.sourcereel.editorWidth, enableDebugging: state.workspaces.sourcereel.enableDebugging, - externalLibraryName: state.workspaces.sourcereel.playgroundExternal, + externalLibraryName: state.workspaces.sourcereel.externalLibrary, highlightedLines: state.workspaces.sourcereel.highlightedLines, isDebugging: state.workspaces.sourcereel.isDebugging, isEditorAutorun: state.workspaces.sourcereel.isEditorAutorun, @@ -72,7 +72,7 @@ const mapDispatchToProps: MapDispatchToProps = (dispatch: Di handleEditorUpdateBreakpoints: (breakpoints: string[]) => setEditorBreakpoint(breakpoints, location), handleExternalSelect: (externalLibraryName: ExternalLibraryName) => - playgroundExternalSelect(externalLibraryName, location), + externalLibrarySelect(externalLibraryName, location), handleInterruptEval: () => beginInterruptExecution(location), handleRecordInput: (input: Input) => recordInput(input, location), handleReplEval: () => evalRepl(location), diff --git a/src/reducers/__tests__/workspaces.ts b/src/reducers/__tests__/workspaces.ts index 9ed3807246..88cc491319 100644 --- a/src/reducers/__tests__/workspaces.ts +++ b/src/reducers/__tests__/workspaces.ts @@ -3,7 +3,7 @@ import { BROWSE_REPL_HISTORY_UP, CHANGE_EDITOR_HEIGHT, CHANGE_EDITOR_WIDTH, - CHANGE_PLAYGROUND_EXTERNAL, + CHANGE_EXTERNAL_LIBRARY, CHANGE_SIDE_CONTENT_HEIGHT, CLEAR_REPL_INPUT, CLEAR_REPL_OUTPUT, @@ -289,11 +289,11 @@ describe('CHANGE_EDITOR_WIDTH', () => { }); }); -describe('CHANGE_PLAYGROUND_EXTERNAL', () => { - test('sets playgroundExternal correctly', () => { +describe('CHANGE_EXTERNAL_LIBRARY', () => { + test('sets externalLibrary correctly', () => { const newExternal = 'new_external_test'; const playgroundAction: IAction = { - type: CHANGE_PLAYGROUND_EXTERNAL, + type: CHANGE_EXTERNAL_LIBRARY, payload: { newExternal, workspaceLocation: playgroundWorkspace @@ -305,7 +305,7 @@ describe('CHANGE_PLAYGROUND_EXTERNAL', () => { ...defaultWorkspaceManager, playground: { ...defaultWorkspaceManager.playground, - playgroundExternal: newExternal + externalLibrary: newExternal } }); }); @@ -1017,7 +1017,7 @@ describe('LOG_OUT', () => { editorHeight: 200, editorValue: 'test program here', highlightedLines: [[1, 2], [3, 4]], - playgroundExternal: 'NONE', + externalLibrary: 'NONE', replValue: 'test repl value here', websocketStatus: 0 }; diff --git a/src/reducers/states.ts b/src/reducers/states.ts index 645a9bdffe..b7604e60cd 100755 --- a/src/reducers/states.ts +++ b/src/reducers/states.ts @@ -106,7 +106,7 @@ export interface IWorkspaceState { readonly enableDebugging: boolean; readonly isEditorAutorun: boolean; readonly output: InterpreterOutput[]; - readonly playgroundExternal: ExternalLibraryName; + readonly externalLibrary: ExternalLibraryName; readonly replHistory: ReplHistory; readonly replValue: string; readonly sharedbAceInitValue: string; @@ -258,7 +258,7 @@ export const createDefaultWorkspace = (workspaceLocation: WorkspaceLocation): IW editorTestcases: [], editorHeight: 150, editorWidth: '50%', - playgroundExternal: ExternalLibraryNames.NONE, + externalLibrary: ExternalLibraryNames.NONE, execTime: 1000, highlightedLines: [], output: [], diff --git a/src/reducers/workspaces.ts b/src/reducers/workspaces.ts index 1c5e156ed3..61cef04ccd 100755 --- a/src/reducers/workspaces.ts +++ b/src/reducers/workspaces.ts @@ -7,7 +7,7 @@ import { CHANGE_EDITOR_HEIGHT, CHANGE_EDITOR_WIDTH, CHANGE_EXEC_TIME, - CHANGE_PLAYGROUND_EXTERNAL, + CHANGE_EXTERNAL_LIBRARY, CHANGE_SIDE_CONTENT_HEIGHT, CLEAR_REPL_INPUT, CLEAR_REPL_OUTPUT, @@ -272,12 +272,12 @@ export const reducer: Reducer = ( * This action is only meant for Playground usage, where * the external library is displayed. */ - case CHANGE_PLAYGROUND_EXTERNAL: + case CHANGE_EXTERNAL_LIBRARY: return { ...state, [workspaceLocation]: { ...state[workspaceLocation], - playgroundExternal: action.payload.newExternal + externalLibrary: action.payload.newExternal } }; case HANDLE_CONSOLE_LOG: diff --git a/src/sagas/__tests__/playground.ts b/src/sagas/__tests__/playground.ts index da4e7a81e8..4b132dbb32 100644 --- a/src/sagas/__tests__/playground.ts +++ b/src/sagas/__tests__/playground.ts @@ -35,7 +35,7 @@ describe('Playground saga tests', () => { ...defaultWorkspaceManager, playground: { ...createDefaultWorkspace(WorkspaceLocations.playground), - playgroundExternal: ExternalLibraryNames.NONE, + externalLibrary: ExternalLibraryNames.NONE, editorValue: dummyEditorValue } } @@ -57,7 +57,7 @@ describe('Playground saga tests', () => { ...defaultWorkspaceManager, playground: { ...createDefaultWorkspace(WorkspaceLocations.playground), - playgroundExternal: ExternalLibraryNames.NONE, + externalLibrary: ExternalLibraryNames.NONE, editorValue: dummyEditorValue } } @@ -75,7 +75,7 @@ describe('Playground saga tests', () => { function createQueryString(code: string, state: IState): string { const chapter: number = state.workspaces.playground.context.chapter; - const external: ExternalLibraryName = state.workspaces.playground.playgroundExternal; + const external: ExternalLibraryName = state.workspaces.playground.externalLibrary; const newQueryString: string = qs.stringify({ prgrm: compressToEncodedURIComponent(code), chap: chapter, diff --git a/src/sagas/__tests__/workspaces.ts b/src/sagas/__tests__/workspaces.ts index ec2c67e0da..d3fca2e4a6 100644 --- a/src/sagas/__tests__/workspaces.ts +++ b/src/sagas/__tests__/workspaces.ts @@ -389,14 +389,14 @@ describe('PLAYGROUND_EXTERNAL_SELECT', () => { }; }); - test('puts changePlaygroundExternal, beginClearContext, clearReplOutput and calls showSuccessMessage correctly', () => { + test('puts changeExternalLibrary, beginClearContext, clearReplOutput and calls showSuccessMessage correctly', () => { const oldExternalLibraryName = ExternalLibraryNames.SOUNDS; const newExternalLibraryName = ExternalLibraryNames.RUNES; const newDefaultState = generateDefaultState(workspaceLocation, { context, globals, - playgroundExternal: oldExternalLibraryName + externalLibrary: oldExternalLibraryName }); const symbols = externalLibraries.get(newExternalLibraryName)!; @@ -411,7 +411,7 @@ describe('PLAYGROUND_EXTERNAL_SELECT', () => { return expectSaga(workspaceSaga) .withState(newDefaultState) - .put(actions.changePlaygroundExternal(newExternalLibraryName, workspaceLocation)) + .put(actions.changeExternalLibrary(newExternalLibraryName, workspaceLocation)) .put(actions.beginClearContext(library, workspaceLocation)) .put(actions.clearReplOutput(workspaceLocation)) .call(showSuccessMessage, `Switched to ${newExternalLibraryName} library`, 1000) @@ -432,7 +432,7 @@ describe('PLAYGROUND_EXTERNAL_SELECT', () => { const newDefaultState = generateDefaultState(workspaceLocation, { context, globals, - playgroundExternal: oldExternalLibraryName + externalLibrary: oldExternalLibraryName }); const symbols = externalLibraries.get(newExternalLibraryName)!; @@ -447,7 +447,7 @@ describe('PLAYGROUND_EXTERNAL_SELECT', () => { return expectSaga(workspaceSaga) .withState(newDefaultState) - .not.put(actions.changePlaygroundExternal(newExternalLibraryName)) + .not.put(actions.changeExternalLibrary(newExternalLibraryName, workspaceLocation)) .not.put(actions.beginClearContext(library, workspaceLocation)) .not.put(actions.clearReplOutput(workspaceLocation)) .not.call(showSuccessMessage, `Switched to ${newExternalLibraryName} library`, 1000) diff --git a/src/sagas/playground.ts b/src/sagas/playground.ts index 106c897ed4..20a3ec49c7 100644 --- a/src/sagas/playground.ts +++ b/src/sagas/playground.ts @@ -24,7 +24,7 @@ function* updateQueryString() { (state: IState) => state.workspaces.playground.context.chapter ); const external: ExternalLibraryName = yield select( - (state: IState) => state.workspaces.playground.playgroundExternal + (state: IState) => state.workspaces.playground.externalLibrary ); const newQueryString: string = qs.stringify({ prgrm: compressToEncodedURIComponent(codeString), diff --git a/src/sagas/workspaces.ts b/src/sagas/workspaces.ts index 7e282d4b40..18b9b53619 100644 --- a/src/sagas/workspaces.ts +++ b/src/sagas/workspaces.ts @@ -231,7 +231,7 @@ export default function* workspaceSaga(): SagaIterator { ); const newExternalLibraryName = (action as actionTypes.IAction).payload.externalLibraryName; const oldExternalLibraryName = yield select( - (state: IState) => state.workspaces[workspaceLocation].playgroundExternal + (state: IState) => state.workspaces[workspaceLocation].externalLibrary ); const symbols = externalLibraries.get(newExternalLibraryName)!; const library = { @@ -243,7 +243,7 @@ export default function* workspaceSaga(): SagaIterator { globals }; if (newExternalLibraryName !== oldExternalLibraryName) { - yield put(actions.changePlaygroundExternal(newExternalLibraryName, workspaceLocation)); + yield put(actions.changeExternalLibrary(newExternalLibraryName, workspaceLocation)); yield put(actions.beginClearContext(library, workspaceLocation)); yield put(actions.clearReplOutput(workspaceLocation)); yield call(showSuccessMessage, `Switched to ${newExternalLibraryName} library`, 1000); From 13ad6908a01d7a3b11426d5e51a53a821ac555aa Mon Sep 17 00:00:00 2001 From: Chee Yuan Date: Fri, 2 Aug 2019 01:23:03 +0800 Subject: [PATCH 3/4] Fix typo --- src/components/Application.tsx | 4 ++-- src/components/__tests__/Application.tsx | 2 +- src/containers/ApplicationContainer.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Application.tsx b/src/components/Application.tsx index 974ec75947..b4e684f9e1 100644 --- a/src/components/Application.tsx +++ b/src/components/Application.tsx @@ -22,7 +22,7 @@ export interface IStateProps { role?: Role; title: string; name?: string; - currentExternalLibraryLibrary: ExternalLibraryName; + currentExternalLibrary: ExternalLibraryName; } export interface IDispatchProps { @@ -86,7 +86,7 @@ const toLogin = (props: IApplicationProps) => () => ( const parsePlayground = (props: IApplicationProps) => { const prgrm = parsePrgrm(props); const chapter = parseChapter(props) || props.currentPlaygroundChapter; - const externalLibraryName = parseExternalLibrary(props) || props.currentExternalLibraryLibrary; + const externalLibraryName = parseExternalLibrary(props) || props.currentExternalLibrary; if (prgrm) { props.handleEditorValueChange(prgrm); props.handleEnsureLibrariesLoaded(); diff --git a/src/components/__tests__/Application.tsx b/src/components/__tests__/Application.tsx index dc678a1dc9..f3236083d2 100644 --- a/src/components/__tests__/Application.tsx +++ b/src/components/__tests__/Application.tsx @@ -11,7 +11,7 @@ test('Application renders correctly', () => { title: 'Cadet', currentPlaygroundChapter: 2, handleLogOut: () => {}, - currentExternalLibraryLibrary: ExternalLibraryNames.NONE, + currentExternalLibrary: ExternalLibraryNames.NONE, handleClearContext: (chapter: number, externalLibraryName: ExternalLibraryName) => {}, handleEditorValueChange: (val: string) => {}, handleEditorUpdateBreakpoints: (breakpoints: string[]) => {}, diff --git a/src/containers/ApplicationContainer.ts b/src/containers/ApplicationContainer.ts index 72706e1d14..0310bbde7c 100644 --- a/src/containers/ApplicationContainer.ts +++ b/src/containers/ApplicationContainer.ts @@ -25,7 +25,7 @@ const mapStateToProps: MapStateToProps = state => ({ role: state.session.role, name: state.session.name, currentPlaygroundChapter: state.workspaces.playground.context.chapter, - currentExternalLibraryLibrary: state.workspaces.playground.externalLibrary + currentExternalLibrary: state.workspaces.playground.externalLibrary }); const workspaceLocation = WorkspaceLocations.playground; From 6e18cebe10c5e50fa9dc2ea99846e902607f8b34 Mon Sep 17 00:00:00 2001 From: Chee Yuan Date: Fri, 2 Aug 2019 01:27:24 +0800 Subject: [PATCH 4/4] Removed misleading comment --- src/reducers/workspaces.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/reducers/workspaces.ts b/src/reducers/workspaces.ts index 61cef04ccd..7982054067 100755 --- a/src/reducers/workspaces.ts +++ b/src/reducers/workspaces.ts @@ -268,10 +268,6 @@ export const reducer: Reducer = ( } } }; - /** - * This action is only meant for Playground usage, where - * the external library is displayed. - */ case CHANGE_EXTERNAL_LIBRARY: return { ...state,