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

Communication: Migrate FAQ feature to new client guidelines #9902

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

Conversation

cremertim
Copy link
Contributor

@cremertim cremertim commented Nov 29, 2024

Checklist

General

Client

Motivation and Context

We want to migrate the communication section to the new client guidelines. In particular, this means that all components should become standalone

Description

This PR adresses the FAQ feature and updates it to the new client guidelines by removing constructor injection

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Tutor
  • 1 Course with FAQ enabled
  1. Log in to Artemis
  2. Navigate to Course Management
  3. Create / Propose an FAQ as Instructor/Tutor
  4. Accept the FAQ

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

Manual Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

  • New Features

    • Updated dependency injection method for improved simplicity in the FAQ service and resolver.
  • Bug Fixes

    • No bugs reported or fixed in this release.
  • Documentation

    • Clarified the changes in dependency injection patterns for developers.
  • Refactor

    • Simplified the construction of services using Angular's inject function.

@cremertim cremertim requested a review from a team as a code owner November 29, 2024 09:20
@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Nov 29, 2024
Copy link

coderabbitai bot commented Nov 29, 2024

Walkthrough

The changes in this pull request involve refactoring the dependency injection methods in the FaqResolve and FaqService classes. The constructor-based injection has been replaced with Angular's inject function for both classes, simplifying the dependency management. The core functionality of the methods within these classes remains unchanged, ensuring that the retrieval and handling of FAQ data continue to operate as intended.

Changes

File Path Change Summary
src/main/webapp/app/faq/faq.routes.ts Updated FaqResolve class to use inject(FaqService) instead of constructor for dependency injection.
src/main/webapp/app/faq/faq.service.ts Modified FaqService class to use inject(HttpClient) instead of constructor for dependency injection.

Possibly related PRs

  • Communication: Add FAQs to Artemis #9325: The changes in the FaqService class regarding the use of Angular's inject function for dependency injection are related to the modifications made in the FaqResolve class in the main PR, as both involve updating how services are injected in the FAQ management system.
  • Communication: Only show accepted categories of accepted FAQs #9591: The addition of the findAllCategoriesByCourseIdAndState method in the FaqRepository and the related changes in the FaqService to filter FAQs based on their state are directly connected to the changes in the main PR, which also focuses on the management and retrieval of FAQs.
  • Communication: Reduce FAQ size #9568: The modifications to the FAQ component's HTML structure and styling in this PR are relevant as they aim to enhance the user interface for FAQs, aligning with the main PR's focus on simplifying the FAQ management through code changes in the FaqResolve class.

Suggested labels

communication, ready to merge

Suggested reviewers

  • JohannesStoehr
  • florian-glombik
  • rabeatwork
  • sachmii
  • pzdr7

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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: 0

🧹 Outside diff range and nitpick comments (4)
src/main/webapp/app/faq/faq.routes.ts (2)

Line range hint 1-8: Consider organizing imports by category

While the imports are functional, they could be better organized following Angular's style guide:

  1. Angular imports
  2. Third-party imports
  3. Application imports

Apply this organization:

 import { Injectable, inject } from '@angular/core';
 import { HttpResponse } from '@angular/common/http';
 import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
 import { Observable, of } from 'rxjs';
 import { filter, map } from 'rxjs/operators';
+
 import { FaqService } from 'app/faq/faq.service';
 import { Faq } from 'app/entities/faq.model';

Line range hint 13-24: Consider enhancing error handling and type safety

While the implementation is functional, there are opportunities to improve error handling and type safety:

  1. Add error handling for failed HTTP requests
  2. Handle the non-null assertion more gracefully

Consider this implementation:

     resolve(route: ActivatedRouteSnapshot): Observable<Faq> {
         const faqId = route.params['faqId'];
         const courseId = route.params['courseId'];
         if (faqId) {
             return this.faqService.find(courseId, faqId).pipe(
                 filter((response: HttpResponse<Faq>) => response.ok),
-                map((faq: HttpResponse<Faq>) => faq.body!),
+                map((faq: HttpResponse<Faq>) => {
+                    if (!faq.body) {
+                        throw new Error('FAQ not found');
+                    }
+                    return faq.body;
+                }),
+                catchError(() => {
+                    console.error('Error loading FAQ');
+                    return of(new Faq());
+                }),
             );
         }
         return of(new Faq());
     }
src/main/webapp/app/faq/faq.service.ts (2)

Line range hint 17-24: Consider enhancing error handling in HTTP operations

While the basic error handling through observables is present, consider adding a catchError operator to handle HTTP errors more gracefully and provide better user feedback.

Here's a suggested enhancement:

 create(courseId: number, faq: Faq): Observable<EntityResponseType> {
     const copy = FaqService.convertFaqFromClient(faq);
     return this.http.post<Faq>(`${this.resourceUrl}/${courseId}/faqs`, copy, { observe: 'response' }).pipe(
         map((res: EntityResponseType) => {
             return res;
         }),
+        catchError(error => {
+            console.error('Error creating FAQ:', error);
+            return throwError(() => new Error('Failed to create FAQ'));
+        })
     );
 }

Line range hint 1-150: Consider implementing proper subscription cleanup

To prevent potential memory leaks, consider implementing proper subscription cleanup for components that use this service.

Recommendations:

  1. Document that consumers should use the async pipe where possible
  2. For manual subscriptions, use takeUntil or take(1) operators
  3. Consider adding a note in the service documentation about subscription management

Example usage in components:

export class FaqComponent implements OnDestroy {
  private destroy$ = new Subject<void>();

  ngOnInit() {
    this.faqService.findAllByCourseId(courseId).pipe(
      takeUntil(this.destroy$)
    ).subscribe(faqs => {
      // handle faqs
    });
  }

  ngOnDestroy() {
    this.destroy$.next();
    this.destroy$.complete();
  }
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5f2e030 and e739f40.

📒 Files selected for processing (2)
  • src/main/webapp/app/faq/faq.routes.ts (2 hunks)
  • src/main/webapp/app/faq/faq.service.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/faq/faq.routes.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/faq/faq.service.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

🔇 Additional comments (3)
src/main/webapp/app/faq/faq.routes.ts (1)

11-11: LGTM! Successful migration to new DI pattern

The change from constructor injection to the inject() function aligns with the PR objectives and modern Angular practices.

src/main/webapp/app/faq/faq.service.ts (2)

1-1: LGTM: Import statement is correctly updated

The addition of inject to the Angular core imports is properly implemented.


15-15: LGTM: Dependency injection properly migrated to modern pattern

The migration from constructor injection to Angular's inject function is correctly implemented, following the new client guidelines and Angular best practices.

Let's verify the consistency of this migration pattern across related files:

Copy link
Contributor

@PaRangger PaRangger 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

@sachmii sachmii 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, created FAQ as instructor and proposed FAQ as tutor. Everything works fine.

Copy link

@HawKhiem HawKhiem 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. FAQ proposal and acceptance functionalities work as described

Screenshot 2024-11-29 191106
Screenshot 2024-11-29 191128
Screenshot 2024-11-29 191136

Copy link

@sawys777 sawys777 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. Everything worked as intended.

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
Projects
Status: Work In Progress
Development

Successfully merging this pull request may close these issues.

5 participants