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

Lectures: Disable submit button on invalid form and add tooltip #9846

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

Conversation

laxerhd
Copy link

@laxerhd laxerhd commented Nov 21, 2024

Checklist

General

Server

Client

  • 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 screenshots/screencasts of my UI changes.
  • I translated all newly inserted strings into English and German.

Motivation and Context

Fixes #9829. The submit button did not indicate that a mandatory field was still missing and could be clicked.
This led to confusion among users.
The error message for files that were too large also had an redundant sentence.

Description

I have updated/changed the conditions in isValidForm to recognize empty string names and uploaded files.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Course
  • 1 Lecture
  1. Log in to Artemis
  2. Navigate the Course
  3. Create a new Lecture
  4. Click on Units -> File
  5. Take a look at tooltip and unclickable submit button

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.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) 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

Exam Mode Test

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Test Coverage

Screenshots

image

tooltip-submit-button.mp4

Summary by CodeRabbit

  • New Features

    • Enhanced form validation criteria for improved user experience.
    • Added dynamic tooltip messages for form validation feedback.
    • Introduced new validation error messages for required fields in both English and German.
  • Bug Fixes

    • Removed redundant display of file limitation messages for oversized files.
  • Improvements

    • Improved visibility of validation messages in the attachment unit form.
    • Streamlined the structure of the submit button for better user interaction.

@laxerhd laxerhd requested a review from a team as a code owner November 21, 2024 18:30
@laxerhd laxerhd marked this pull request as draft November 21, 2024 18:30
@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Nov 21, 2024
Copy link

coderabbitai bot commented Nov 21, 2024

Walkthrough

The changes in this pull request focus on the attachment-unit-form.component within an Angular application. The HTML template has been modified to improve the user interface by removing unnecessary spaces and enhancing the tooltip logic for the submit button. The TypeScript component has updated validation logic to ensure that the form is only valid when specific conditions are met, including checks for file size and the presence of a name. Additionally, new validation error messages have been added for localization to improve user feedback during form submission.

Changes

File Change Summary
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html Adjusted label for "name" input, modified submit button structure for tooltip logic, updated error handling for file input.
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts Updated isFormValid logic to include stricter validation checks; modified onFileChange method for name setting; added tooltipText getter for validation messages.
src/main/webapp/i18n/de/lectureUnit.json Added new validation error message for required name and file upload.
src/main/webapp/i18n/en/lectureUnit.json Added new validation error message for required name and file upload.

Assessment against linked issues

