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

Learning path: Add discussion section to lecture unit and exercises #9264

Merged
merged 21 commits into from
Sep 6, 2024

Conversation

JohannesWt
Copy link
Contributor

@JohannesWt JohannesWt commented Sep 1, 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 (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding and design guidelines.
  • Following the theming guidelines, I specified colors only in the theming variable files and checked that the changes look consistent in both the light and the dark theme.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.
  • I documented the TypeScript code using JSDoc style.
  • I added multiple screenshots/screencasts of my UI changes.

Motivation and Context

This PR adds the discussion section to lecture units and exercises in the student's learning path view.

Description

The discussion section (communication feature) is now displayed alongside lecture units and exercises in the student's learning path view. Instead of the router-based approach previously used in the course details view, the discussion section component is now integrated directly to simplify the implementation.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Students
  • at least 1 competency
  • 1 Lecture Unit connected to a competency
  • 1 Exercise connected to a competency
  1. Log in to Artemis
  2. enable the communication feature for the specified course (if not all ready enabled)
  3. Navigate the learning path student view
  4. verify that the discussion section is shown for lecture units (for the specific lecture) as well as for exercises (for the specific exercise)
  5. verify that the discussion sections in the student of of lectures and exercises still work as expected

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

Performance Review

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Class/File Line Coverage Confirmation (assert/expect)
learning-path-lecture-unit.component.ts 97.05%
learning-path-lecture-unit-view.component.ts 91.66%
course-lecture-details.component.ts 98.61%
discussion-section.component.ts 94.69%
course-exercise-details.component.ts 90.29%

Screenshots

image image

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced layout and functionality for lecture units, allowing for discussion features based on communication settings.
    • Improved user interaction by integrating discussion capabilities within lecture units.
  • Refactor

    • Streamlined component interactions and dependencies, particularly regarding discussion functionalities.
    • Transitioned the discussion section component to a standalone entity, enhancing modularity.
  • Tests

    • Improved test suite for the discussion section, optimizing setup and enhancing clarity.
    • Added new test cases to validate the visibility of discussion sections based on communication settings.
    • Updated tests for the CourseExerciseDetailsComponent to reflect changes in component dependencies and communication settings.

@JohannesWt JohannesWt self-assigned this Sep 1, 2024
@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) labels Sep 1, 2024
@JohannesWt JohannesWt marked this pull request as ready for review September 2, 2024 18:15
@JohannesWt JohannesWt requested a review from a team as a code owner September 2, 2024 18:15
Copy link

coderabbitai bot commented Sep 2, 2024

Walkthrough

The changes involve restructuring components related to lecture units, discussion sections, and course exercise details in an Angular application. Key modifications include introducing computed properties for managing communication settings, enhancing the DiscussionSectionComponent to function as a standalone entity, and updating test suites for improved reliability and clarity. Additionally, the CourseExerciseDetailsComponent has been modified to focus on course communication settings, reflecting a shift in functionality.

Changes

Files Change Summary
src/main/webapp/app/course/learning-paths/components/...html Restructured HTML layout for lecture units, added conditional rendering for discussion section based on communication settings.
src/main/webapp/app/course/learning-paths/components/...ts Introduced computed properties for communication settings, updated imports, and added logic to streamline access to lecture details.
src/test/javascript/spec/component/learning-paths/components/...spec.ts Enhanced tests for lecture unit components, focusing on conditional rendering of discussion sections based on communication settings.
src/main/webapp/app/overview/discussion-section/...component.ts Declared DiscussionSectionComponent as a standalone entity, updated input handling to reactive inputs, and removed dependency on MetisConversationService.
src/test/javascript/spec/component/overview/discussion-section/...spec.ts Streamlined test setup, improved component initialization, and focused on essential dependencies for testing DiscussionSectionComponent.
src/test/javascript/spec/component/learning-paths/participate/...spec.ts Removed unused import of DiscussionSectionComponent and eliminated a test case related to child component activation, reflecting a shift in component dependencies.
src/main/webapp/app/overview/exercise-details/...component.ts Removed discussion-related properties and methods from CourseExerciseDetailsComponent, indicating a shift in functionality.
src/test/javascript/spec/component/overview/exercise-details/...spec.ts Updated test suite to reflect changes in component structure, introduced new tests for discussion section visibility based on course communication settings.

Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 99e4e91 and 26b0038.

