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

Development: Remove the unused Ace code editor component #8832

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from

Conversation

pzdr7
Copy link
Contributor

@pzdr7 pzdr7 commented Jun 20, 2024

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data.
  • I strictly followed the client coding and design guidelines.

Motivation and Context

The CodeEditorAceComponent was only used in the code editor container if a flag useMonacoEditor was false. However, the flag was true for all instances of the code editor container, rendering it unused.

Description

  • Removed the CodeEditorAceComponent
  • Removed references to it from the code
  • Removed tests

Steps for Testing

Code review

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Test Coverage

No non-trivial changes

Screenshots

No UI changes

Summary by CodeRabbit

  • New Features

    • Transitioned from Ace Editor to Monaco Editor across various code editing components for improved functionality and performance.
  • Bug Fixes

    • Adjusted line highlighting and annotation handling to ensure compatibility with the new Monaco Editor.
  • Refactor

    • Consolidated code editor components to consistently use Monaco Editor, removing conditional checks for Ace Editor.
  • Tests

    • Updated and streamlined test files to reflect the switch from Ace Editor to Monaco Editor, ensuring accurate test coverage and functionality.

@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) labels Jun 20, 2024
@pzdr7 pzdr7 marked this pull request as ready for review June 20, 2024 21:07
@pzdr7 pzdr7 requested a review from a team as a code owner June 20, 2024 21:07
Copy link

coderabbitai bot commented Jun 20, 2024

Walkthrough

The changes involve refactoring the codebase to replace instances of the Ace code editor with the Monaco code editor. This includes updating import statements, modifying HTML components, and adjusting TypeScript logic to remove dependencies on Ace and integrate Monaco instead. This streamlines the editor usage across various components, ensuring consistency and improving maintainability by standardizing on a single code editor framework.

Changes

File(s) Change Summary
src/main/webapp/app/entities/build-log.model.ts, src/main/webapp/app/exercises/programming/shared/code-editor/build-output/code-editor-build-output.component.ts, .../orion/orion-connector.service.ts Update import statements for Annotation to use the Monaco code editor component instead of Ace.
src/main/webapp/app/exam/participate/exercises/programming/programming-exam-submission.component.html, .../code-editor-tutor-assessment-container.component.html Remove the [useMonacoEditor] attribute from various jhi-code-editor-container components in HTML templates.
src/main/webapp/app/exercises/programming/assess/code-editor-tutor-assessment-container.component.ts, .../exercises/programming/shared/code-editor/container/code-editor-container.component.ts Update TypeScript methods and properties to replace Ace editor logic with Monaco editor logic.
src/main/webapp/app/exercises/programming/shared/code-editor/code-editor.module.ts Remove CodeEditorAceComponent from imports and exports in the code editor module.
src/main/webapp/app/exercises/programming/shared/code-editor/container/code-editor-container.component.html Switch from Ace to Monaco for the code editor component, removing conditional logic based on useMonacoEditor.
src/main/webapp/app/exercises/programming/shared/code-editor/monaco/code-editor-monaco.component.html, src/main/webapp/app/shared/markdown-editor/ace-editor/ace-editor.component.ts Remove or adjust class assignments and modify the visibility of constructor parameters respectively, impacting the use of HTML elements and class members.
src/test/javascript/spec/component/code-editor/code-editor-build-output.component.spec.ts, .../helpers/sample/build-logs.ts, .../integration/code-editor/code-editor-container.integration.spec.ts Update test files and integration tests to replace Ace with Monaco editor references, adjusting import paths and modifying test logic accordingly.
src/test/javascript/spec/integration/code-editor/code-editor-instructor.integration.spec.ts, .../integration/code-editor/code-editor-student.integration.spec.ts Remove Ace related imports and dependencies, including brace, and adjust mock components and test setups to focus on Monaco editor. Compare editor state and functionality transitions from Ace to Monaco seamlessly in integration tests.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range comments (40)
src/main/webapp/app/entities/build-log.model.ts (2)

Line range hint 12-12: Replace the any type with a more specific type to enhance type safety and code quality.

- time: any;
+ time: string; // Assuming ISO 8601 format, adjust as necessary

Line range hint 78-80: Address linting issues regarding non-null assertions and global functions.

- feedback.getReferenceLine(suggestion)!
+ feedback.getReferenceLine(suggestion) ?? 0

- parseInt(row, 10)
+ Number.parseInt(row, 10)

- parseInt(column, 10)
+ Number.parseInt(column, 10)

Also applies to: 89-90

src/main/webapp/app/shared/markdown-editor/ace-editor/ace-editor.component.ts (3)

Line range hint 67-67: Replace Infinity with Number.Infinity for consistency with modern JavaScript standards.

- this._editor.$blockScrolling = Infinity;
+ this._editor.$blockScrolling = Number.Infinity;

Line range hint 200-200: Use strict equality === to avoid unexpected type coercion.

