Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b6c83b1
Add a default variant as a constant
anubh-v Apr 6, 2020
f55b05c
slangHelper: Add variant as a parameter to createContext
anubh-v Apr 6, 2020
70d33ae
Use default source variant when creating default workspace
anubh-v Apr 6, 2020
1491100
Use default variant when clearing context
anubh-v Apr 6, 2020
f95894b
Fix style issues
anubh-v Apr 6, 2020
a01a8a5
Support non-deterministic Source (#1)
arsalan0c Mar 29, 2020
2e9e877
update notification to show correct chapter name
arsalan0c Mar 29, 2020
ad0ea1a
Set variant property in createContext
anubh-v Apr 6, 2020
6c8ecef
Handle variant independently from chapter
anubh-v Apr 6, 2020
219486f
clear context when variant changes
arsalan0c Apr 7, 2020
614820e
make variant optional in createContext
arsalan0c Apr 7, 2020
23293b6
use function for calling non-det
arsalan0c Apr 7, 2020
f796d95
add semicolon
arsalan0c Apr 7, 2020
7ec1c7f
remove shadowed name
arsalan0c Apr 7, 2020
846109d
generalize chapter selection
arsalan0c Apr 7, 2020
2420db0
fix test
arsalan0c Apr 7, 2020
57697a9
handle variant urls
arsalan0c Apr 7, 2020
abcc0bd
format
arsalan0c Apr 7, 2020
ec7a155
add space for variant display
arsalan0c Apr 7, 2020
898f285
change variable name
arsalan0c Apr 7, 2020
5b4d7bc
remove variant export
arsalan0c Apr 7, 2020
0300604
rename datastructure
arsalan0c Apr 7, 2020
aa52208
use variant in button name
arsalan0c Apr 7, 2020
7680705
Merge branch 'sa_2021' into non-det-sa_2021-rebased
anubh-v Apr 8, 2020
0789e5b
Merge branch 'sa_2021' into non-det-sa_2021-rebased
martin-henz Apr 9, 2020
19b3fa4
use default variant value
arsalan0c Apr 9, 2020
9007dec
fix: chapter in share link
arsalan0c Apr 9, 2020
1c66131
refactor language url name
arsalan0c Apr 9, 2020
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
4 changes: 3 additions & 1 deletion src/actions/__tests__/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ test('changeSideContentHeight generates correct action object', () => {

test('chapterSelect generates correct action object', () => {
const chapter = 3;
const action = chapterSelect(chapter, playgroundWorkspace);
const variant = 'default';
const action = chapterSelect(chapter, variant, playgroundWorkspace);
expect(action).toEqual({
type: actionTypes.CHAPTER_SELECT,
payload: {
chapter,
variant,
workspaceLocation: playgroundWorkspace
}
});
Expand Down
8 changes: 7 additions & 1 deletion src/actions/workspaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { action } from 'typesafe-actions';

import { Variant } from 'js-slang/dist/types';
import { ExternalLibraryName, Library } from '../components/assessment/assessmentShape';
import { IPosition } from '../components/workspace/Editor';
import { IWorkspaceState, SideContentType } from '../reducers/states';
Expand Down Expand Up @@ -46,9 +47,14 @@ export const changeExecTime = (execTime: string, workspaceLocation: WorkspaceLoc
export const changeSideContentHeight = (height: number, workspaceLocation: WorkspaceLocation) =>
action(actionTypes.CHANGE_SIDE_CONTENT_HEIGHT, { height, workspaceLocation });

export const chapterSelect = (chapter: number, workspaceLocation: WorkspaceLocation) =>
export const chapterSelect = (
chapter: number,
variant: Variant,
workspaceLocation: WorkspaceLocation
) =>
action(actionTypes.CHAPTER_SELECT, {
chapter,
variant,
workspaceLocation
});

Expand Down
34 changes: 29 additions & 5 deletions src/components/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,33 @@ import Material from '../containers/material/MaterialContainer';
import MissionControlContainer from '../containers/missionControl';
import Playground from '../containers/PlaygroundContainer';
import Sourcecast from '../containers/sourcecast/SourcecastContainer';
import { Role, sourceChapters } from '../reducers/states';
import { languageURLNames, Role } from '../reducers/states';
import { stringParamToInt } from '../utils/paramParseHelpers';
import { ExternalLibraryName, ExternalLibraryNames } from './assessment/assessmentShape';
import Contributors from './contributors';
import NavigationBar from './NavigationBar';
import NotFound from './NotFound';

import { Variant } from 'js-slang/dist/types';

export interface IApplicationProps extends IDispatchProps, IStateProps, RouteComponentProps<{}> {}

export interface IStateProps {
accessToken?: string;
currentPlaygroundChapter: number;
currentPlaygroundVariant: Variant;
role?: Role;
title: string;
name?: string;
currentExternalLibrary: ExternalLibraryName;
}

export interface IDispatchProps {
handleClearContext: (chapter: number, externalLibraryName: ExternalLibraryName) => void;
handleClearContext: (
chapter: number,
variant: Variant,
externalLibraryName: ExternalLibraryName
) => void;
handleEditorValueChange: (val: string) => void;
handleEditorUpdateBreakpoints: (breakpoints: string[]) => void;
handleEnsureLibrariesLoaded: () => void;
Expand Down Expand Up @@ -90,12 +97,13 @@ const toLogin = (props: IApplicationProps) => () => (
const parsePlayground = (props: IApplicationProps) => {
const prgrm = parsePrgrm(props);
const chapter = parseChapter(props) || props.currentPlaygroundChapter;
const variant = parseVariant(props) || props.currentPlaygroundVariant;
const externalLibraryName = parseExternalLibrary(props) || props.currentExternalLibrary;
const execTime = parseExecTime(props);
if (prgrm) {
props.handleEditorValueChange(prgrm);
props.handleEnsureLibrariesLoaded();
props.handleClearContext(chapter, externalLibraryName);
props.handleClearContext(chapter, variant, externalLibraryName);
props.handleExternalLibrarySelect(externalLibraryName);
props.handleSetExecTime(execTime);
}
Expand All @@ -112,8 +120,24 @@ const parsePrgrm = (props: RouteComponentProps<{}>) => {

const parseChapter = (props: RouteComponentProps<{}>) => {
const chapQuery = qs.parse(props.location.hash).chap;
const chap = chapQuery === undefined ? NaN : parseInt(chapQuery, 10);
return sourceChapters.includes(chap) ? chap : undefined;

const chap: number = languageURLNames.has(chapQuery)
? languageURLNames.get(chapQuery)!.chapter
: chapQuery === undefined
? NaN
: parseInt(chapQuery, 10);

return chap ? chap : undefined;
};

const parseVariant = (props: RouteComponentProps<{}>) => {
const chapQuery = qs.parse(props.location.hash).chap;

const variant: Variant = languageURLNames.has(chapQuery)
? languageURLNames.get(chapQuery)!.variant
: 'default';

return variant;
};

const parseExternalLibrary = (props: RouteComponentProps<{}>) => {
Expand Down
12 changes: 9 additions & 3 deletions src/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as React from 'react';
import { HotKeys } from 'react-hotkeys';
import { RouteComponentProps } from 'react-router';

import { Variant } from 'js-slang/dist/types';
import { InterpreterOutput, SideContentType } from '../reducers/states';
import { LINKS } from '../utils/constants';
import { ExternalLibraryName, ExternalLibraryNames } from './assessment/assessmentShape';
Expand Down Expand Up @@ -70,6 +71,7 @@ export interface IStateProps {
sharedbAceInitValue: string;
sharedbAceIsInviting: boolean;
sourceChapter: number;
sourceVariant: Variant;
websocketStatus: number;
externalLibraryName: string;
usingSubst: boolean;
Expand All @@ -80,7 +82,7 @@ export interface IDispatchProps {
handleBrowseHistoryDown: () => void;
handleBrowseHistoryUp: () => void;
handleChangeExecTime: (execTime: number) => void;
handleChapterSelect: (chapter: number) => void;
handleChapterSelect: (chapter: number, variant: Variant) => void;
handleDeclarationNavigate: (cursorPosition: IPosition) => void;
handleEditorEval: () => void;
handleEditorHeightChange: (height: number) => void;
Expand Down Expand Up @@ -151,7 +153,10 @@ class Playground extends React.Component<IPlaygroundProps, PlaygroundState> {
/>
);

const chapterSelectHandler = ({ chapter }: { chapter: number }, e: any) => {
const chapterSelectHandler = (
{ chapter, variant }: { chapter: number; variant: Variant },
e: any
) => {
if (
(chapter <= 2 && this.state.hasBreakpoints) ||
this.state.selectedTab === SideContentType.substVisualizer
Expand All @@ -162,12 +167,13 @@ class Playground extends React.Component<IPlaygroundProps, PlaygroundState> {
this.props.handleReplOutputClear();
this.props.handleUsingSubst(false);
}
this.props.handleChapterSelect(chapter);
this.props.handleChapterSelect(chapter, variant);
};
const chapterSelect = (
<ChapterSelect
handleChapterSelect={chapterSelectHandler}
sourceChapter={this.props.sourceChapter}
sourceVariant={this.props.sourceVariant}
key="chapter"
/>
);
Expand Down
9 changes: 8 additions & 1 deletion src/components/__tests__/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ import { mockRouterProps } from '../../mocks/components';
import Application, { IApplicationProps } from '../Application';
import { ExternalLibraryName, ExternalLibraryNames } from '../assessment/assessmentShape';

import { Variant } from 'js-slang/dist/types';

test('Application renders correctly', () => {
const props: IApplicationProps = {
...mockRouterProps('/academy', {}),
title: 'Cadet',
currentPlaygroundChapter: 2,
currentPlaygroundVariant: 'default',
handleLogOut: () => {},
currentExternalLibrary: ExternalLibraryNames.NONE,
handleClearContext: (chapter: number, externalLibraryName: ExternalLibraryName) => {},
handleClearContext: (
chapter: number,
variant: Variant,
externalLibraryName: ExternalLibraryName
) => {},
handleEditorValueChange: (val: string) => {},
handleEditorUpdateBreakpoints: (breakpoints: string[]) => {},
handleEnsureLibrariesLoaded: () => {},
Expand Down
2 changes: 2 additions & 0 deletions src/components/__tests__/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { shallow } from 'enzyme';
import * as React from 'react';

import { Variant } from 'js-slang/dist/types';
import { SideContentType } from 'src/reducers/states';
import { mockRouterProps } from '../../mocks/components';
import { ExternalLibraryName, ExternalLibraryNames } from '../assessment/assessmentShape';
Expand All @@ -22,6 +23,7 @@ const baseProps = {
sharedbAceIsInviting: false,
sideContentHeight: 40,
sourceChapter: 2,
sourceVariant: 'default' as Variant,
externalLibraryName: ExternalLibraryNames.NONE,
output: [],
replValue: '',
Expand Down
3 changes: 2 additions & 1 deletion src/components/assessment/assessmentShape.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SourceError } from 'js-slang/dist/types';
import { SourceError, Variant } from 'js-slang/dist/types';

/*
* Used to display information regarding an assessment in the UI.
Expand Down Expand Up @@ -166,6 +166,7 @@ type ExternalLibrary = {

export type Library = {
chapter: number;
variant?: Variant;
external: ExternalLibrary;
globals: Array<{
0: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { IconNames } from '@blueprintjs/icons';
import { ItemRenderer, Select } from '@blueprintjs/select';
import * as React from 'react';
import { externalLibraries } from '../../../reducers/externalLibraries';
import { sourceChapters } from '../../../reducers/states';
import { sourceLanguages, styliseChapter } from '../../../reducers/states';

import { ExternalLibraryName, IAssessment, Library } from '../../assessment/assessmentShape';
import { controlButton } from '../../commons';
import { emptyLibrary } from '../assessmentTemplates';
import { assignToPath, getValueFromPath } from './';
import TextareaContent from './TextareaContent';

import { Variant } from 'js-slang/dist/types';

interface IProps {
assessment: IAssessment;
label: string;
Expand Down Expand Up @@ -120,7 +122,7 @@ export class DeploymentTab extends React.Component<IProps, {}> {
<Divider />
Interpreter:
<br />
{chapterSelect(deployment.chapter, this.handleChapterSelect)}
{chapterSelect(deployment.chapter, deployment.variant, this.handleChapterSelect)}
<Divider />
{symbolsFragment}
<Divider />
Expand Down Expand Up @@ -240,14 +242,15 @@ const altEval = (str: string): any => {
return Function('"use strict";return (' + str + ')')();
};

function styliseChapter(chap: number) {
return `Source \xa7${chap}`;
}

const chapters = sourceChapters.map(chap => ({ displayName: styliseChapter(chap), chapter: chap }));
const chapters = sourceLanguages.map(lang => ({
chapter: lang.chapter,
variant: lang.variant,
displayName: styliseChapter(lang.chapter, lang.variant)
}));

const chapterSelect = (
currentChap: number,
variant: Variant = 'default',
handleSelect = (i: IChapter, e: React.ChangeEvent<HTMLSelectElement>) => {}
) => (
<ChapterSelectComponent
Expand All @@ -259,7 +262,7 @@ const chapterSelect = (
>
<Button
className={Classes.MINIMAL}
text={styliseChapter(currentChap)}
text={styliseChapter(currentChap, variant)}
rightIcon={IconNames.DOUBLE_CARET_VERTICAL}
/>
</ChapterSelectComponent>
Expand Down
3 changes: 3 additions & 0 deletions src/components/sourcecast/Sourcecast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IconNames } from '@blueprintjs/icons';
import * as classNames from 'classnames';
import * as React from 'react';

import { Variant } from 'js-slang/dist/types';
import { InterpreterOutput, SideContentType } from '../../reducers/states';
import { ExternalLibraryName } from '../assessment/assessmentShape';
import Workspace, { WorkspaceProps } from '../workspace';
Expand Down Expand Up @@ -57,6 +58,7 @@ export interface IStateProps {
sideContentHeight?: number;
sourcecastIndex: ISourcecastData[] | null;
sourceChapter: number;
sourceVariant: Variant;
}

export interface IDispatchProps {
Expand Down Expand Up @@ -140,6 +142,7 @@ class Sourcecast extends React.Component<ISourcecastProps> {
<ChapterSelect
handleChapterSelect={chapterSelectHandler}
sourceChapter={this.props.sourceChapter}
sourceVariant={this.props.sourceVariant}
key="chapter"
/>
);
Expand Down
3 changes: 3 additions & 0 deletions src/components/sourcecast/Sourcereel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IconNames } from '@blueprintjs/icons';
import * as classNames from 'classnames';
import * as React from 'react';

import { Variant } from 'js-slang/dist/types';
import { InterpreterOutput, SideContentType } from '../../reducers/states';
import { ExternalLibraryName } from '../assessment/assessmentShape';
import Workspace, { WorkspaceProps } from '../workspace';
Expand Down Expand Up @@ -52,6 +53,7 @@ export interface IStateProps {
sideContentHeight?: number;
sourcecastIndex: ISourcecastData[] | null;
sourceChapter: number;
sourceVariant: Variant;
timeResumed: number;
}

Expand Down Expand Up @@ -142,6 +144,7 @@ class Sourcereel extends React.Component<ISourcereelProps> {
<ChapterSelect
handleChapterSelect={chapterSelectHandler}
sourceChapter={this.props.sourceChapter}
sourceVariant={this.props.sourceVariant}
key="chapter"
/>
);
Expand Down
32 changes: 22 additions & 10 deletions src/components/workspace/controlBar/chapterSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,44 @@ import { IconNames } from '@blueprintjs/icons';
import { ItemRenderer, Select } from '@blueprintjs/select';
import * as React from 'react';

import { sourceChapters } from '../../../reducers/states';
import { Variant } from 'js-slang/dist/types';
import { ISourceLanguage, sourceLanguages, styliseChapter } from '../../../reducers/states';

export type ChapterSelectProps = {
handleChapterSelect?: (i: IChapter, e: React.ChangeEvent<HTMLSelectElement>) => void;
sourceChapter: number;
sourceVariant: Variant;
key: string;
};

export interface IChapter {
chapter: number;
variant: Variant;
displayName: string;
}

export function ChapterSelect(props: ChapterSelectProps) {
const styliseChapter = (chap: number) => `Source \xa7${chap}`;
const chapters = sourceChapters.map(chap => ({
displayName: styliseChapter(chap),
chapter: chap
}));
const chapterRenderer: ItemRenderer<IChapter> = (chap, { handleClick }) => (
<MenuItem active={false} key={chap.chapter} onClick={handleClick} text={chap.displayName} />
const chapters = sourceLanguages.map((lang: ISourceLanguage) => {
return {
chapter: lang.chapter,
variant: lang.variant,
displayName: styliseChapter(lang.chapter, lang.variant)
};
});

const chapterRenderer: ItemRenderer<IChapter> = (lang, { handleClick }) => (
<MenuItem
active={false}
key={lang.chapter + lang.variant}
onClick={handleClick}
text={lang.displayName}
/>
);
const ChapterSelectComponent = Select.ofType<IChapter>();

const chapSelect = (
currentChap: number,
currentVariant: Variant,
handleSelect = (i: IChapter, e: React.ChangeEvent<HTMLSelectElement>) => {}
) => (
<ChapterSelectComponent
Expand All @@ -40,11 +52,11 @@ export function ChapterSelect(props: ChapterSelectProps) {
>
<Button
className={Classes.MINIMAL}
text={styliseChapter(currentChap)}
text={styliseChapter(currentChap, currentVariant)}
rightIcon={IconNames.DOUBLE_CARET_VERTICAL}
/>
</ChapterSelectComponent>
);

return chapSelect(props.sourceChapter, props.handleChapterSelect);
return chapSelect(props.sourceChapter, props.sourceVariant, props.handleChapterSelect);
}
Loading