Skip to content

Commit ec0aecb

Browse files
CSE Machine: Implement navigation arrows to jump to the next/previous 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 <minhkhicon2468@gmail.com>
1 parent 85a63f1 commit ec0aecb

File tree

8 files changed

+70
-9
lines changed

8 files changed

+70
-9
lines changed

src/commons/application/ApplicationTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ export const defaultWorkspaceManager: WorkspaceManagerState = {
413413
currentStep: -1,
414414
stepsTotal: 0,
415415
breakpointSteps: [],
416+
changepointSteps: [],
416417
activeEditorTabIndex: 0,
417418
editorTabs: [
418419
{
@@ -466,6 +467,7 @@ export const defaultWorkspaceManager: WorkspaceManagerState = {
466467
currentStep: -1,
467468
stepsTotal: 0,
468469
breakpointSteps: [],
470+
changepointSteps: [],
469471
activeEditorTabIndex: 0,
470472
editorTabs: [
471473
{

src/commons/sagas/WorkspaceSaga/helpers/evalCode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ export function* evalCode(
248248
yield put(
249249
actions.updateBreakpointSteps(context.runtime.breakpointSteps, workspaceLocation)
250250
);
251+
yield put(
252+
actions.updateChangePointSteps(context.runtime.changepointSteps, workspaceLocation)
253+
);
251254
}
252255
} else {
253256
// Safe to use ! as storyEnv will be defined from above when we call from EVAL_STORY
@@ -315,6 +318,7 @@ export function* evalCode(
315318
// But TS can't infer that yet, so we need a typecast here.
316319
yield put(actions.toggleUpdateCse(false, workspaceLocation as any));
317320
yield put(actions.updateBreakpointSteps(context.runtime.breakpointSteps, workspaceLocation));
321+
yield put(actions.updateChangePointSteps(context.runtime.changepointSteps, workspaceLocation));
318322
}
319323
// Stop the home icon from flashing for an error if it is doing so since the evaluation is successful
320324
if (context.executionMethod === 'cse-machine' || context.executionMethod === 'interpreter') {

src/commons/sagas/__tests__/PlaygroundSaga.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ describe('Playground saga tests', () => {
8787
updateCse: true,
8888
currentStep: -1,
8989
stepsTotal: 0,
90-
breakpointSteps: []
90+
breakpointSteps: [],
91+
changepointSteps: []
9192
}
9293
}
9394
};
@@ -154,7 +155,8 @@ describe('Playground saga tests', () => {
154155
updateCse: true,
155156
currentStep: -1,
156157
stepsTotal: 0,
157-
breakpointSteps: []
158+
breakpointSteps: [],
159+
changepointSteps: []
158160
}
159161
}
160162
};
@@ -221,7 +223,8 @@ describe('Playground saga tests', () => {
221223
updateCse: true,
222224
currentStep: -1,
223225
stepsTotal: 0,
224-
breakpointSteps: []
226+
breakpointSteps: [],
227+
changepointSteps: []
225228
}
226229
}
227230
};
@@ -271,7 +274,8 @@ describe('Playground saga tests', () => {
271274
updateCse: true,
272275
currentStep: -1,
273276
stepsTotal: 0,
274-
breakpointSteps: []
277+
breakpointSteps: [],
278+
changepointSteps: []
275279
}
276280
}
277281
};
@@ -340,7 +344,8 @@ describe('Playground saga tests', () => {
340344
updateCse: true,
341345
currentStep: -1,
342346
stepsTotal: 0,
343-
breakpointSteps: []
347+
breakpointSteps: [],
348+
changepointSteps: []
344349
}
345350
}
346351
};
@@ -398,7 +403,8 @@ describe('Playground saga tests', () => {
398403
updateCse: true,
399404
currentStep: -1,
400405
stepsTotal: 0,
401-
breakpointSteps: []
406+
breakpointSteps: [],
407+
changepointSteps: []
402408
}
403409
}
404410
};

src/commons/sideContent/content/SideContentCseMachine.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type StateProps = {
5050
stepsTotal: number;
5151
currentStep: number;
5252
breakpointSteps: number[];
53+
changepointSteps: number[];
5354
needCseUpdate: boolean;
5455
machineOutput: InterpreterOutput[];
5556
};
@@ -257,12 +258,14 @@ class SideContentCseMachineBase extends React.Component<CseMachineProps, State>
257258
<Button
258259
disabled={!this.state.visualization}
259260
icon="chevron-left"
260-
onClick={this.stepPrevious}
261+
onClick={
262+
CseMachine.getControlStash() ? this.stepPrevious : this.stepPrevChangepoint
263+
}
261264
/>
262265
<Button
263266
disabled={!this.state.visualization}
264267
icon="chevron-right"
265-
onClick={this.stepNext}
268+
onClick={CseMachine.getControlStash() ? this.stepNext : this.stepNextChangepoint}
266269
/>
267270
<Button
268271
disabled={!this.state.visualization}
@@ -450,6 +453,31 @@ class SideContentCseMachineBase extends React.Component<CseMachineProps, State>
450453
this.sliderShift(0);
451454
this.sliderRelease(0);
452455
};
456+
457+
private stepNextChangepoint = () => {
458+
for (const step of this.props.changepointSteps) {
459+
if (step > this.state.value) {
460+
this.sliderShift(step);
461+
this.sliderRelease(step);
462+
return;
463+
}
464+
}
465+
this.sliderShift(this.props.stepsTotal);
466+
this.sliderRelease(this.props.stepsTotal);
467+
};
468+
469+
private stepPrevChangepoint = () => {
470+
for (let i = this.props.changepointSteps.length - 1; i >= 0; i--) {
471+
const step = this.props.changepointSteps[i];
472+
if (step < this.state.value) {
473+
this.sliderShift(step);
474+
this.sliderRelease(step);
475+
return;
476+
}
477+
}
478+
this.sliderShift(0);
479+
this.sliderRelease(0);
480+
};
453481
}
454482

455483
const mapStateToProps: MapStateToProps<StateProps, OwnProps, OverallState> = (
@@ -479,6 +507,7 @@ const mapStateToProps: MapStateToProps<StateProps, OwnProps, OverallState> = (
479507
stepsTotal: workspace.stepsTotal,
480508
currentStep: workspace.currentStep,
481509
breakpointSteps: workspace.breakpointSteps,
510+
changepointSteps: workspace.changepointSteps,
482511
needCseUpdate: workspace.updateCse,
483512
machineOutput: workspace.output
484513
};

src/commons/workspace/WorkspaceActions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
UPDATE_ACTIVE_EDITOR_TAB,
5959
UPDATE_ACTIVE_EDITOR_TAB_INDEX,
6060
UPDATE_BREAKPOINTSTEPS,
61+
UPDATE_CHANGEPOINTSTEPS,
6162
UPDATE_CURRENT_ASSESSMENT_ID,
6263
UPDATE_CURRENT_SUBMISSION_ID,
6364
UPDATE_CURRENTSTEP,
@@ -495,6 +496,13 @@ export const updateBreakpointSteps = createAction(
495496
})
496497
);
497498

499+
export const updateChangePointSteps = createAction(
500+
UPDATE_CHANGEPOINTSTEPS,
501+
(changepointSteps: number[], workspaceLocation: WorkspaceLocation) => ({
502+
payload: { changepointSteps, workspaceLocation }
503+
})
504+
);
505+
498506
export const updateLastDebuggerResult = createAction(
499507
UPDATE_LAST_DEBUGGER_RESULT,
500508
(lastDebuggerResult: any, workspaceLocation: WorkspaceLocation) => ({

src/commons/workspace/WorkspaceReducer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import {
7777
UPDATE_ACTIVE_EDITOR_TAB,
7878
UPDATE_ACTIVE_EDITOR_TAB_INDEX,
7979
UPDATE_BREAKPOINTSTEPS,
80+
UPDATE_CHANGEPOINTSTEPS,
8081
UPDATE_CURRENT_ASSESSMENT_ID,
8182
UPDATE_CURRENT_SUBMISSION_ID,
8283
UPDATE_CURRENTSTEP,
@@ -1077,6 +1078,14 @@ const oldWorkspaceReducer: Reducer<WorkspaceManagerState, SourceActionType> = (
10771078
breakpointSteps: action.payload.breakpointSteps
10781079
}
10791080
};
1081+
case UPDATE_CHANGEPOINTSTEPS:
1082+
return {
1083+
...state,
1084+
[workspaceLocation]: {
1085+
...state[workspaceLocation],
1086+
changepointSteps: action.payload.changepointSteps
1087+
}
1088+
};
10801089
case UPDATE_LAST_DEBUGGER_RESULT:
10811090
return {
10821091
...state,

src/commons/workspace/WorkspaceTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const UPDATE_SUBLANGUAGE = 'UPDATE_SUBLANGUAGE';
6161
export const UPDATE_CURRENTSTEP = 'UPDATE_CURRENTSTEP';
6262
export const UPDATE_STEPSTOTAL = 'UPDATE_STEPSTOTAL';
6363
export const UPDATE_BREAKPOINTSTEPS = 'UPDATE_BREAKPOINTSTEPS';
64+
export const UPDATE_CHANGEPOINTSTEPS = 'UPDATE_CHANGEPOINTSTEPS';
6465
export const CHANGE_SUBLANGUAGE = 'CHANGE_SUBLANGUAGE';
6566
export const UPDATE_LAST_DEBUGGER_RESULT = 'UPDATE_LAST_DEBUGGER_RESULT';
6667
export const UPDATE_LAST_NON_DET_RESULT = 'UPDATE_LAST_NON_DET_RESULT';
@@ -91,6 +92,7 @@ type PlaygroundWorkspaceAttr = {
9192
readonly currentStep: number;
9293
readonly stepsTotal: number;
9394
readonly breakpointSteps: number[];
95+
readonly changepointSteps: number[];
9496
};
9597
export type PlaygroundWorkspaceState = PlaygroundWorkspaceAttr & WorkspaceState;
9698

src/commons/workspace/__tests__/WorkspaceReducer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,8 @@ describe('LOG_OUT', () => {
861861
updateCse: true,
862862
currentStep: -1,
863863
stepsTotal: 0,
864-
breakpointSteps: []
864+
breakpointSteps: [],
865+
changepointSteps: []
865866
};
866867

867868
const logoutDefaultState: WorkspaceManagerState = {

0 commit comments

Comments
 (0)