- if (text == undefined) {
+ if (text === undefined) {

Line range hint 201-201: Avoid reassigning function parameters as it can lead to confusing bugs. Use a local variable instead.

- setText(text: string) {
+ setText(inputText: string) {
+   let text = inputText;
src/main/webapp/app/exercises/programming/shared/code-editor/build-output/code-editor-build-output.component.ts (5)

Line range hint 35-35: Type any should be avoided as it bypasses TypeScript's type checking. Consider specifying a more precise type for better type safety and code maintainability.

- function theWindow(): any {
+ function theWindow(): Window {

Line range hint 95-95: Avoid using assignments within expressions as they can lead to code that is difficult to read and maintain.

- tap((result) => (this.result = result)),
+ tap((result) => { this.result = result; }),

Apply this change to all similar occurrences in the file.

Also applies to: 144-144, 161-161


Line range hint 97-97: Usage of the non-null assertion operator (!) bypasses TypeScript's nullability checks. It's safer to handle potential nulls explicitly or use optional chaining (?.) if the context allows.

- this.result!.completionDate
+ this.result?.completionDate

Apply this change to all similar occurrences where non-null assertions are used.

Also applies to: 121-121, 123-123, 125-125, 157-157, 161-161, 181-181


Line range hint 207-209: The else clause is unnecessary here as the previous branches return early. Simplifying the control flow improves readability.

- } else {
-     if (!this.resultSubscription && this.participation) {
-         this.setupResultWebsocket();
-     }
- }
+ if (!this.resultSubscription && this.participation) {
+     this.setupResultWebsocket();
+ }

Line range hint 217-217: The usage of any should be avoided. Specifying a more precise type enhances type safety and code clarity.

- function theWindow(): any {
+ function theWindow(): Window {
src/main/webapp/app/shared/monaco-editor/monaco-editor.component.ts (2)

Line range hint 62-62: Type annotations for properties initialized with a boolean or string are inferred by TypeScript and thus redundant.

- private _readOnly: boolean = false;
+ private _readOnly = false;

Apply this change to all similar occurrences.

Also applies to: 226-226


Line range hint 262-262: Prefer template literals over string concatenation for better readability and maintainability.

- 'glyph-margin-hover-button-' + this._editor.getId()
+ `glyph-margin-hover-button-${this._editor.getId()}`
src/main/webapp/app/shared/orion/orion-connector.service.ts (3)

Line range hint 16-16: The use of any should be avoided. Consider providing a more specific type to enhance type safety.

- function theWindow(): any {
+ function theWindow(): Window {

Line range hint 214-214: Avoid using non-null assertions. Consider using optional chaining to safely access properties.

- this.activeAssessmentComponent!.updateFeedback(submissionId, feedbackAsArray);
+ this.activeAssessmentComponent?.updateFeedback(submissionId, feedbackAsArray);

Line range hint 150-150: Avoid using the spread operator in reducers as it can lead to performance issues due to its O(n^2) complexity. Use other methods like .push or direct assignment.

- [fileName]: [...(buildLogErrors[fileName] || []), { ...rest, ts: timestamp }],
+ if (!buildLogErrors[fileName]) {
+     buildLogErrors[fileName] = [];
+ }
+ buildLogErrors[fileName].push({ ...rest, ts: timestamp });
src/test/javascript/spec/component/shared/monaco-editor/monaco-editor.component.spec.ts (1)

Line range hint 96-96: Avoid using non-null assertions. Consider using optional chaining to safely access properties.

- comp.glyphMarginHoverButton!.moveAndUpdate(1);
+ comp.glyphMarginHoverButton?.moveAndUpdate(1);

Apply this change to all similar occurrences where non-null assertions are used.

Also applies to: 190-190, 216-216

src/main/webapp/app/exercises/programming/shared/code-editor/container/code-editor-container.component.ts (2)

Line range hint 198-198: Remove the non-null assertion to adhere to best practices and avoid potential runtime errors.

- this.monacoEditor!.onFileChange(fileChange);
+ this.monacoEditor.onFileChange(fileChange);

Line range hint 254-254: Type of error should be specified instead of using any. Consider defining a type that includes possible error values.

interface ErrorDetails {
  translationKey: string;
  connectionIssue?: string;
}

onError(error: ErrorDetails) {
  // Implementation remains the same
}
src/test/javascript/spec/integration/code-editor/code-editor-student.integration.spec.ts (1)

Line range hint 191-191: The type of error should be specified instead of using any. Consider defining a type that includes possible error values.

interface ErrorDetails {
  message: string;
  code?: number;
}

onError(error: ErrorDetails) {
  // Implementation remains the same
}
src/main/webapp/app/exercises/programming/shared/code-editor/monaco/code-editor-monaco.component.ts (9)

Line range hint 169-169: Use template literals for string concatenation to enhance readability and maintain consistency with modern JavaScript practices.

- this.onError.emit('loadingFailed' + error.message);
+ this.onError.emit(`loadingFailed${error.message}`);

Line range hint 306-306: Replace string concatenation with template literals to align with modern JavaScript standards.

- this.editor.addLineWidget(line + 1, 'feedback-new-' + line, feedbackNode);
+ this.editor.addLineWidget(line + 1, `feedback-new-${line}`, feedbackNode);

Line range hint 323-323: Use template literals for more efficient and readable string concatenation.

- this.editor.addLineWidget(line + 1, 'feedback-' + feedback.id, feedbackNode);
+ this.editor.addLineWidget(line + 1, `feedback-${feedback.id}`, feedbackNode);

Line range hint 339-339: Adopt template literals to improve the readability of string operations.

- throw new Error('No line found for feedback ' + feedback.id);
+ throw new Error(`No line found for feedback ${feedback.id}`);

Line range hint 344-344: Convert string concatenation to template literals for cleaner code.

- this.editor.addLineWidget(line + 1, 'feedback-' + feedback.id, feedbackNode);
+ this.editor.addLineWidget(line + 1, `feedback-${feedback.id}`, feedbackNode);

Line range hint 393-393: Template literals are preferred over concatenation for constructing strings.

- throw new Error('No feedback node found at line ' + line);
+ throw new Error(`No feedback node found at line ${line}`);

Line range hint 405-405: Opt for template literals to simplify string construction in JavaScript.

- const hash = a.fileName + a.row + a.column + a.text;
+ const hash = `${a.fileName}${a.row}${a.column}${a.text}`;

Line range hint 413-413: Use strict equality comparison (===) instead of loose equality (==) to avoid type coercion and potential bugs.

- if (sessionAnnotations[hash] == undefined || sessionAnnotations[hash].timestamp < a.timestamp) {
+ if (sessionAnnotations[hash] === undefined || sessionAnnotations[hash].timestamp < a.timestamp) {

Line range hint 415-417: The else clause is unnecessary here because the if condition already covers all possibilities.

- } else {
-     return sessionAnnotations[hash];
- }
src/test/javascript/spec/component/code-editor/code-editor-monaco.component.spec.ts (4)

Line range hint 86-86: Non-null assertion usage should be avoided for safer code practices.

- expect(element!.hidden).toBeTrue();
+ expect(element?.hidden).toBeTrue();

Line range hint 105-105: Replace non-null assertion with optional chaining for safer code.

- expect(element!.hidden).toBeTrue();
+ expect(element?.hidden).toBeTrue();

Line range hint 116-116: Use optional chaining instead of non-null assertion.

- expect(element!.hidden).toBeFalse();
+ expect(element?.hidden).toBeFalse();

Line range hint 122-126: Avoid using assignments within expressions to reduce confusion and potential bugs.

- comp.ngOnChanges({});
+ const changes = {};
+ comp.ngOnChanges(changes);
src/test/javascript/spec/integration/code-editor/code-editor-instructor.integration.spec.ts (4)

Line range hint 86-86: Replace non-null assertion with optional chaining for safer code.

- expect(container.codeEditorContainer.grid).toBeDefined();
+ expect(container.codeEditorContainer?.grid).toBeDefined();

Line range hint 105-105: Use optional chaining instead of non-null assertion.

- expect(container.codeEditorContainer.fileBrowser).toBeDefined();
+ expect(container.codeEditorContainer?.fileBrowser).toBeDefined();

Line range hint 116-116: Non-null assertion usage should be avoided for safer code practices.

- expect(container.codeEditorContainer.actions).toBeDefined();
+ expect(container.codeEditorContainer?.actions).toBeDefined();

Line range hint 122-126: Avoid using assignments within expressions to reduce confusion and potential bugs.

- expect(container.codeEditorContainer.buildOutput).toBeDefined();
+ const buildOutput = container.codeEditorContainer?.buildOutput;
+ expect(buildOutput).toBeDefined();
src/test/javascript/spec/integration/code-editor/code-editor-container.integration.spec.ts (2)

Line range hint 206-206: Replace the use of any to ensure type safety. Consider specifying a more explicit type or using generics if applicable.

- const someVariable: any = ...;
+ const someVariable: SpecificType = ...;  // Replace SpecificType with the actual type

Line range hint 256-256: Replace non-null assertions with optional chaining to avoid potential runtime errors.

- someObject!.someProperty
+ someObject?.someProperty

Also applies to: 332-332, 442-442, 454-454, 498-498, 510-510

src/main/webapp/app/exercises/programming/assess/code-editor-tutor-assessment-container.component.ts (2)

Line range hint 105-105: Specify explicit types instead of using any.

Consider replacing any with specific types to enhance type safety and code maintainability. TypeScript's type system can help catch many potential runtime errors at compile time.

Also applies to: 106-106, 110-110


Line range hint 140-140: Avoid assignments within expressions to enhance clarity.

- const examId = params['examId'];
+ const examId = Number(params['examId']);
- if (examId) {
+ if (examId !== undefined) {

This change clarifies the intent of the code by separating the assignment from the condition, making the code easier to read and understand.

Also applies to: 141-141, 182-182

Copy link
Contributor

@egekurt123 egekurt123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM

Copy link
Contributor

@sarpsahinalp sarpsahinalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM

Copy link
Contributor

@JohannesStoehr JohannesStoehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Copy link
Contributor

@SimonEntholzer SimonEntholzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) ready for review tests
Projects
Status: Developer Approved
Development

Successfully merging this pull request may close these issues.

None yet

5 participants