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

feat: add possibility to specify customized bonus points logic for live quizzes #4262

Merged
merged 13 commits into from
Sep 17, 2024

Conversation

sjschlapbach
Copy link
Member

@sjschlapbach sjschlapbach commented Sep 17, 2024

Screenshot 2024-09-17 at 15 18 09 Screenshot 2024-09-17 at 13 15 42

Copy link

aviator-app bot commented Sep 17, 2024

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged manually (without Aviator). Merging manually can negatively impact the performance of the queue. Consider using Aviator next time.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

Copy link

coderabbitai bot commented Sep 17, 2024

Warning

Rate limit exceeded

@sjschlapbach has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 52 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between de1c1fd and 370572f.

Walkthrough

Walkthrough

The changes introduce a new modal component for configuring advanced settings in live quizzes, allowing users to specify maximum bonus points and time to zero bonus. Localization strings in both German and English are added to support these new settings, including tooltips and validation messages. The updates enhance the user interface and improve the overall functionality of the live quiz feature, ensuring that users can interact with these settings effectively.

Changes

Files Change Summary
apps/frontend-manage/src/components/sessions/creation/liveQuiz/AdvancedLiveQuizSettings.tsx Introduced AdvancedLiveQuizSettings modal for configuring advanced quiz settings, including UI components for input handling and a dynamic chart for visualizing points.
packages/i18n/messages/de.ts Introduced new localization strings for advanced settings related to live quizzes in German.
packages/i18n/messages/en.ts Added new string constants for advanced settings related to live quizzes in English.

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 generate interesting stats about this repository and render them as a table.
    -- @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 anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.
Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI o1 for code reviews: OpenAI's new o1 model is being tested for generating code suggestions in code reviews.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Copy link

cypress bot commented Sep 17, 2024

klicker-uzh    Run #2982

Run Properties:  status check failed Failed #2982  •  git commit aa95c06cc7 ℹ️: Merge 370572f66e2e9bcea8f29ae4c233e16390c7c04c into 5e0be7e1a02d8d4b0ff4c26ec420...
Project klicker-uzh
Branch Review modular-bonus-points
Run status status check failed Failed #2982
Run duration 09m 09s
Commit git commit aa95c06cc7 ℹ️: Merge 370572f66e2e9bcea8f29ae4c233e16390c7c04c into 5e0be7e1a02d8d4b0ff4c26ec420...
Committer Julius Schlapbach
View all properties for this run ↗︎

Test results
Tests that failed  Failures 1
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 42
View all changes introduced in this branch ↗︎

Tests for review

Failed  cypress/e2e/E-course-workflow.cy.ts • 1 failed test

View Output

Test Artifacts
Test course creation and editing functionalities > Test the assignment of random groups in the seeded test course Test Replay Screenshots
Flakiness  cypress/e2e/G-microlearning-workflow.cy.ts • 1 flaky test

View Output

Test Artifacts
Different microlearning workflows > converts a seeded past microlearning into a practice quiz Test Replay Screenshots

@sjschlapbach sjschlapbach marked this pull request as ready for review September 17, 2024 12:00
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: 26

Outside diff range and nitpick comments (9)
apps/frontend-manage/src/components/sessions/creation/liveQuiz/submitLiveSessionForm.tsx (1)

48-49: Simplify the parsing of numeric values

The use of parseInt(String(values.maxBonusPoints)) and parseInt(String(values.timeToZeroBonus)) can be simplified. Wrapping the values with String() is unnecessary because parseInt can handle both strings and numbers.

Consider updating the code as follows:

-maxBonusPoints: parseInt(String(values.maxBonusPoints)),
-timeToZeroBonus: parseInt(String(values.timeToZeroBonus)),
+maxBonusPoints: parseInt(values.maxBonusPoints),
+timeToZeroBonus: parseInt(values.timeToZeroBonus),

Additionally, it's recommended to specify the radix parameter in parseInt to avoid unexpected results due to leading zeros.

-maxBonusPoints: parseInt(values.maxBonusPoints),
-timeToZeroBonus: parseInt(values.timeToZeroBonus),
+maxBonusPoints: parseInt(values.maxBonusPoints, 10),
+timeToZeroBonus: parseInt(values.timeToZeroBonus, 10),

Also applies to: 82-83

apps/frontend-manage/src/components/sessions/creation/liveQuiz/LiveSessionWizard.tsx (1)

12-15: Use Consistent Import Paths

