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

Programming exercises: Fix setting language without project type #8399

Merged
merged 2 commits into from
Apr 15, 2024

Conversation

milljoniaer
Copy link
Contributor

@milljoniaer milljoniaer commented Apr 14, 2024

Checklist

General

  • I tested all changes and their related features with all corresponding user types on a test server.
  • This is a small issue that I tested locally and was confirmed by another developer on a test server.
  • I chose a title conforming to the naming conventions for pull requests.

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.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.

Changes affecting Programming Exercises

  • High priority: I tested all changes and their related features with all corresponding user types on a test server configured with the integrated lifecycle setup (LocalVC and LocalCI).
  • I tested all changes and their related features with all corresponding user types on a test server configured with Gitlab and Jenkins.

Motivation and Context

Resolves #8394

Description

The server was adapted to not send an empty array but undefined for non existing project types for programming languages (#8360 ) -> this resulted in a type error in the typescript code.
image

This PR makes projectType typing in ts optional to match server implementation.

Steps for Testing

Prerequisites:

  • 1 Instructor
  1. Log in to Artemis
  2. Create a Python exercise (or some other where no project type can be set)
  3. Verify that it is possible and created correctly (language PYTHON is visible on the detail page)

Testserver States

Note

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







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

  • New Features

    • Enhanced configuration flexibility in programming exercises by making project types and mode options optional.
  • Bug Fixes

    • Updated UI components to handle optional project types and mode options, preventing potential errors.
  • Refactor

    • Improved code robustness by introducing optional chaining in programming exercise management components.
  • Tests

    • Adjusted tests to align with the new optional fields in programming exercise configurations.

@milljoniaer milljoniaer requested a review from a team as a code owner April 14, 2024 11:09
Copy link

coderabbitai bot commented Apr 14, 2024

Walkthrough

The changes primarily involve making certain properties optional in the configuration and components related to programming exercises, enhancing flexibility in handling different programming languages and project types. This includes updates to ensure proper handling of optional fields and adjustments in Angular templates to accommodate these changes.

Changes

Files Changes
.../programming-exercise-creation-config.ts, .../programming-exercise-update.component.ts, .../programming-language-feature.service.ts Made projectTypes, modePickerOptions, and related fields optional. Adjusted related functions and methods to handle optional values.
.../programming-exercise-language.component.html Updated Angular template condition to check for the presence of modePickerOptions.
.../spec/component/programming-exercise/programming-exercise-update.component.spec.ts Removed initialization of projectTypes in test setup.

Assessment against linked issues

Objective Addressed Explanation
Ensure Python programming exercises can be created without a package name (#8394)
Maintain project type consistency across exercise edits, irrespective of course default language (#7481) The changes involve handling optional project types, but it's unclear if they directly address the issue of project type being reset or lost during edits.
Address feedback mechanism extension for programming exercises (#7094) The changes do not include any modifications related to feedback mechanisms or integration with external feedback systems.

Possibly related issues


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6d6173a and 83a9c17.
Files selected for processing (5)
  • src/main/webapp/app/exercises/programming/manage/update/programming-exercise-creation-config.ts (1 hunks)
  • src/main/webapp/app/exercises/programming/manage/update/programming-exercise-update.component.ts (4 hunks)
  • src/main/webapp/app/exercises/programming/manage/update/update-components/programming-exercise-language.component.html (1 hunks)
  • src/main/webapp/app/exercises/programming/shared/service/programming-language-feature/programming-language-feature.service.ts (1 hunks)
  • src/test/javascript/spec/component/programming-exercise/programming-exercise-update.component.spec.ts (1 hunks)
Additional Context Used
Path-based Instructions (5)
src/main/webapp/app/exercises/programming/shared/service/programming-language-feature/programming-language-feature.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

src/main/webapp/app/exercises/programming/manage/update/programming-exercise-creation-config.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/exercises/programming/manage/update/update-components/programming-exercise-language.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/test/javascript/spec/component/programming-exercise/programming-exercise-update.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}}

src/main/webapp/app/exercises/programming/manage/update/programming-exercise-update.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

Additional comments not posted (9)
src/main/webapp/app/exercises/programming/shared/service/programming-language-feature/programming-language-feature.service.ts (1)

16-16: The change to make projectTypes optional in ProgrammingLanguageFeature aligns with the PR's goal to handle languages without project types. This modification should help in cases where a programming language does not use project types, such as Python, ensuring that the system handles such cases gracefully.

src/main/webapp/app/exercises/programming/manage/update/programming-exercise-creation-config.ts (2)

26-26: Making modePickerOptions optional is appropriate given the context where some programming languages might not have associated project types. This change should prevent runtime errors when these properties are not provided.


34-36: The changes to make projectTypes and selectedProjectType optional, and to allow onProjectTypeChange to return undefined, are well-aligned with the PR's objectives to handle languages without project types. These changes enhance the robustness of the system by gracefully handling cases where project types are irrelevant.

src/main/webapp/app/exercises/programming/manage/update/update-components/programming-exercise-language.component.html (1)

26-26: The updated conditional rendering logic correctly checks for the presence of modePickerOptions in addition to other conditions. This is a prudent addition, ensuring that UI elements related to project types are only rendered when applicable, which aligns with the new handling of languages without project types.

src/test/javascript/spec/component/programming-exercise/programming-exercise-update.component.spec.ts (1)

Line range hint 1-1: The removal of the projectTypes field from the ProgrammingLanguageFeature object in the test setup is consistent with the changes in the main codebase where projectTypes is now optional. This change should ensure that the tests remain relevant and reflect the new system behavior accurately.

src/main/webapp/app/exercises/programming/manage/update/programming-exercise-update.component.ts (4)

98-98: Consider initializing selectedProjectTypeValue to undefined explicitly for clarity.

While the TypeScript type system treats uninitialized properties as undefined, explicitly initializing selectedProjectTypeValue to undefined can improve code readability and make the intent clearer.


153-153: Ensure that projectTypes is initialized properly when undefined.

Verification successful

The search for direct indexing usage of projectTypes in the specified directory did not yield any results. This suggests that there are no instances where projectTypes is accessed by index without prior checks, which could lead to null pointer exceptions if it were undefined. However, the initialization of projectTypes as an empty array at its declaration should inherently prevent it from being undefined.

Given this information, it appears that the initialization of projectTypes as an empty array is sufficient to prevent the issues related to being undefined. Therefore, the concern raised in the review comment about ensuring projectTypes is initialized properly when undefined does not apply, as it is already initialized properly.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for any potential null pointer exceptions that might occur if `projectTypes` is used without checking for undefined.
rg --type ts "projectTypes\[\d+\]" src/main/webapp/app/exercises/programming/manage/update/

Length of output: 93


157-157: Consider handling the case where modePickerOptions might be undefined.

To prevent runtime errors in scenarios where modePickerOptions might be undefined, consider adding checks or defaulting to an empty array when accessing its properties or methods.


263-264: Ensure that the default project type is set correctly when changing programming languages.

Verification successful

The verification requires further investigation into how this.projectTypes is populated and the conditions under which the programming language changes to ensure that the default project type set at line 263 aligns with the expected defaults for each programming language. Let's proceed with this verification.


The investigation shows that this.projectTypes is dynamically populated based on the features associated with the selected programming language, and it filters out certain project types not suitable for specific settings. The default project type is set to the first valid entry in this list, which is a reasonable approach given the context. Additionally, changes in the programming language directly affect this list, ensuring that the default project type is aligned with the selected programming language's capabilities.

This confirms that the default project type is set correctly when changing programming languages, as per the expectations outlined in the review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the default project type set here is consistent with the expected defaults for each programming language.
ast-grep --lang typescript --pattern $'this.programmingExercise.projectType = $_'

Length of output: 1357



Script:

#!/bin/bash
# Check how `this.projectTypes` is populated and find conditions affecting programming language changes.
ast-grep --lang typescript --pattern $'this.projectTypes = $_'
ast-grep --lang typescript --pattern $'this.programmingExercise.programmingLanguage = $_'

Length of output: 605


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) labels Apr 14, 2024
coderabbitai[bot]
coderabbitai bot previously requested changes Apr 14, 2024
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

Copy link
Member

@julian-christl julian-christl 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, tested on ts2

Copy link
Contributor

@JohannesWt JohannesWt 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 Test Server 2 --> works as expected

Copy link
Contributor

@rstief rstief 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 also tested on ts2, works as expected.

Copy link
Contributor

@rabeatwork rabeatwork left a comment

Choose a reason for hiding this comment

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

maintainer approve

@julian-christl julian-christl added the maintainer-approved The feature maintainer has approved the PR label Apr 15, 2024
@julian-christl julian-christl added this to the 7.0.1 milestone Apr 15, 2024
Copy link
Contributor

@Strohgelaender Strohgelaender left a comment

Choose a reason for hiding this comment

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

tested locally, works. Also the issue mentioned in Slack (no problem statement for python exercises) got fixed by this PR.

@krusche krusche merged commit 72fa260 into develop Apr 15, 2024
48 of 54 checks passed
@krusche krusche deleted the fix/set-prog-lang-without-project-type branch April 15, 2024 18:22
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 tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Can't setup python programming exercises
7 participants