Files selected for processing (1)
  • src/test/javascript/spec/component/learning-paths/components/learning-path-lecture-unit.component.spec.ts (5 hunks)
Additional context used
Path-based instructions (1)
src/test/javascript/spec/component/learning-paths/components/learning-path-lecture-unit.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

Biome
src/test/javascript/spec/component/learning-paths/components/learning-path-lecture-unit.component.spec.ts

[error] 138-138: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (3)
src/test/javascript/spec/component/learning-paths/components/learning-path-lecture-unit.component.spec.ts (3)

20-22: Review of new imports for testing setup.

The new imports for CourseInformationSharingConfiguration, DiscussionSectionComponent, and MockComponent are appropriate for the testing context. These imports are necessary for the new functionality being tested, which involves conditional rendering of the discussion section based on course communication settings.


Line range hint 54-87: Good isolation and setup for component testing.

The test configuration effectively isolates the LearningPathLectureUnitComponent by using MockComponent for the DiscussionSectionComponent. This setup ensures that the tests are focused on the component's behavior in response to different communication settings without interference from the actual implementation of the discussion section.


162-183: Existing comments on test cases for discussion section visibility are still valid.

The suggestions made in the existing comments for improving the test cases by using more specific expectations and checking component properties are still applicable. No further comments are necessary at this time.


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

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: 8

Outside diff range comments (4)
src/main/webapp/app/overview/exercise-details/course-exercise-details.module.ts (1)

Line range hint 1-78: Overall module structure review.

The module structure adheres to Angular style guidelines. However, there are a few suggestions for improvement:

  1. Consider grouping related imports together (e.g., Angular core imports, shared modules, feature modules).
  2. The imports array in the @NgModule decorator is quite long. Consider breaking it into logical groups with comments for better readability.
  3. Use consistent naming conventions for modules. Some modules use the "Artemis" prefix while others don't. Consider standardizing this across the project.

Example of grouped imports:

// Angular core imports
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

// Shared modules
import { ArtemisSharedModule } from 'app/shared/shared.module';
import { ArtemisSidePanelModule } from 'app/shared/side-panel/side-panel.module';
// ... other shared modules ...

// Feature modules
import { ArtemisProgrammingExerciseInstructionsRenderModule } from 'app/exercises/programming/shared/instructions-render/programming-exercise-instructions-render.module';
// ... other feature modules ...

// Components
import { CourseExerciseDetailsComponent } from 'app/overview/exercise-details/course-exercise-details.component';
// ... other component imports ...
src/main/webapp/app/overview/course-lectures/course-lecture-details.component.ts (3)

Line range hint 30-138: Consider implementing lazy loading for LectureUnit components.

To improve performance, especially for courses with many lecture units, consider implementing lazy loading for the LectureUnit components.

You can use Angular's built-in lazy loading feature to load LectureUnit components on demand. This can be achieved by creating a separate module for each LectureUnit type and using the loadChildren property in the routing configuration.


Line range hint 67-138: Enhance error handling and user feedback.

The current error handling in the loadData method could be improved to provide more specific feedback to the user.

Consider implementing a custom error handling service that can provide more detailed error messages based on the type of error encountered. For example:

private handleError(error: HttpErrorResponse): void {
    let errorMessage = 'An error occurred while loading the lecture data.';
    if (error.status === 404) {
        errorMessage = 'The requested lecture could not be found.';
    } else if (error.status === 403) {
        errorMessage = 'You do not have permission to access this lecture.';
    }
    this.alertService.error(errorMessage);
}

