Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring & Debugging Content #251

Merged
merged 24 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
88a9338
Add sections for Debugging/Refactoring Module
bonham000 Nov 4, 2020
83e754e
Fix issue intializing monaco editor with custom type definitions
bonham000 Nov 4, 2020
ccbaa9b
Remove debug statements
bonham000 Nov 4, 2020
83966d6
Add the Debug the Sanitize Object Function Challenge
bonham000 Nov 4, 2020
58aeca7
Add the Debug the Reverse Iterator Challenge
bonham000 Nov 4, 2020
abf8631
Add the Debug the Truth Teller Challenge
bonham000 Nov 4, 2020
4c4b44e
Add the Debug the Tree Sum Problem Challenge
bonham000 Nov 4, 2020
901e50d
Add Working with Linked Lists Challenge
bonham000 Nov 4, 2020
a3241ec
Add Code Should be DRY Challenge
bonham000 Nov 4, 2020
040dc52
Add Variable Naming Conventions Challenge
bonham000 Nov 4, 2020
8db6336
Working on Refactor Some Poorly Written Code Challenge
bonham000 Nov 4, 2020
752d997
Delete refactoring challenge...
bonham000 Nov 4, 2020
dd51dcc
Add Refactoring Repeated Code in Tic Tac Toe Challenge
bonham000 Nov 5, 2020
311b287
Add Project: Refactor Legacy Project Code
bonham000 Nov 5, 2020
2cf7a66
Edit Intro challenge
bonham000 Nov 5, 2020
9e6b45a
Rename project
bonham000 Nov 5, 2020
af6d490
Rename Linked List Challenge
bonham000 Nov 6, 2020
7837bec
Update Debugging Section
bonham000 Nov 6, 2020
747d407
Fix bug in Debug the Truth Teller starter code
bonham000 Nov 6, 2020
0cb1c18
Edit
bonham000 Nov 6, 2020
b3ea686
Rename module
bonham000 Nov 6, 2020
ccb9f77
Add videos
bonham000 Nov 6, 2020
8befd83
Merge branch 'master' into content/debugging-and-refactoring
bonham000 Nov 6, 2020
afd1375
Merge branch 'master' into content/debugging-and-refactoring
bonham000 Nov 6, 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
21 changes: 20 additions & 1 deletion packages/client/src/components/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export interface ICodeEditorProps {
userSettings: UserSettings;
editorOptions: ICodeEditorOptions;
onDidBlurEditorText: () => void;
onDidInitializeMonacoEditor: () => void;
}

export interface ICodeEditor extends React.Component<ICodeEditorProps> {
Expand Down Expand Up @@ -387,6 +388,13 @@ class Workspace extends React.Component<IProps, IState> {
}
}

/**
* Handle any actions after the Monaco editor is initialized.
*/
onDidInitializeMonacoEditor = () => {
this.addModuleDependenciesOnMount();
};

/**
* For non-markup challenges (React, TS), enable the user to
* preview test messages without the tests being run
Expand Down Expand Up @@ -805,6 +813,7 @@ class Workspace extends React.Component<IProps, IState> {
language={this.getMonacoLanguageFromChallengeType()}
value={this.state.code}
onChange={this.handleEditorContentChange}
onDidInitializeMonacoEditor={this.onDidInitializeMonacoEditor}
/>
</CodeEditorContainer>
);
Expand Down Expand Up @@ -1374,12 +1383,12 @@ class Workspace extends React.Component<IProps, IState> {
};

compileAndTransformCodeString = async () => {
const { isTestingAndAutomationChallenge } = this.props;
const { code, dependencies } = await compileCodeString(
this.state.code,
this.props.challenge,
);

const { isTestingAndAutomationChallenge } = this.props;
if (this.editor) {
this.editor.addModuleTypeDefinitionsToMonaco(
dependencies,
Expand All @@ -1390,6 +1399,16 @@ class Workspace extends React.Component<IProps, IState> {
return code;
};

/**
* This method calls the compileAndTransformCodeString method, which has the
* side effect of add relevant type definitions to the Monaco editor based
* on the current challenge code. This avoids the issue where these are not
* present when the challenge first loads.
*/
addModuleDependenciesOnMount = () => {
this.compileAndTransformCodeString();
};

handleCompilationError = (error: Error) => {
debug("[handleCompilationError]", error);
const log = Decode([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class WorkspaceCodemirrorEditor

refresh = async () => {
debug("noop(refresh)");
// Unecessary for the controlled component, but required by the ICodeEditor spec
// Unnecessary for the controlled component, but required by the ICodeEditor spec
// noop
};

Expand Down
3 changes: 3 additions & 0 deletions packages/client/src/components/WorkspaceMonacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ export default class WorkspaceMonacoEditor
}

debug("[initializeMonaco] Monaco editor initialized.");

// Call parent callback to trigger any events on Monaco initialization
this.props.onDidInitializeMonacoEditor();
};

setTheme = (theme: string) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const generateEmptyModule = (): Module => ({
});

const starterTestCode = `// Write your tests here:
test("\`variable\` should be defined", () => {
test("\`variable\` should be defined.", () => {
expect(variable).toBeDefined();
});
`;
Expand Down
Loading