Consider using absolute import paths for consistency and readability, as other imports in this file use absolute paths.

Apply this diff to adjust the import:

-import {
-  LQ_MAX_BONUS_POINTS,
-  LQ_TIME_TO_ZERO_BONUS,
-} from '@klicker-uzh/shared-components/src/constants'
+import { LQ_MAX_BONUS_POINTS, LQ_TIME_TO_ZERO_BONUS } from '@klicker-uzh/shared-components/src/constants'
packages/shared-components/src/constants.ts (1)

5-8: Consider adding explicit type annotations for consistency

To maintain consistency with the existing codebase, consider adding explicit type annotations to the new constants.

Apply this diff to add explicit type annotations:

-export const LQ_MAX_BONUS_POINTS = 45 // live quiz: maximum 45 bonus points for fastest answer
+export const LQ_MAX_BONUS_POINTS: number = 45 // live quiz: maximum 45 bonus points for fastest answer

-export const LQ_TIME_TO_ZERO_BONUS = 20 // live quiz: seconds until the bonus points are zero
+export const LQ_TIME_TO_ZERO_BONUS: number = 20 // live quiz: seconds until the bonus points are zero

-export const LQ_DEFAULT_POINTS = 10 // live quiz: points a participant gets for participating in a poll
+export const LQ_DEFAULT_POINTS: number = 10 // live quiz: points a participant gets for participating in a poll

-export const LQ_DEFAULT_CORRECT_POINTS = 5 // live quiz: points a participant gets for answering correctly (independent of time)
+export const LQ_DEFAULT_CORRECT_POINTS: number = 5 // live quiz: points a participant gets for answering correctly (independent of time)
cypress/cypress/e2e/F-live-quiz-workflow.cy.ts (1)

934-937: Remove commented-out code or provide justification

Lines 935-937 contain commented-out code. Commented-out code can lead to confusion and should be removed if not needed. If you plan to use this code in the future, consider adding a comment explaining why it's commented out.

packages/graphql/src/services/sessions.ts (1)

110-111: Use object property shorthand syntax for brevity

Since the property names and the variable names are the same, you can use the object property shorthand syntax to make the code more concise and maintain consistency.

Apply this diff to simplify the code:

// At lines 110-111
-      maxBonusPoints: maxBonusPoints,
-      timeToZeroBonus: timeToZeroBonus,
+      maxBonusPoints,
+      timeToZeroBonus,

// At lines 127-128
-                    maxBonusPoints: maxBonusPoints,
-                    timeToZeroBonus: timeToZeroBonus,
+                    maxBonusPoints,
+                    timeToZeroBonus,

// At lines 260-261
-          maxBonusPoints: maxBonusPoints,
-          timeToZeroBonus: timeToZeroBonus,
+          maxBonusPoints,
+          timeToZeroBonus,

// At lines 277-278
-                    maxBonusPoints: maxBonusPoints,
-                    timeToZeroBonus: timeToZeroBonus,
+                    maxBonusPoints,
+                    timeToZeroBonus,

Also applies to: 127-128, 260-261, 277-278

packages/graphql/src/public/server.json (2)

21-21: Update API Documentation for CreateSession Mutation

The addition of maxBonusPoints and timeToZeroBonus enhances session customization. Ensure the API documentation is updated to reflect these new parameters, including their purpose and usage guidelines, to assist developers integrating with the API.


37-37: Refresh API Documentation for EditSession Mutation

The EditSession mutation's new parameters should be clearly documented. Update the API documentation to include maxBonusPoints and timeToZeroBonus, providing explanations and examples to guide users.

packages/i18n/messages/en.ts (2)

1100-1101: Improve clarity in liveQuizMaxBonusPointsTooltip

Consider rephrasing the tooltip for better readability. For example:

"This is the maximum number of bonus points a participant can receive for correctly answering a question during a gamified live quiz. The default value is {defaultValue}."

Apply this diff to refine the wording:

-            'This is the maximum number of points a participant will receive during a gamified live quiz for a correct answer to a question with sample solution. The default value is {defaultValue}.',
+            'This is the maximum number of bonus points a participant can receive for correctly answering a question during a gamified live quiz. The default value is {defaultValue}.',

1102-1102: Consider rephrasing liveQuizTimeToZeroBonus for clarity

To enhance user understanding, consider changing the label to "Time until bonus points reach zero".

Apply this diff:

-          liveQuizTimeToZeroBonus: 'Time to zero bonus points',
+          liveQuizTimeToZeroBonus: 'Time until bonus points reach zero',
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 385db73 and b413570.

Files selected for processing (27)
  • apps/frontend-manage/src/components/sessions/creation/WizardLayout.tsx (1 hunks)
  • apps/frontend-manage/src/components/sessions/creation/liveQuiz/AdvancedLiveQuizSettings.tsx (1 hunks)
  • apps/frontend-manage/src/components/sessions/creation/liveQuiz/LiveQuizSettingsStep.tsx (2 hunks)
  • apps/frontend-manage/src/components/sessions/creation/liveQuiz/LiveSessionWizard.tsx (4 hunks)
  • apps/frontend-manage/src/components/sessions/creation/liveQuiz/submitLiveSessionForm.tsx (2 hunks)
  • apps/func-response-processor/src/index.ts (3 hunks)
  • cypress/cypress/e2e/F-live-quiz-workflow.cy.ts (5 hunks)
  • packages/graphql/src/graphql/ops/MCreateSession.graphql (2 hunks)
  • packages/graphql/src/graphql/ops/MEditSession.graphql (2 hunks)
  • packages/graphql/src/graphql/ops/QGetSingleLiveSession.graphql (1 hunks)
  • packages/graphql/src/ops.schema.json (6 hunks)
  • packages/graphql/src/public/client.json (3 hunks)
  • packages/graphql/src/public/schema.graphql (4 hunks)
  • packages/graphql/src/public/server.json (3 hunks)
  • packages/graphql/src/schema/mutation.ts (2 hunks)
  • packages/graphql/src/schema/session.ts (1 hunks)
  • packages/graphql/src/services/questions.ts (8 hunks)
  • packages/graphql/src/services/sessions.ts (9 hunks)
  • packages/graphql/src/types/app.ts (1 hunks)
  • packages/i18n/index.ts (1 hunks)
  • packages/i18n/messages/de.ts (1 hunks)
  • packages/i18n/messages/en.ts (1 hunks)
  • packages/prisma/src/data/helpers.ts (2 hunks)
  • packages/prisma/src/prisma/migrations/20240917085550_modular_live_quiz_bonus_points/migration.sql (1 hunks)
  • packages/prisma/src/prisma/schema/element.prisma (1 hunks)
  • packages/prisma/src/prisma/schema/quiz.prisma (2 hunks)
  • packages/shared-components/src/constants.ts (1 hunks)
Additional comments not posted (45)
packages/graphql/src/graphql/ops/QGetSingleLiveSession.graphql (1)

20-21: Verify that maxBonusPoints and timeToZeroBonus exist in the LiveSession schema

Please ensure that the maxBonusPoints and timeToZeroBonus fields are defined in the LiveSession GraphQL type. If these fields are not present in the schema, the query will fail at runtime.

Run the following script to confirm that these fields are declared in the schema:

packages/prisma/src/prisma/migrations/20240917085550_modular_live_quiz_bonus_points/migration.sql (2)

6-7: Ensure default values in LiveSession align with business logic

The LiveSession table has new columns maxBonusPoints and timeToZeroBonus with default values of 45 and 20, respectively. Verify that these defaults are appropriate and consistent with the intended behavior. Specifically, consider whether these defaults might override values inherited from the LiveQuiz table or if sessions should always start with these defaults regardless of the quiz settings.

To confirm that the default values are correctly applied and do not conflict with inherited values, consider reviewing the session creation logic in the application code.


2-3: Confirm handling of nullable columns in QuestionInstance

The columns maxBonusPoints and timeToZeroBonus are added to the LiveQuiz and LiveSession tables as INTEGER NOT NULL with default values, ensuring they always have valid data. However, in the QuestionInstance table (lines 10-11), these columns are added as nullable (INTEGER without NOT NULL) and without default values. Please verify that this difference is intentional and that the application logic correctly handles NULL values for these columns when they are not set.

To check how NULL values are handled in the codebase for these columns, you can run:

Verification successful

Null handling for 'maxBonusPoints' and 'timeToZeroBonus' is implemented correctly

The application properly handles potential null values for 'maxBonusPoints' and 'timeToZeroBonus' in the QuestionInstance table:

  1. Backend: The response processor uses null coalescing operators to replace null values with default constants.
  2. Frontend: The LiveSessionWizard component assigns these values with fallbacks to default form values.
  3. Database: The Prisma schema confirms that these fields have default values for LiveQuiz and LiveSession tables, while allowing them to be nullable for QuestionInstance.

This implementation provides flexibility for QuestionInstance while maintaining consistent behavior throughout the application. The difference in nullability between tables is intentional and well-managed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of 'maxBonusPoints' and 'timeToZeroBonus' to verify NULL handling.

# Search for 'maxBonusPoints' usages
rg 'maxBonusPoints' -A 5

# Search for 'timeToZeroBonus' usages
rg 'timeToZeroBonus' -A 5

Length of output: 193558


Script:

#!/bin/bash
# Search for usages of 'maxBonusPoints' and 'timeToZeroBonus' with null checks or default assignments

echo "Searching for 'maxBonusPoints' usages with null checks or default assignments:"
rg 'maxBonusPoints.*(\?\?|[|]{2}|==\s*null|===\s*null|!=\s*null|!==\s*null)' -g '!*.{json,graphql}' --no-heading

echo -e "\nSearching for 'timeToZeroBonus' usages with null checks or default assignments:"
rg 'timeToZeroBonus.*(\?\?|[|]{2}|==\s*null|===\s*null|!=\s*null|!==\s*null)' -g '!*.{json,graphql}' --no-heading

echo -e "\nSearching for default value assignments in Prisma schema:"
rg '@default' packages/prisma/src/prisma/schema/ --no-heading

Length of output: 19571

packages/graphql/src/graphql/ops/MCreateSession.graphql (1)

8-9: Verify Server-Side Handling of New Parameters

Ensure that the server-side implementation of the createSession mutation properly handles maxBonusPoints and timeToZeroBonus, including validation and default values if they are made optional.

Run the following script to check the resolver implementation for createSession:

Also applies to: 22-23

Verification successful

Server-Side Implementation Verified for New Parameters

The server-side implementation of the createSession mutation correctly handles the new parameters maxBonusPoints and timeToZeroBonus. These parameters are:

  • Included in the function signature of the createSession service method
  • Passed to the database creation method via Prisma
  • Defined as required (non-nullable) fields in the GraphQL schema

The implementation is consistent across the service layer, GraphQL schema, and mutation definition, ensuring proper handling of these new parameters.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the createSession resolver handles new parameters.

# Test: Search for the createSession resolver implementation.
# Expect: The resolver includes handling for maxBonusPoints and timeToZeroBonus.

rg 'createSession\(.*\):.*\{' -A 50 --type ts --glob '**/graphql/**'

Length of output: 70


Script:

#!/bin/bash
# Description: Broader search for createSession implementation and related files

# Search for any mention of createSession in TypeScript and JavaScript files
echo "Searching for createSession mentions:"
rg "createSession" --type ts --type js

# Look for files that might contain resolver implementations
echo -e "\nSearching for potential resolver files:"
fd -e ts -e js | grep -i "resolver"

# Search for mutations or schema definitions related to createSession
echo -e "\nSearching for createSession in schema or mutation files:"
rg "createSession" --type graphql

Length of output: 8891


Script:

#!/bin/bash
# Description: Examine createSession implementation and search for GraphQL files

# Check the implementation of createSession in sessions.ts
echo "Examining createSession implementation:"
rg -A 30 "export async function createSession" packages/graphql/src/services/sessions.ts

# Search for .graphql files
echo -e "\nSearching for .graphql files:"
fd -e graphql

# If .graphql files exist, search for createSession in them
echo -e "\nSearching for createSession in .graphql files (if they exist):"
rg "createSession" -g "*.graphql"

Length of output: 11812

packages/graphql/src/graphql/ops/MEditSession.graphql (1)

24-25: Ensure Server-side Handling of New Parameters

The new parameters maxBonusPoints and timeToZeroBonus are being passed to the editSession mutation. Please verify that the server-side resolver and associated backend logic have been updated to handle these parameters appropriately, including any necessary validations.

Run the following script to verify that the editSession resolver includes handling for the new parameters:

Verification successful

Server-side Handling of New Parameters Confirmed

The editSession resolver has been updated to include the new parameters maxBonusPoints and timeToZeroBonus. These parameters are properly defined in the GraphQL schema and included in the resolver function signature.

However, it's recommended to manually review the implementation of the editSession function in packages/graphql/src/services/sessions.ts to ensure these parameters are being used appropriately within the function body.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the editSession resolver handles maxBonusPoints and timeToZeroBonus.

# Search for the editSession resolver implementation and check for usage of maxBonusPoints and timeToZeroBonus.
rg --type typescript 'editSession' -A 50 | rg 'maxBonusPoints\|timeToZeroBonus'

Length of output: 114


Script:

#!/bin/bash
# Description: Search for editSession resolver and check for maxBonusPoints and timeToZeroBonus parameters

# Search for editSession in .ts and .js files
echo "Searching for editSession in .ts and .js files:"
rg "editSession" -g "*.{ts,js}" -C 10

# Use ast-grep to find function declarations or arrow functions related to editSession
echo "\nSearching for editSession function declarations:"
ast-grep --lang javascript --pattern 'function $FUNC_NAME($_) { $$$ }' | rg "editSession"
ast-grep --lang javascript --pattern 'const $FUNC_NAME = ($_) => { $$$ }' | rg "editSession"

# Search for maxBonusPoints and timeToZeroBonus in the context of editSession
echo "\nSearching for maxBonusPoints and timeToZeroBonus in editSession context:"
rg "editSession" -g "*.{ts,js}" -C 20 | rg "maxBonusPoints|timeToZeroBonus"

Length of output: 68659

apps/frontend-manage/src/components/sessions/creation/liveQuiz/AdvancedLiveQuizSettings.tsx (2)

82-82: Verify className usage on ResponsiveContainer

The ResponsiveContainer component may not accept the className prop, which could result in the styling not being applied as expected. This might affect the layout or appearance of the chart.

Please check if ResponsiveContainer supports the className prop. If not, consider wrapping it in a div or using alternative methods to apply the margin.


48-48: Confirm className prop structure on Modal component

The className prop is being passed an object { content: 'h-max min-h-max' }. Ensure that the Modal component supports this structure. If the expected prop is classes or a different prop name, or if className should be a string, this might cause unintended styling issues.

Please verify the prop expectations for the Modal component in the design system documentation.

packages/graphql/src/schema/session.ts (1)

62-63: Confirm Nullability and Database Consistency for New Fields

Please verify whether maxBonusPoints and timeToZeroBonus should be nullable. If these fields can be null in the database or are optional in some cases, consider adding { nullable: true } to their GraphQL schema definitions to accurately reflect their potential nullability.

Run the following script to check if these fields are defined and nullable in the Prisma schema:

Verification successful

Fields are Correctly Defined as Non-Nullable

The maxBonusPoints and timeToZeroBonus fields are correctly defined as non-nullable in both the Prisma schema and the GraphQL schema. No changes are required:

  • In the Prisma schema, both fields are defined as Int with @default values, indicating they are non-nullable.
  • In the GraphQL schema, t.exposeInt() is used, which typically represents non-nullable integer fields.

This implementation is consistent across both schemas and accurately reflects the non-nullable nature of these fields.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check definitions of `maxBonusPoints` and `timeToZeroBonus` in the Prisma schema.

# Expected result: The fields should be present in the `LiveSession` model, with `?` if they are optional (nullable).

rg --type prisma -A 20 'model LiveSession' | rg 'maxBonusPoints\|timeToZeroBonus'

Length of output: 114


Script:

#!/bin/bash
# Find the Prisma schema file
echo "Searching for Prisma schema file:"
fd -e prisma

# If Prisma schema is found, search for LiveSession model and fields
echo -e "\nSearching for LiveSession model and fields in Prisma schema:"
fd -e prisma -x cat {} | rg -A 20 'model LiveSession' | rg 'maxBonusPoints|timeToZeroBonus'

# Search for GraphQL schema definition of these fields
echo -e "\nSearching for GraphQL schema definition of fields:"
rg 'maxBonusPoints:|timeToZeroBonus:' packages/graphql/src/schema/session.ts

Length of output: 1287

packages/prisma/src/prisma/schema/quiz.prisma (1)

166-167: Duplicate of previous comment regarding validation

apps/frontend-manage/src/components/sessions/creation/liveQuiz/LiveSessionWizard.tsx (1)

149-150: Confirm Default Values for New Fields

Verify that the default values LQ_MAX_BONUS_POINTS and LQ_TIME_TO_ZERO_BONUS imported from @klicker-uzh/shared-components/src/constants align with the intended defaults for your application. This ensures consistent behavior across different components.

packages/graphql/src/public/client.json (3)

21-21: Hash update for CreateSession operation

The hash value for CreateSession has been updated to reflect the inclusion of new properties related to bonus points management (maxBonusPoints and timeToZeroBonus). This ensures that the client and server are in sync regarding the GraphQL schema changes.