Then, update the error handling in the loadData method:

error: (errorResponse: HttpErrorResponse) => this.handleError(errorResponse),
Tools
Biome

[error] 105-105: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)


Line range hint 1-138: Consider implementing caching for lecture data.

To improve performance and reduce server load, consider implementing a caching mechanism for lecture data.

You can use Angular's HttpInterceptor to implement a caching strategy for GET requests to the lecture endpoint. This would allow you to serve cached data when available and only fetch from the server when necessary.

Here's a basic example of how you might implement this:

import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { tap } from 'rxjs/operators';

@Injectable()
export class CachingInterceptor implements HttpInterceptor {
    private cache = new Map<string, HttpResponse<any>>();

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        if (req.method !== 'GET') {
            return next.handle(req);
        }

        const cachedResponse = this.cache.get(req.url);
        if (cachedResponse) {
            return of(cachedResponse.clone());
        }

        return next.handle(req).pipe(
            tap(event => {
                if (event instanceof HttpResponse) {
                    this.cache.set(req.url, event.clone());
                }
            })
        );
    }
}

Remember to clear the cache when appropriate, such as when a user logs out or when lecture data is updated.

Copy link
Contributor

@pzdr7 pzdr7 left a comment

Choose a reason for hiding this comment

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

Code looks good 👍 I think getting rid of the outlet makes sense

I found one possible simplification & have one more optional comment

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: 2

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: 1

Jan-Thurner
Jan-Thurner previously approved these changes Sep 5, 2024
Copy link
Contributor

@Jan-Thurner Jan-Thurner left a comment

Choose a reason for hiding this comment

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

reapprove after additional test were added

…earning-path-lecture-unit.component.spec.ts

Co-authored-by: Patrik Zander <[email protected]>
…earning-path-lecture-unit.component.spec.ts

Co-authored-by: Patrik Zander <[email protected]>
Copy link
Contributor

@az108 az108 left a comment

Choose a reason for hiding this comment

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

Added tests and rest of the changes to the code look good to me, reapproval

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: 1

it('should set current learning object completion', async () => {
const completeLectureUnitSpy = jest
.spyOn(lectureUnitService, 'completeLectureUnit')
.mockImplementationOnce((lecture: Lecture, completionEvent: LectureUnitCompletionEvent) => (completionEvent.lectureUnit.completed = completionEvent.completed));
Copy link

Choose a reason for hiding this comment

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

Refactor assignment within expression.

The assignment within the expression in the mock implementation of completeLectureUnit can lead to confusion. It's generally a good practice to separate side effects from expressions to improve code clarity and maintainability.

Consider refactoring the mock implementation as follows:

.mockImplementationOnce((lecture: Lecture, completionEvent: LectureUnitCompletionEvent) => {
    completionEvent.lectureUnit.completed = completionEvent.completed;
    return completionEvent;
});
Tools
Biome

[error] 138-138: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Copy link
Contributor

@N0W0RK N0W0RK left a comment

Choose a reason for hiding this comment

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

Tested on TS3 lectures aswell as exercises show communication in Learning path view

Copy link
Contributor

@florian-glombik florian-glombik left a comment

Choose a reason for hiding this comment

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

Re-approve

Copy link
Contributor

@MaximilianAnzinger MaximilianAnzinger left a comment

Choose a reason for hiding this comment

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

Maintainer approved

@bassner bassner added ready to merge maintainer-approved The feature maintainer has approved the PR and removed ready for review labels Sep 6, 2024
@bassner bassner merged commit a67ce95 into develop Sep 6, 2024
47 of 51 checks passed
@bassner bassner deleted the feature/learning-paths/add-discussion-section branch September 6, 2024 10:37
@bassner bassner added this to the 7.5.2 milestone Sep 6, 2024
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!) maintainer-approved The feature maintainer has approved the PR ready to merge small tests
Projects
Archived in project
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants