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

enhance: show live quiz description to students before first block activation #4379

Merged
merged 3 commits into from
Dec 2, 2024

Conversation

sjschlapbach
Copy link
Member

@sjschlapbach sjschlapbach commented Dec 2, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced live quiz functionality with the addition of a beforeFirstBlock property, indicating the status before the first block is activated.
    • New quiz description and related properties are now displayed in the live quiz interface.
    • Improved user notifications about surveys with adjusted positioning.
  • Bug Fixes

    • Corrected the handling of quiz descriptions in both creation and editing workflows.
  • Documentation

    • Updated GraphQL schema to reflect new fields and types related to live quizzes and user interactions.
  • Tests

    • Expanded end-to-end tests to cover new quiz description features and ensure proper UI display across devices.

Copy link

aviator-app bot commented Dec 2, 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 Dec 2, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces several modifications across multiple files, primarily enhancing the functionality and structure of live quizzes. Key changes include the addition of new properties such as beforeFirstBlock and description in various components and GraphQL queries. The QuestionList component's CSS has been adjusted for user notifications, while the session/[id].tsx file has been updated to conditionally render descriptions. Additionally, Cypress tests have been updated to incorporate new quiz descriptions, and the GraphQL schema has been expanded with new fields and mutations related to live quizzes.

Changes

File Path Change Summary
apps/frontend-manage/src/components/questions/QuestionList.tsx Adjusted bottom margin of a fixed div for user notification (CSS change).
apps/frontend-pwa/src/pages/session/[id].tsx Added description and beforeFirstBlock properties; updated rendering logic for conditional display.
cypress/cypress/e2e/F-live-quiz-workflow.cy.ts Added quizDescription2 variable; updated tests to include new quiz description and visibility checks.
packages/graphql/src/graphql/ops/QGetRunningLiveQuiz.graphql Added status and beforeFirstBlock fields; replaced status with description.
packages/graphql/src/ops.schema.json Added multiple new types and fields related to quizzes and user interactions.
packages/graphql/src/public/client.json Updated hash value for GetRunningLiveQuiz.
packages/graphql/src/public/schema.graphql Added beforeFirstBlock field to LiveQuiz type.
packages/graphql/src/public/server.json Added multiple new mutations and queries related to participant accounts and quizzes.
packages/graphql/src/schema/liveQuiz.ts Updated ILiveQuiz interface to include beforeFirstBlock; modified LiveQuiz implementation.
packages/graphql/src/services/liveQuizzes.ts Modified getRunningLiveQuiz to include beforeFirstBlock; updated leaderboard query.

Possibly related PRs

Suggested reviewers

  • rschlaefli: Suggested reviewer for this pull request.

Warning

Rate limit exceeded

@sjschlapbach has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 13 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

Reviewing files that changed from the base of the PR and between fe45216 and fdefebb.


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

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

🧹 Outside diff range and nitpick comments (3)
apps/frontend-pwa/src/pages/session/[id].tsx (1)

194-201: Consider simplifying the nested conditional logic.

The current implementation uses nested ternary operators which can be hard to maintain. Consider extracting this logic into a separate component or using early returns.

Here's a suggested refactor:

-          {!activeBlock ? (
-            beforeFirstBlock &&
-            description !== null &&
-            typeof description !== 'undefined' ? (
-              <div data-cy="live-quiz-description">
-                <H3>{displayName}</H3>
-                <Markdown content={description} />
-              </div>
-            ) : isGamificationEnabled ? (
-              <div className={twMerge('min-h-full flex-1 bg-white')}>
-                <LiveQuizLeaderboard quizId={id} />
-              </div>
-            ) : (
-              <div>{t('pwa.liveQuiz.noActiveQuestion')}</div>
-            )
-          ) : (
+          {activeBlock ? (
+            <QuestionArea
+              expiresAt={activeBlock.expiresAt}
+              instances={activeBlock.elements ?? []}
+              handleNewResponse={handleNewResponse}
+              quizId={id}
+              timeLimit={activeBlock?.timeLimit ?? undefined}
+              execution={activeBlock?.execution ?? 0}
+            />
+          ) : beforeFirstBlock && description ? (
+            <div data-cy="live-quiz-description">
+              <H3>{displayName}</H3>
+              <Markdown content={description} />
+            </div>
+          ) : isGamificationEnabled ? (
+            <div className={twMerge('min-h-full flex-1 bg-white')}>
+              <LiveQuizLeaderboard quizId={id} />
+            </div>
+          ) : (
+            <div>{t('pwa.liveQuiz.noActiveQuestion')}</div>
+          )}
cypress/cypress/e2e/F-live-quiz-workflow.cy.ts (1)

663-682: Consider enhancing the description visibility test.

The test case verifies the basic visibility of the quiz description, but it could be enhanced to cover more edge cases.

Consider adding these test cases:

  1. Verify description visibility after quiz completion
  2. Test description formatting/truncation
  3. Test description with special characters
  4. Test empty description handling

Would you like me to help generate the additional test cases?

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

1998-1999: Consider adding error handling for undefined quiz.

The return statement could be more explicit about handling the case where quiz is undefined.

Apply this diff to improve error handling:

-    return quizWithoutSolutions ?? { ...quiz, beforeFirstBlock }
+    if (!quiz) return null
+    return quizWithoutSolutions ?? { ...quiz, beforeFirstBlock }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1dae178 and fe45216.

📒 Files selected for processing (11)
  • apps/frontend-manage/src/components/questions/QuestionList.tsx (1 hunks)
  • apps/frontend-pwa/src/pages/session/[id].tsx (3 hunks)
  • cypress/cypress/e2e/F-live-quiz-workflow.cy.ts (3 hunks)
  • packages/graphql/src/graphql/ops/QGetRunningLiveQuiz.graphql (1 hunks)
  • packages/graphql/src/ops.schema.json (1 hunks)
  • packages/graphql/src/ops.ts (3 hunks)
  • packages/graphql/src/public/client.json (1 hunks)
  • packages/graphql/src/public/schema.graphql (1 hunks)
  • packages/graphql/src/public/server.json (1 hunks)
  • packages/graphql/src/schema/liveQuiz.ts (2 hunks)
  • packages/graphql/src/services/liveQuizzes.ts (2 hunks)
🔥 Files not summarized due to errors (1)
  • packages/graphql/src/ops.ts: Error: Server error: no LLM provider could handle the message
✅ Files skipped from review due to trivial changes (2)
  • apps/frontend-manage/src/components/questions/QuestionList.tsx
  • packages/graphql/src/public/client.json
🧰 Additional context used
🪛 Biome (1.9.4)
packages/graphql/src/services/liveQuizzes.ts

[error] 1951-1951: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (13)
packages/graphql/src/graphql/ops/QGetRunningLiveQuiz.graphql (2)

9-14: LGTM! New fields support quiz description feature.

The addition of beforeFirstBlock and description fields aligns with the PR objective to show quiz descriptions to students before the first block activation.


4-4: Verify if the status field is redundant.

The query includes both status and activeBlock.status. Consider if both fields are necessary or if they serve different purposes.

packages/graphql/src/schema/liveQuiz.ts (2)

90-90: LGTM! Interface extension is well-defined.

The optional beforeFirstBlock property is appropriately added to the ILiveQuiz interface.


118-118: LGTM! Implementation matches interface definition.

The beforeFirstBlock field is correctly implemented with nullable option, maintaining consistency with the interface.

apps/frontend-pwa/src/pages/session/[id].tsx (2)

19-22: LGTM! Required imports for new functionality.

The imports for Markdown and H3 components are necessary for rendering the quiz description.


85-86: LGTM! Props destructuring is consistent.

The new properties are correctly destructured from data.studentLiveQuiz.

packages/graphql/src/public/schema.graphql (1)

791-791: LGTM: Schema change is well-defined.

The addition of the beforeFirstBlock field to the LiveQuiz type is clean and follows GraphQL schema best practices.

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

147-147: LGTM: Schema change aligns with PR objective

The addition of the beforeFirstBlock field to the studentLiveQuiz type is appropriate for enabling the display of quiz descriptions before first block activation.

Let's verify the implementation of this new field:

✅ Verification successful

Schema change is properly implemented

The beforeFirstBlock field is correctly implemented:

  • Field is defined in the schema types (packages/graphql/src/schema/liveQuiz.ts)
  • Implementation in liveQuizzes.ts service correctly computes the value by checking if all blocks are in SCHEDULED status
  • The field is properly included in the response object for published quizzes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the resolver implementation of the new beforeFirstBlock field

# Search for resolver implementation
ast-grep --pattern 'beforeFirstBlock'

# Search for any tests covering this new field
rg -l 'beforeFirstBlock.*test'

Length of output: 248


Script:

#!/bin/bash
# Let's check the implementation context in the liveQuizzes service
rg -A 10 -B 5 'beforeFirstBlock' packages/graphql/src/services/liveQuizzes.ts

# Let's also check the resolver implementation
ast-grep --pattern $'type StudentLiveQuiz {
  $$$
  beforeFirstBlock: $_
  $$$
}'

# Check for any type definitions
rg 'beforeFirstBlock.*:.*boolean'

Length of output: 3582

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

8743-8754: LGTM! Well-designed schema addition for quiz state tracking.

The new beforeFirstBlock field in the LiveQuiz type is a well-structured addition that enables tracking whether a quiz is in its initial state before the first block activation. The nullable Boolean type is appropriate for this state flag.

packages/graphql/src/ops.ts (4)

866-866: LGTM: Type definition is well-structured

The new beforeFirstBlock field is properly typed as an optional boolean using the Maybe type wrapper, following GraphQL schema conventions.


3710-3710: LGTM: Query type is properly updated

The new fields beforeFirstBlock and description are correctly added to the GetRunningLiveQuizQuery type with proper nullability handling.


4056-4056: LGTM: Document definition is comprehensive

The GetRunningLiveQuizDocument is well-structured with proper field selections, appropriate fragment usage, and correct typing as DocumentNode.


Line range hint 866-4056: Verify handling of new fields in query consumers

Let's ensure that components consuming this query properly handle the new beforeFirstBlock and description fields.

cypress/cypress/e2e/F-live-quiz-workflow.cy.ts Outdated Show resolved Hide resolved
packages/graphql/src/services/liveQuizzes.ts Outdated Show resolved Hide resolved
Copy link

cypress bot commented Dec 2, 2024

klicker-uzh    Run #3734

Run Properties:  status check passed Passed #3734  •  git commit 60671f7b8d ℹ️: Merge fdefebb0e3f134287b146b9d51916fe08a27d3b7 into 1dae1785c44065200bbf65d270ed...
Project klicker-uzh
Branch Review show-live-quiz-description
Run status status check passed Passed #3734
Run duration 11m 50s
Commit git commit 60671f7b8d ℹ️: Merge fdefebb0e3f134287b146b9d51916fe08a27d3b7 into 1dae1785c44065200bbf65d270ed...
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 148
View all changes introduced in this branch ↗︎

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 (3)
cypress/cypress/e2e/F-live-quiz-workflow.cy.ts (3)

590-595: Maintain consistent indentation

The indentation in this block varies between different lines. Consider maintaining consistent indentation for better readability.

-    cy.get('[data-cy="insert-live-description"]')
-      .realClick()
-      .type(quizDescription2)
-    cy.get('[data-cy="insert-live-description"]')
-      .realClick()
-      .contains(quizDescription2)
+    cy.get('[data-cy="insert-live-description"]')
+      .realClick()
+      .type(quizDescription2)
+    cy.get('[data-cy="insert-live-description"]')
+      .realClick()
+      .contains(quizDescription2)

664-675: Well-structured test case with comprehensive coverage

The test case effectively verifies description visibility across both desktop and mobile views. Good practice in testing responsive behavior.

Consider extracting the wait time (1000ms) to a named constant for better maintainability:

+ const DESCRIPTION_VISIBILITY_WAIT_MS = 1000;
  it('Check that the live quiz description is correctly shown to students', () => {
    cy.loginStudent()
    cy.findByText(quizDisplayName2).click()
-   cy.wait(1000)
+   cy.wait(DESCRIPTION_VISIBILITY_WAIT_MS)

677-684: Extract wait times to named constants

The test uses magic numbers for wait times. Consider extracting these to named constants for better maintainability and clarity.

+ const BLOCK_START_WAIT_MS = 1000;
+ const BLOCK_TRANSITION_WAIT_MS = 500;

  it('Start the first block of the live quiz', () => {
    cy.loginLecturer()
    cy.get('[data-cy="live-quizzes"]').click()
    cy.get(`[data-cy="live-quiz-cockpit${quizName2}"]`).click()
-   cy.wait(1000)
+   cy.wait(BLOCK_START_WAIT_MS)
    cy.get('[data-cy="next-block-timeline"]').click()
-   cy.wait(500)
+   cy.wait(BLOCK_TRANSITION_WAIT_MS)
  })
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fe45216 and fdefebb.

📒 Files selected for processing (2)
  • cypress/cypress/e2e/F-live-quiz-workflow.cy.ts (3 hunks)
  • packages/graphql/src/services/liveQuizzes.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/graphql/src/services/liveQuizzes.ts

[error] 1951-1951: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (5)
packages/graphql/src/services/liveQuizzes.ts (4)

1940-1940: LGTM: Required include for block status check.

The addition of blocks to the include statement is necessary to support the new block status checking functionality.


1944-1947: Improve null safety with optional chaining.

The code could benefit from using optional chaining to handle potential null values more elegantly.

Apply this diff to improve null safety:

- const beforeFirstBlock = quiz?.blocks.every(
+ const beforeFirstBlock = quiz?.blocks?.every(
    (block) => block.status === ElementBlockStatus.SCHEDULED
  )

1954-1954: LGTM: Proper integration of the new property.

The beforeFirstBlock property is correctly added to the quiz object structure.


1998-1998: LGTM: Consistent return type maintained.

The beforeFirstBlock property is correctly included in the fallback case, ensuring consistent return types.

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

19-19: LGTM: Variable declaration follows consistent pattern

The new constant follows the established naming convention and is appropriately placed with other quiz-related constants.

Copy link

sonarqubecloud bot commented Dec 2, 2024

@sjschlapbach sjschlapbach merged commit cc424db into v3 Dec 2, 2024
16 checks passed
@sjschlapbach sjschlapbach deleted the show-live-quiz-description branch December 2, 2024 06:43
Copy link

cypress bot commented Dec 2, 2024

klicker-uzh    Run #3735

Run Properties:  status check passed Passed #3735  •  git commit cc424dbf93: enhance: show live quiz description to students before first block activation (#...
Project klicker-uzh
Branch Review v3
Run status status check passed Passed #3735
Run duration 12m 12s
Commit git commit cc424dbf93: enhance: show live quiz description to students before first block activation (#...
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 148
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.

1 participant