37-37: Hash update for EditSession operation

The updated hash for EditSession aligns with the additions in the schema to support customized bonus points logic for live quizzes. This change is necessary for the client to recognize the updated mutations.


133-133: Hash update for GetSingleLiveSession operation

The hash value for GetSingleLiveSession has been updated, indicating that the query now includes the new bonus points properties. This allows clients to retrieve the bonus points configuration for live quizzes.

packages/shared-components/src/constants.ts (1)

5-8: New constants added correctly

The new constants for live quiz scoring are appropriately added and enhance the functionality as per the PR objectives.

packages/graphql/src/services/questions.ts (4)

567-568: Verify the Presence of maxBonusPoints and timeToZeroBonus

When assigning maxBonusPoints and timeToZeroBonus from instance.sessionBlock.session, ensure that these properties are available and properly defined. If there is a possibility that they might be undefined, consider adding null checks or default values to prevent potential runtime errors.


656-657: Confirm Correct Update of Instance Data

In the questionInstance.update call, you're updating maxBonusPoints and timeToZeroBonus. Verify that these fields exist in the database schema and the QuestionInstance model to ensure the update operates correctly.


551-552: Ensure Correct Return Statement in Reduce Functions

In the reduce functions starting at line 551, ensure that you're returning the accumulator acc at the end of each iteration. Missing the return statement can lead to unexpected results or runtime errors.

Apply this diff to fix the missing return statement:

        }, [])
+       , [])

Likely invalid or redundant comment.


541-542: Fix Initialization: Initialize instanceData as an Array

The instanceData variable is declared as an array of objects but is initialized with an object {}. This will cause a type mismatch and potential runtime errors. You should initialize it as an array [] to correctly collect the instances from the reduce functions.

Apply this diff to correct the initialization:

-const instanceData: {
+const instanceData: {
    instanceId: number
    multiplier: number
    maxBonusPoints: number | undefined
    timeToZeroBonus: number | undefined
    sessionId: string | undefined
    practiceQuizId: string | undefined
    microLearningId: string | undefined
-}[] = {
+}[] = [
    // existing code
-}
+]

Likely invalid or redundant comment.

packages/prisma/src/data/helpers.ts (1)

212-213: Verify handling of optional bonus point parameters

The optional parameters maxBonusPoints and timeToZeroBonus have been added to prepareQuestionInstance. Please ensure that all downstream code properly handles cases when these parameters are undefined to prevent potential runtime errors.

Also applies to: 220-221, 229-230

cypress/cypress/e2e/F-live-quiz-workflow.cy.ts (2)

74-74: Verified that advanced settings are appropriately hidden

The test correctly asserts that the advanced settings are not visible when no course is selected, which aligns with the expected user interface behavior.


280-289: Confirmed persistence of advanced settings in edit mode

The test appropriately verifies that maxBonusPoints and timeToZeroBonus values are persisted when editing the session. This ensures that the advanced settings are correctly saved and retrieved.

packages/graphql/src/services/sessions.ts (4)

77-78: New parameters maxBonusPoints and timeToZeroBonus added to CreateSessionArgs

The new properties maxBonusPoints and timeToZeroBonus are correctly added to the CreateSessionArgs interface with appropriate type annotations.


869-870: Parameters added correctly to cache initialization

The properties maxBonusPoints and timeToZeroBonus are correctly included when initializing the cache for the new active block. This ensures that these values are accessible during the session.


195-196: Ensure all calls to editSession are updated with new parameters

The editSession function now includes maxBonusPoints and timeToZeroBonus as parameters. Please verify that all calls to this function have been updated to include these new parameters to prevent potential runtime errors.

Run the following script to find all calls to editSession and check parameter usage:

Verification successful

To complete the verification, we need to check the GraphQL schema definition for the mutation that uses editSession. Let's search for it in the GraphQL schema files.


Changes to editSession have been properly implemented

The GraphQL schema for the editSession mutation has been updated to include the new parameters maxBonusPoints and timeToZeroBonus. These parameters are correctly defined and passed as arguments to the editSession field in the mutation. Since the resolver function receives the args object directly, we can confirm that all calls to editSession will now include these new parameters.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to `editSession` and display surrounding lines for context.

# Search for `editSession(` in TypeScript files and show 3 lines before and after each match.
rg --type ts -A 3 -B 3 'editSession\('

Length of output: 894


Script:

#!/bin/bash
# Search for the GraphQL mutation definition related to editSession
rg --type ts -A 10 -B 2 'mutation.*editSession'

Length of output: 33162


93-94: Ensure all calls to createSession are updated with new parameters

The createSession function now includes maxBonusPoints and timeToZeroBonus as parameters. Please verify that all calls to this function throughout the codebase have been updated to include these new parameters to prevent potential runtime errors.

Run the following script to find all calls to createSession and check parameter usage:

packages/graphql/src/public/server.json (3)

21-21: Ensure New Parameters are Optional or Provide Default Values

In the CreateSession mutation, the new parameters maxBonusPoints and timeToZeroBonus are added as required fields. This may break existing clients that do not provide these arguments. Consider making these parameters optional with default values to maintain backward compatibility.

Run the following script to check for usages of CreateSession that may omit the new parameters:


37-37: Ensure New Parameters are Optional or Provide Default Values in EditSession

Similar to CreateSession, the EditSession mutation now includes the required parameters maxBonusPoints and timeToZeroBonus. To prevent breaking changes for existing clients, consider making these parameters optional or setting default values.

Run the following script to identify potential issues in EditSession usage:

Verification successful

To gather the necessary information, I'll generate new shell scripts to verify the usage of the EditSession mutation.

This script will:

  1. Find files with extensions .graphql, .gql, .js, or .ts (common for GraphQL files and files that might contain GraphQL).
  2. Search these files for EditSession mutations.
  3. Show 20 lines after the match to capture the full mutation.
  4. Filter out results that contain both maxBonusPoints and timeToZeroBonus.

If there are any matches, it would indicate usages of EditSession without the new parameters.


Based on the analysis of the script results, I can now provide a final response to the review comment.

New Required Parameters in EditSession Mutation Confirmed

The EditSession mutation in packages/graphql/src/graphql/ops/MEditSession.graphql indeed includes the new required parameters maxBonusPoints and timeToZeroBonus. While this change is consistent within the codebase, it does pose a risk of breaking existing clients as pointed out in the original review.

To mitigate this:

  • Consider making maxBonusPoints and timeToZeroBonus optional parameters (remove the !).
  • Alternatively, provide default values for these parameters in the resolver.
  • Implement a thorough testing strategy to ensure backward compatibility.
  • Plan a migration path for existing clients to adopt the new parameters.

These steps will help maintain compatibility while introducing the new functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of `EditSession` mutation without the new parameters.

# Test: Search for `EditSession` mutations missing `maxBonusPoints` or `timeToZeroBonus`.
rg --type graphql 'mutation\s+EditSession\(' -A10 | rg -L 'maxBonusPoints' | rg -L 'timeToZeroBonus'

Length of output: 130


Script:

#!/bin/bash
# Find GraphQL files and search for EditSession mutations
fd '\.(graphql|gql|js|ts)$' | xargs rg 'mutation\s+EditSession\s*\(' -A20 | rg -v 'maxBonusPoints.*timeToZeroBonus'

Length of output: 1731


133-133: Verify Consistency of Fragments and Queries

The fragment QuestionData and related queries have been updated. Ensure that all fragments and queries using QuestionData are consistent with these changes across the codebase to prevent runtime GraphQL errors.

Run the following script to check for inconsistencies:

Verification successful

QuestionData Fragment and Queries are Consistent

The QuestionData fragment and related queries have been verified to be consistent across the codebase. The changes mentioned in the review comment are accurately reflected in the implementation, including the structure for ChoicesQuestionData, NumericalQuestionData, and FreeTextQuestionData. No further action is required to ensure consistency.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for all usages of the `QuestionData` fragment.

# Test: Find files using `...QuestionData` to verify consistency.
rg --type graphql '\.\.\.\s*QuestionData'

Length of output: 75


Script:

#!/bin/bash
# Search for "QuestionData" in all files
echo "Searching for QuestionData in all files:"
rg "QuestionData" -n

echo "\nFinding potential GraphQL files:"
fd -e graphql -e gql -e js -e ts -e json

echo "\nSearching for QuestionData fragment definition:"
rg "fragment\s+QuestionData" -n

Length of output: 124245


Script:

#!/bin/bash
# Search for all uses of the QuestionData fragment
echo "Searching for QuestionData fragment usage:"
rg "\.\.\.QuestionData" -n

echo "\nSearching for QuestionData type definitions:"
rg "type QuestionData" -n

echo "\nSearching for QuestionData interface definitions:"
rg "interface QuestionData" -n

Length of output: 9003

packages/i18n/messages/en.ts (9)

1098-1098: LGTM!

The addition of liveQuizAdvancedSettings is appropriate and consistent with the existing structure.


1099-1099: LGTM!

The key liveQuizMaxBonusPoints has been added correctly.


1105-1105: LGTM!

The addition of liveQuizTotalPointsCorrect is appropriate.


1106-1106: LGTM!

The key liveQuizAnswerTime is correctly added.


1107-1107: LGTM!

The key liveQuizTotalAwardedPoints has been added appropriately.


1108-1109: LGTM!

The validation message liveQuizMaxBonusPointsReq is correctly formulated.


1110-1110: LGTM!

The message liveQuizMaxBonusPointsMin is appropriate.


1111-1112: LGTM!

The validation message liveQuizTimeToZeroBonusReq is well-defined.


1113-1114: LGTM!

The message liveQuizTimeToZeroBonusMin is correctly added.

packages/i18n/messages/de.ts (1)

1103-1120: New localization strings are correctly added and consistent

The added localization strings for live quiz bonus points settings are properly implemented with accurate German translations. The placeholders {defaultValue}, {answerTime}, and {totalPoints} are correctly used and consistent with existing patterns.

packages/graphql/src/ops.schema.json (7)

8120-8135: LGTM!

The addition of the maxBonusPoints argument to the createSession mutation looks good. It is defined as a non-nullable Int type, which is appropriate for specifying the maximum bonus points for a session.


8167-8182: LGTM!

The addition of the timeToZeroBonus argument to the createSession mutation looks good. It is defined as a non-nullable Int type, which is appropriate for specifying the time limit for bonus points to reach zero.


16495-16510: LGTM!

The addition of the maxBonusPoints field to the Session type looks good. It is defined as a non-nullable Int type, which is appropriate for representing the maximum bonus points for a session.


16623-16638: LGTM!

The addition of the timeToZeroBonus field to the Session type looks good. It is defined as a non-nullable Int type, which is appropriate for representing the time limit for bonus points to reach zero in a session.


9227-9242: LGTM!

The addition of the maxBonusPoints argument to the editSession mutation looks good. It is defined as a non-nullable Int type, which is appropriate for specifying the maximum bonus points when editing a session.


9274-9289: LGTM!

The addition of the timeToZeroBonus argument to the editSession mutation looks good. It is defined as a non-nullable Int type, which is appropriate for specifying the time limit for bonus points to reach zero when editing a session.


Line range hint 1-18000: Verify the usage of new fields in the codebase.

The additions of maxBonusPoints and timeToZeroBonus fields to the createSession and editSession mutations, as well as to the Session type, look good.

However, it's important to verify that all usages of these mutations and the Session type have been updated to provide values for the new required fields.

Run the following script to search for usages of the mutations and type:

If any usages are found that don't provide the new required arguments or select the new fields, they will need to be updated to avoid GraphQL validation errors.

packages/i18n/index.ts Show resolved Hide resolved
packages/graphql/src/schema/mutation.ts Show resolved Hide resolved
packages/graphql/src/schema/mutation.ts Show resolved Hide resolved
packages/graphql/src/services/sessions.ts Outdated Show resolved Hide resolved
packages/i18n/messages/en.ts Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b413570 and de1c1fd.

Files selected for processing (3)
  • apps/frontend-manage/src/components/sessions/creation/liveQuiz/AdvancedLiveQuizSettings.tsx (1 hunks)
  • packages/i18n/messages/de.ts (1 hunks)
  • packages/i18n/messages/en.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/i18n/messages/de.ts
  • packages/i18n/messages/en.ts

@sjschlapbach sjschlapbach merged commit 9b5d199 into v3 Sep 17, 2024
7 of 10 checks passed
@sjschlapbach sjschlapbach deleted the modular-bonus-points branch September 17, 2024 13:59
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
9.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

Copy link

cypress bot commented Sep 17, 2024

klicker-uzh    Run #2983

Run Properties:  status check passed Passed #2983  •  git commit 9b5d199559: feat: add possibility to specify customized bonus points logic for live quizzes ...
Project klicker-uzh
Branch Review v3
Run status status check passed Passed #2983
Run duration 08m 48s
Commit git commit 9b5d199559: feat: add possibility to specify customized bonus points logic for live quizzes ...
Committer Julius Schlapbach
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 43
View all changes introduced in this branch ↗︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants