Skip to content

Commit

Permalink
CSE Machine: Implement navigation arrows to jump to the next/previous…
Browse files Browse the repository at this point in the history
… change in environment (frontend) (#2869)

* Add extra {} when the control item is of type Program

* Format files properly and remove unnecessary lines

* Update changepointSteps in context to match js-slang

* Implement navigation arrows to jump to next/previous change in environment

* update changepointSteps in context 2

* Format code

* Update changpointSteps in context to match js-slang 3

* Revert unintentional lockfile change

* Resolve conflict

* please do not remove config files

* Fix format

* Fix merging mistakes

---------

Co-authored-by: NhatMinh0208 <[email protected]>
  • Loading branch information
2 people authored and izruff committed Mar 30, 2024
1 parent ed89765 commit 37f1b4c
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/commons/application/ApplicationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ export const defaultWorkspaceManager: WorkspaceManagerState = {
currentStep: -1,
stepsTotal: 0,
breakpointSteps: [],
changepointSteps: [],
activeEditorTabIndex: 0,
editorTabs: [
{
Expand Down Expand Up @@ -466,6 +467,7 @@ export const defaultWorkspaceManager: WorkspaceManagerState = {
currentStep: -1,
stepsTotal: 0,
breakpointSteps: [],
changepointSteps: [],
activeEditorTabIndex: 0,
editorTabs: [
{
Expand Down
4 changes: 4 additions & 0 deletions src/commons/sagas/WorkspaceSaga/helpers/evalCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ export function* evalCode(
yield put(
actions.updateBreakpointSteps(context.runtime.breakpointSteps, workspaceLocation)
);
yield put(
actions.updateChangePointSteps(context.runtime.changepointSteps, workspaceLocation)
);
}
} else {
// Safe to use ! as storyEnv will be defined from above when we call from EVAL_STORY
Expand Down Expand Up @@ -315,6 +318,7 @@ export function* evalCode(
// But TS can't infer that yet, so we need a typecast here.
yield put(actions.toggleUpdateCse(false, workspaceLocation as any));
yield put(actions.updateBreakpointSteps(context.runtime.breakpointSteps, workspaceLocation));
yield put(actions.updateChangePointSteps(context.runtime.changepointSteps, workspaceLocation));
}
// Stop the home icon from flashing for an error if it is doing so since the evaluation is successful
if (context.executionMethod === 'cse-machine' || context.executionMethod === 'interpreter') {
Expand Down
18 changes: 12 additions & 6 deletions src/commons/sagas/__tests__/PlaygroundSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ describe('Playground saga tests', () => {
updateCse: true,
currentStep: -1,
stepsTotal: 0,
breakpointSteps: []
breakpointSteps: [],
changepointSteps: []
}
}
};
Expand Down Expand Up @@ -154,7 +155,8 @@ describe('Playground saga tests', () => {
updateCse: true,
currentStep: -1,
stepsTotal: 0,
breakpointSteps: []
breakpointSteps: [],
changepointSteps: []
}
}
};
Expand Down Expand Up @@ -221,7 +223,8 @@ describe('Playground saga tests', () => {
updateCse: true,
currentStep: -1,
stepsTotal: 0,
breakpointSteps: []
breakpointSteps: [],
changepointSteps: []
}
}
};
Expand Down Expand Up @@ -271,7 +274,8 @@ describe('Playground saga tests', () => {
updateCse: true,
currentStep: -1,
stepsTotal: 0,
breakpointSteps: []
breakpointSteps: [],
changepointSteps: []
}
}
};
Expand Down Expand Up @@ -340,7 +344,8 @@ describe('Playground saga tests', () => {
updateCse: true,
currentStep: -1,
stepsTotal: 0,
breakpointSteps: []
breakpointSteps: [],
changepointSteps: []
}
}
};
Expand Down Expand Up @@ -398,7 +403,8 @@ describe('Playground saga tests', () => {
updateCse: true,
currentStep: -1,
stepsTotal: 0,
breakpointSteps: []
breakpointSteps: [],
changepointSteps: []
}
}
};
Expand Down
33 changes: 31 additions & 2 deletions src/commons/sideContent/content/SideContentCseMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type StateProps = {
stepsTotal: number;
currentStep: number;
breakpointSteps: number[];
changepointSteps: number[];
needCseUpdate: boolean;
machineOutput: InterpreterOutput[];
};
Expand Down Expand Up @@ -257,12 +258,14 @@ class SideContentCseMachineBase extends React.Component<CseMachineProps, State>
<Button
disabled={!this.state.visualization}
icon="chevron-left"
onClick={this.stepPrevious}
onClick={
CseMachine.getControlStash() ? this.stepPrevious : this.stepPrevChangepoint
}
/>
<Button
disabled={!this.state.visualization}
icon="chevron-right"
onClick={this.stepNext}
onClick={CseMachine.getControlStash() ? this.stepNext : this.stepNextChangepoint}
/>
<Button
disabled={!this.state.visualization}
Expand Down Expand Up @@ -450,6 +453,31 @@ class SideContentCseMachineBase extends React.Component<CseMachineProps, State>
this.sliderShift(0);
this.sliderRelease(0);
};

private stepNextChangepoint = () => {
for (const step of this.props.changepointSteps) {
if (step > this.state.value) {
this.sliderShift(step);
this.sliderRelease(step);
return;
}
}
this.sliderShift(this.props.stepsTotal);
this.sliderRelease(this.props.stepsTotal);
};

private stepPrevChangepoint = () => {
for (let i = this.props.changepointSteps.length - 1; i >= 0; i--) {
const step = this.props.changepointSteps[i];
if (step < this.state.value) {
this.sliderShift(step);
this.sliderRelease(step);
return;
}
}
this.sliderShift(0);
this.sliderRelease(0);
};
}

const mapStateToProps: MapStateToProps<StateProps, OwnProps, OverallState> = (
Expand Down Expand Up @@ -479,6 +507,7 @@ const mapStateToProps: MapStateToProps<StateProps, OwnProps, OverallState> = (
stepsTotal: workspace.stepsTotal,
currentStep: workspace.currentStep,
breakpointSteps: workspace.breakpointSteps,
changepointSteps: workspace.changepointSteps,
needCseUpdate: workspace.updateCse,
machineOutput: workspace.output
};
Expand Down
8 changes: 8 additions & 0 deletions src/commons/workspace/WorkspaceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
UPDATE_ACTIVE_EDITOR_TAB,
UPDATE_ACTIVE_EDITOR_TAB_INDEX,
UPDATE_BREAKPOINTSTEPS,
UPDATE_CHANGEPOINTSTEPS,
UPDATE_CURRENT_ASSESSMENT_ID,
UPDATE_CURRENT_SUBMISSION_ID,
UPDATE_CURRENTSTEP,
Expand Down Expand Up @@ -495,6 +496,13 @@ export const updateBreakpointSteps = createAction(
})
);

export const updateChangePointSteps = createAction(
UPDATE_CHANGEPOINTSTEPS,
(changepointSteps: number[], workspaceLocation: WorkspaceLocation) => ({
payload: { changepointSteps, workspaceLocation }
})
);

export const updateLastDebuggerResult = createAction(
UPDATE_LAST_DEBUGGER_RESULT,
(lastDebuggerResult: any, workspaceLocation: WorkspaceLocation) => ({
Expand Down
9 changes: 9 additions & 0 deletions src/commons/workspace/WorkspaceReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
UPDATE_ACTIVE_EDITOR_TAB,
UPDATE_ACTIVE_EDITOR_TAB_INDEX,
UPDATE_BREAKPOINTSTEPS,
UPDATE_CHANGEPOINTSTEPS,
UPDATE_CURRENT_ASSESSMENT_ID,
UPDATE_CURRENT_SUBMISSION_ID,
UPDATE_CURRENTSTEP,
Expand Down Expand Up @@ -1077,6 +1078,14 @@ const oldWorkspaceReducer: Reducer<WorkspaceManagerState, SourceActionType> = (
breakpointSteps: action.payload.breakpointSteps
}
};
case UPDATE_CHANGEPOINTSTEPS:
return {
...state,
[workspaceLocation]: {
...state[workspaceLocation],
changepointSteps: action.payload.changepointSteps
}
};
case UPDATE_LAST_DEBUGGER_RESULT:
return {
...state,
Expand Down
2 changes: 2 additions & 0 deletions src/commons/workspace/WorkspaceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const UPDATE_SUBLANGUAGE = 'UPDATE_SUBLANGUAGE';
export const UPDATE_CURRENTSTEP = 'UPDATE_CURRENTSTEP';
export const UPDATE_STEPSTOTAL = 'UPDATE_STEPSTOTAL';
export const UPDATE_BREAKPOINTSTEPS = 'UPDATE_BREAKPOINTSTEPS';
export const UPDATE_CHANGEPOINTSTEPS = 'UPDATE_CHANGEPOINTSTEPS';
export const CHANGE_SUBLANGUAGE = 'CHANGE_SUBLANGUAGE';
export const UPDATE_LAST_DEBUGGER_RESULT = 'UPDATE_LAST_DEBUGGER_RESULT';
export const UPDATE_LAST_NON_DET_RESULT = 'UPDATE_LAST_NON_DET_RESULT';
Expand Down Expand Up @@ -91,6 +92,7 @@ type PlaygroundWorkspaceAttr = {
readonly currentStep: number;
readonly stepsTotal: number;
readonly breakpointSteps: number[];
readonly changepointSteps: number[];
};
export type PlaygroundWorkspaceState = PlaygroundWorkspaceAttr & WorkspaceState;

Expand Down
3 changes: 2 additions & 1 deletion src/commons/workspace/__tests__/WorkspaceReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,8 @@ describe('LOG_OUT', () => {
updateCse: true,
currentStep: -1,
stepsTotal: 0,
breakpointSteps: []
breakpointSteps: [],
changepointSteps: []
};

const logoutDefaultState: WorkspaceManagerState = {
Expand Down

0 comments on commit 37f1b4c

Please sign in to comment.