Objective Addressed Explanation
Disable submit button if no file is uploaded (Issue #9829)
Display tooltip indicating file upload requirement (Issue #9829)

Possibly related PRs

Suggested labels

tests, bugfix, user interface, small, code quality

Suggested reviewers

  • JohannesStoehr
  • florian-glombik
  • az108
  • BBesrour
  • HawKhiem
  • magaupp

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8c9741c and d3c7a32.

📒 Files selected for processing (1)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts

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/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (3)

71-71: Improve type safety and readability of the validation check.

While the stricter validation aligns with the PR objectives, the string comparison can be improved.

Consider this more idiomatic approach:

-        return this.statusChanges() === 'VALID' && !this.isFileTooBig() && this.nameControl?.value != '' && this.fileName();
+        return this.statusChanges() === 'VALID' && !this.isFileTooBig() && Boolean(this.nameControl?.value?.trim()) && Boolean(this.fileName());

This change:

  • Uses trim() to handle whitespace-only values
  • Uses Boolean() for explicit type conversion
  • Maintains null-safety with the optional chaining

Line range hint 82-95: Add file type validation and error handling.

The file change handler should validate the file type against the accepted extensions.

Consider adding these validations:

     onFileChange(event: Event): void {
         const input = event.target as HTMLInputElement;
         if (!input.files?.length) {
             return;
         }
         this.file = input.files[0];
+        const fileExtension = this.file.name.split('.').pop()?.toLowerCase();
+        if (!fileExtension || !ACCEPTED_FILE_EXTENSIONS_FILE_BROWSER.includes(`.${fileExtension}`)) {
+            // Reset the input
+            input.value = '';
+            this.file = undefined;
+            this.fileName.set(undefined);
+            return;
+        }
         this.fileName.set(this.file.name);
         // automatically set the name in case it is not yet specified
         if (this.form && (this.nameControl?.value == undefined || this.nameControl?.value == '')) {
             this.form.patchValue({
                 // without extension
                 name: this.file.name.replace(/\.[^/.]+$/, ''),
             });
         }
         this.isFileTooBig.set(this.file.size > MAX_FILE_SIZE);
     }

Line range hint 38-40: Enhance component with accessibility and cleanup.

Consider these improvements for better maintainability and accessibility:

  1. Implement OnDestroy to clean up subscriptions:
export class AttachmentUnitFormComponent implements OnChanges, OnDestroy {
    private destroy$ = new Subject<void>();

    ngOnDestroy(): void {
        this.destroy$.next();
        this.destroy$.complete();
    }
}
  1. Add ARIA attributes to the file input in the template:
<input
    #fileInput
    type="file"
    [attr.aria-label]="'attachment.fileInput' | translate"
    [attr.aria-invalid]="isFileTooBig()"
    [attr.aria-describedby]="isFileTooBig() ? 'file-size-error' : undefined"
/>
  1. Consider extracting error messages to translation files for better i18n support.
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html (1)

108-130: Consider simplifying the tooltip logic.

The implementation successfully meets the PR objectives by disabling the submit button and showing appropriate tooltips. However, the tooltip logic could be improved:

  1. Consider moving the tooltip condition to the component:
get tooltipText(): string | null {
  if (!this.fileInputTouched && this.nameControl?.invalid) {
    return this.translateService.instant('artemisApp.attachmentUnit.createAttachmentUnit.nameRequiredValidationError') + 
           ' ' +
           this.translateService.instant('artemisApp.attachmentUnit.createAttachmentUnit.fileRequiredValidationError');
  }
  if (!this.fileInputTouched) {
    return this.translateService.instant('artemisApp.attachmentUnit.createAttachmentUnit.fileRequiredValidationError');
  }
  if (this.nameControl?.invalid) {
    return this.translateService.instant('artemisApp.attachmentUnit.createAttachmentUnit.nameRequiredValidationError');
  }
  return null;
}
  1. Consider using ng-container instead of span to avoid extra DOM elements.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 31bd52c and 42ab4d0.

📒 Files selected for processing (2)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html (2 hunks)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.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

📓 Learnings (1)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (1)
Learnt from: florian-glombik
PR: ls1intum/Artemis#9656
File: src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts:69-71
Timestamp: 2024-11-12T12:52:03.805Z
Learning: In the `src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts`, the `isFormValid` computed property intentionally uses a logical OR between `this.statusChanges() === 'VALID'` and `this.fileName()` to mirror the original `isSubmitPossible` getter, ensuring consistent form validation behavior.
🔇 Additional comments (2)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html (2)

5-5: LGTM! Clean formatting of the required field indicator.

The removal of extra space before the asterisk improves visual consistency while maintaining the required field indication.


111-113: Verify tooltip text concatenation.

The current implementation uses string concatenation with spaces which could be fragile if translations contain trailing/leading spaces.

✅ Verification successful

String concatenation for validation messages is safe

After examining the translation files, the current implementation is safe. The translation strings for both German and English do not contain any leading or trailing spaces:

  • "nameRequiredValidationError": "Name is required."
  • "fileRequiredValidationError": "You must select a file to upload."

The explicit space concatenation in the template ensures consistent spacing between the messages, making the implementation robust and maintainable.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential spacing issues in translations
rg -g '*.json' '"artemisApp\.attachmentUnit\.createAttachmentUnit\.(nameRequiredValidationError|fileRequiredValidationError)"\s*:\s*"[^"]*(\s+$|^\s+)'

Length of output: 152


Script:

#!/bin/bash
# Let's first find the translation files and check the actual content of these specific keys
fd -e json | xargs rg -l "artemisApp.attachmentUnit.createAttachmentUnit"

# Then let's examine the actual translation strings for these specific validation messages
fd -e json | xargs rg "nameRequiredValidationError|fileRequiredValidationError"

Length of output: 2275

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 21, 2024
@laxerhd laxerhd changed the title Disable submit button on invalid form and add tooltip to it Lectures: Disable submit button on invalid form and add tooltip to it Nov 21, 2024
@laxerhd
Copy link
Author

laxerhd commented Nov 21, 2024

Could someone please give me some pointers on the tooltip. Should I move the “logic” to the component file as CodeRabbit suggested? Do you think it is necessary to add a new text for the combined tooltip?

@laxerhd laxerhd changed the title Lectures: Disable submit button on invalid form and add tooltip to it Lectures: Disable submit button on invalid form and add tooltip Nov 21, 2024
@laxerhd laxerhd closed this Nov 24, 2024
@laxerhd laxerhd deleted the bugfix/lectures/disable-submit-button-on-invalid-form-add-tooltip branch November 24, 2024 14:47
@laxerhd laxerhd restored the bugfix/lectures/disable-submit-button-on-invalid-form-add-tooltip branch November 24, 2024 14:48
@laxerhd laxerhd reopened this Nov 24, 2024
…ton-on-invalid-form

Bugfix/lectures/disable submit button on invalid form
@laxerhd
Copy link
Author

laxerhd commented Nov 24, 2024

Sorry for the confusion, tried to rename the branch and thus some complications happend...

@laxerhd laxerhd marked this pull request as ready for review November 24, 2024 14:58
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

🧹 Outside diff range and nitpick comments (2)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (2)

73-73: Enhance form validation robustness

While the validation logic is comprehensive, consider these improvements:

  1. Use strict comparison (!==) instead of loose comparison (!=) for empty string check
  2. Optimize condition order for better short-circuiting by checking simpler conditions first
-return this.statusChanges() === 'VALID' && !this.isFileTooBig() && this.nameControl?.value != '' && this.fileName();
+return this.nameControl?.value !== '' && this.fileName() && !this.isFileTooBig() && this.statusChanges() === 'VALID';

Line range hint 87-93: Improve file name handling robustness

Consider these improvements to the file name handling:

  1. Use strict comparison (===) for undefined check
  2. Extract the file name extraction logic into a separate method
  3. Add a comment explaining the auto-naming behavior
-if (this.form && (this.nameControl?.value == undefined || this.nameControl?.value == '')) {
+// Auto-set the name from file name if not explicitly provided by user
+if (this.form && (this.nameControl?.value === undefined || this.nameControl?.value === '')) {
+    const fileNameWithoutExtension = this.extractFileNameWithoutExtension(this.file.name);
     this.form.patchValue({
-        // without extension
-        name: this.file.name.replace(/\.[^/.]+$/, ''),
+        name: fileNameWithoutExtension,
     });
 }

+private extractFileNameWithoutExtension(fileName: string): string {
+    return fileName.replace(/\.[^/.]+$/, '');
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 42ab4d0 and 8e3133e.

📒 Files selected for processing (2)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html (2 hunks)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.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

📓 Learnings (1)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (1)
Learnt from: florian-glombik
PR: ls1intum/Artemis#9656
File: src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts:69-71
Timestamp: 2024-11-12T12:52:03.805Z
Learning: In the `src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts`, the `isFormValid` computed property intentionally uses a logical OR between `this.statusChanges() === 'VALID'` and `this.fileName()` to mirror the original `isSubmitPossible` getter, ensuring consistent form validation behavior.
🔇 Additional comments (2)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (2)

9-9: LGTM: TranslateService import added for internationalization support

The import is correctly placed and follows Angular style guidelines.


72-73: Verify implementation against PR objectives

The changes successfully implement the PR objectives:

  1. The submit button is properly disabled when no file is uploaded through the enhanced isFormValid computed property
  2. Clear tooltip messages are provided through the new tooltipText getter

Also applies to: 99-114

✅ Verification successful

Let me gather the template file to verify the implementation.


Implementation correctly matches PR objectives

The code inspection confirms that:

  1. The submit button is properly disabled through [disabled]="!isFormValid()" binding, which includes file validation
  2. The tooltip is correctly implemented using [ngbTooltip]="tooltipText" with appropriate validation messages
  3. The form validation logic in isFormValid computed property matches the template's requirements
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that the component template uses these properties correctly
rg -l 'attachment-unit-form\.component\.html' | xargs cat

Length of output: 6051


Script:

#!/bin/bash
# Find and show the template file content
fd -e html attachment-unit-form.component.html -x cat {}

Length of output: 6913

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/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (3)

73-73: Verify the stricter form validation logic

The validation has been enhanced to ensure both name and file are provided before enabling submission. However, the empty string check nameControl?.value != '' should use strict equality for consistency with TypeScript best practices.

-        return this.statusChanges() === 'VALID' && !this.isFileTooBig() && this.nameControl?.value != '' && this.fileName();
+        return this.statusChanges() === 'VALID' && !this.isFileTooBig() && this.nameControl?.value !== '' && this.fileName();

99-113: Consider adding type safety for translation keys

The tooltip implementation looks good with clear conditions and i18n support. However, consider using TypeScript's string literal types to ensure type safety for translation keys.

// Add at the top of the file
type TranslationKey =
  | 'artemisApp.attachmentUnit.createAttachmentUnit.nameAndFileRequiredValidationError'
  | 'artemisApp.attachmentUnit.createAttachmentUnit.fileRequiredValidationError'
  | 'artemisApp.attachmentUnit.createAttachmentUnit.nameRequiredValidationError';

// Then update the getter
get tooltipText(): string | null {
    const translate = (key: TranslationKey) => this.translateService.instant(key);
    // Rest of the implementation remains the same
}

Line range hint 82-92: Improve file handling robustness

The file handling logic could be improved in several ways:

  1. Use strict equality checks
  2. Extract the file extension regex to a constant
  3. Add null check for form before accessing nameControl
     if (!input.files?.length) {
         return;
     }
     this.file = input.files[0];
     this.fileName.set(this.file.name);
     // automatically set the name in case it is not yet specified
-    if (this.form && (this.nameControl?.value == undefined || this.nameControl?.value == '')) {
+    const FILE_EXTENSION_REGEX = /\.[^/.]+$/;
+    if (this.form && this.nameControl && (this.nameControl.value === undefined || this.nameControl.value === '')) {
         this.form.patchValue({
             // without extension
-            name: this.file.name.replace(/\.[^/.]+$/, ''),
+            name: this.file.name.replace(FILE_EXTENSION_REGEX, ''),
         });
     }
src/main/webapp/i18n/de/lectureUnit.json (1)

176-176: Consider splitting the combined validation message

The translation follows the informal style guide correctly using "Du" form. However, combining two validation messages ("name required" and "file required") into one key might reduce maintainability and reusability.

Consider splitting into separate keys for better maintainability:

-"nameAndFileRequiredValidationError": "Der Name ist ein Pflichtfeld. Du musst eine Datei zum Uploaden auswählen.",
+"nameRequiredValidationError": "Der Name ist ein Pflichtfeld.",
+"fileRequiredValidationError": "Du musst eine Datei zum Uploaden auswählen."

This approach would:

  1. Allow reusing individual messages elsewhere
  2. Make it easier to maintain translations
  3. Follow the single responsibility principle
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8e3133e and 8c9741c.

📒 Files selected for processing (3)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (4 hunks)
  • src/main/webapp/i18n/de/lectureUnit.json (1 hunks)
  • src/main/webapp/i18n/en/lectureUnit.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.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/i18n/de/lectureUnit.json (1)

Pattern src/main/webapp/i18n/de/**/*.json: German language translations should be informal (dutzen) and should never be formal (sietzen). So the user should always be addressed with "du/dein" and never with "sie/ihr".

📓 Learnings (1)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (1)
Learnt from: florian-glombik
PR: ls1intum/Artemis#9656
File: src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts:69-71
Timestamp: 2024-11-12T12:52:03.805Z
Learning: In the `src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts`, the `isFormValid` computed property intentionally uses a logical OR between `this.statusChanges() === 'VALID'` and `this.fileName()` to mirror the original `isSubmitPossible` getter, ensuring consistent form validation behavior.
🔇 Additional comments (3)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.ts (2)

9-9: LGTM: TranslateService import added for i18n support

The import is correctly placed and follows Angular style guidelines.


Line range hint 1-166: Verify component structure and memory management

The component follows Angular best practices with:

  • Proper use of signals and computed properties
  • Clear separation of concerns
  • Type safety throughout the component
  • Memory leak prevention through proper cleanup

However, consider adding:

  1. Unit tests for the new validation and tooltip logic
  2. Error handling for file operations
src/main/webapp/i18n/en/lectureUnit.json (1)

176-176: LGTM! Please verify German translation.

The new validation message effectively combines the name and file requirements, providing clear user feedback. This aligns well with the PR objective to improve the file upload dialog experience.

Let's verify the German translation exists:

✅ Verification successful

German translation is present and accurate ✓

The German translation for the new validation message exists and correctly conveys the same meaning as the English version, combining both the name requirement ("Der Name ist ein Pflichtfeld") and file upload requirement ("Du musst eine Datei zum Uploaden auswählen").

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the German translation for the new validation message exists
rg "nameAndFileRequiredValidationError" "src/main/webapp/i18n/de/lectureUnit.json"

Length of output: 211

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 24, 2024
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

Comment on lines +99 to +113
get tooltipText(): string | null {
// Both name and file are invalid
if (!this.fileInputTouched && this.nameControl?.invalid) {
return this.translateService.instant('artemisApp.attachmentUnit.createAttachmentUnit.nameAndFileRequiredValidationError');
}
// Only file is invalid
if (!this.fileInputTouched) {
return this.translateService.instant('artemisApp.attachmentUnit.createAttachmentUnit.fileRequiredValidationError');
}
// Only name is invalid
if (this.nameControl?.invalid) {
return this.translateService.instant('artemisApp.attachmentUnit.createAttachmentUnit.nameRequiredValidationError');
}
return null;
}
Copy link
Contributor

@florian-glombik florian-glombik Nov 28, 2024

Choose a reason for hiding this comment

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

This approach will have a bad performance as the getter will be updated with each cycle - you can add a console.log in there to see that you will have thousands of logs just by moving your mouse within the view.

While working on another PR (#9655) I am introducing signals for the validation, you might want to stack this PR as you can then re-use the signals and instead of a getter use a computed property which is much more efficient regarding the performance.

(I will link the other PR once I have pushed the branch to remote and created it)
Here is the PR with the signal changes, on which you might want to stack these changes Lectures: Improve and refactor lecture attachment validation #9893

Copy link
Contributor

Choose a reason for hiding this comment

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

You might also want to revise the client guidelines https://docs.artemis.cit.tum.de/dev/guidelines/client#null-and-undefined

Copy link
Author

Choose a reason for hiding this comment

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

Thank you so much for the detailed feedback! I really appreciate it.
I'll wait until your PR is merged and then revise the code here.
I will also make sure I follow the guidelines 👍
I guess null and undefined might be mistakes often made by new contributors. Is there perhaps a Coderabbit policy that could be added so that it warns when used?

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: Ready For Review
Development

Successfully merging this pull request may close these issues.

Lectures: Disable submit button in file upload dialog if no file is uploaded yet
8 participants