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(apps/frontend-manage): add completeness states to workflow component in wizards #4365

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

sjschlapbach
Copy link
Member

@sjschlapbach sjschlapbach commented Nov 8, 2024

Summary by CodeRabbit

  • New Features

    • Updated the @uzh-bf/design-system dependency to version 3.0.0-alpha.34 across multiple applications and packages, potentially introducing new features and improvements.
  • Bug Fixes

    • Enhanced type safety in various components by explicitly defining state types, improving reliability and maintainability.
  • Documentation

    • Updated validation schemas for forms in components, ensuring better adherence to specified rules and structures.

@sjschlapbach sjschlapbach marked this pull request as ready for review November 8, 2024 13:29
Copy link

aviator-app bot commented Nov 8, 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 Nov 8, 2024

📝 Walkthrough

Walkthrough

The pull request includes updates to the package.json files across multiple projects within the @klicker-uzh organization. The primary change involves updating the version of the @uzh-bf/design-system dependency from 3.0.0-alpha.32 to 3.0.0-alpha.34. Additionally, several components have been modified to enhance type safety by explicitly defining the type of the stepValidity state variable as boolean[] and updating the workflowItems array to include a completed property for each step.

Changes

File Path Change Summary
apps/auth/package.json Updated @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
apps/backend-docker/package.json Updated package version to 3.3.0-alpha.7 and @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
apps/docs/package.json Updated @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
apps/frontend-control/package.json Updated @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
apps/frontend-manage/package.json Updated @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
apps/frontend-manage/src/components/sessions/... Updated stepValidity type to boolean[] and added completed property to workflowItems
apps/frontend-pwa/package.json Updated @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
apps/func-incoming-responses/package.json Updated package version to 3.3.0-alpha.7 and @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
apps/func-response-processor/package.json Updated @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
apps/office-addin/package.json Updated @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
packages/markdown/package.json Updated peer dependency @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
packages/shared-components/package.json Updated peer dependency @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34
packages/transactional/package.json Updated @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34

Possibly related PRs

Suggested reviewers

  • rschlaefli

Warning

Tool Failures:

Tool Failure Count:


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

sonarqubecloud bot commented Nov 8, 2024

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarCloud

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 (9)
apps/frontend-manage/src/components/sessions/creation/liveQuiz/LiveSessionWizard.tsx (3)

76-78: Consider more granular step validation initialization.

While the explicit typing of stepValidity as boolean[] improves type safety, initializing all steps as valid in edit mode (!!initialValues) might not accurately reflect the actual validity state of each step. Consider initializing each step's validity based on its specific validation requirements.

-const [stepValidity, setStepValidity] = useState<boolean[]>(
-  Array(4).fill(!!initialValues)
-)
+const [stepValidity, setStepValidity] = useState<boolean[]>(() => {
+  if (!initialValues) return Array(4).fill(false);
+  return [
+    nameValidationSchema.isValidSync(initialValues),
+    descriptionValidationSchema.isValidSync(initialValues),
+    settingsValidationSchema.isValidSync(initialValues),
+    questionsValidationSchema.isValidSync(initialValues),
+  ];
+});

161-161: Consider using an enum for step indices.

The completed property correctly references stepValidity indices, but using magic numbers (0,1,2,3) makes the code less maintainable. Consider introducing an enum to manage step indices.

enum WizardSteps {
  INFORMATION = 0,
  DESCRIPTION = 1,
  SETTINGS = 2,
  QUESTIONS = 3,
}

const workflowItems = [
  {
    title: t('shared.generic.information'),
    completed: stepValidity[WizardSteps.INFORMATION],
  },
  // ... other items using WizardSteps enum
];

Also applies to: 167-167, 173-173, 179-179


Line range hint 1-359: Consider architectural improvements for better maintainability.

The component handles complex functionality well but could benefit from the following improvements:

  1. Move validation schemas to a separate file to improve maintainability
  2. Implement lazy loading for step components to improve initial load time
  3. Consider extracting the wizard logic into a custom hook for reusability

Example implementation for lazy loading:

const LiveQuizInformationStep = lazy(() => import('./LiveQuizInformationStep'));
const LiveQuizDescriptionStep = lazy(() => import('./LiveQuizDescriptionStep'));
// ... other step components

// Wrap the steps with Suspense
<Suspense fallback={<LoadingSpinner />}>
  {steps[activeStep]}
</Suspense>

Would you like me to help create a separate PR for these improvements?

apps/frontend-manage/src/components/sessions/creation/practiceQuiz/PracticeQuizWizard.tsx (2)

95-97: Consider deriving stepValidity length from workflow steps.

While the explicit typing improves type safety, the hardcoded array length of 4 could become a maintenance issue if steps are added or removed.

Consider this more maintainable approach:

-const [stepValidity, setStepValidity] = useState<boolean[]>(
-  Array(4).fill(!!initialValues)
-)
+const WORKFLOW_STEPS = ['information', 'description', 'settings', 'questions'] as const
+const [stepValidity, setStepValidity] = useState<boolean[]>(
+  Array(WORKFLOW_STEPS.length).fill(!!initialValues)
+)

Line range hint 1-424: Consider architectural improvements for better maintainability.

The component is well-structured but could benefit from the following improvements:

  1. Move validation schemas to a separate file to improve maintainability and reusability
  2. Consider lazy loading step components to improve initial load performance

Example implementation for validation schemas:

// validationSchemas.ts
export const nameValidationSchema = yup.object().shape({
  name: yup.string().required(t('manage.sessionForms.sessionName')),
})
// ... other schemas

Example implementation for lazy loading:

const PracticeQuizInformationStep = lazy(() => import('./PracticeQuizInformationStep'))
const PracticeQuizDescriptionStep = lazy(() => import('./PracticeQuizDescriptionStep'))
// ... other steps
apps/frontend-manage/src/components/sessions/creation/microLearning/MicroLearningWizard.tsx (2)

82-84: Consider deriving stepValidity initialization from workflowItems.

While the explicit typing improves type safety, using a magic number (4) for array initialization makes the code brittle. Consider deriving the array length from workflowItems to maintain consistency.

- const [stepValidity, setStepValidity] = useState<boolean[]>(
-   Array(4).fill(!!initialValues)
- )
+ const [stepValidity, setStepValidity] = useState<boolean[]>(() => 
+   new Array(workflowItems.length).fill(!!initialValues)
+ )

193-213: Consider making the step-validity relationship more explicit.

The mapping between stepValidity indices and workflowItems is implicit. Consider using an enum or constants to make this relationship more maintainable and type-safe.

// Add at the top of the file
enum WizardStep {
  INFORMATION = 0,
  DESCRIPTION = 1,
  SETTINGS = 2,
  QUESTIONS = 3,
}

// Then in workflowItems
const workflowItems = [
  {
    title: t('shared.generic.information'),
    tooltip: t('manage.sessionForms.microLearningInformation'),
    completed: stepValidity[WizardStep.INFORMATION],
  },
  // ... rest of the items using WizardStep enum
]
apps/frontend-manage/src/components/sessions/creation/groupActivity/GroupActivityWizard.tsx (2)

84-86: LGTM! Consider const assertion for array length.

The explicit typing and initialization logic look good. For additional type safety, consider defining the number of steps as a const:

+const TOTAL_WIZARD_STEPS = 4 as const;
 const [stepValidity, setStepValidity] = useState<boolean[]>(
-  Array(4).fill(!!initialValues)
+  Array(TOTAL_WIZARD_STEPS).fill(!!initialValues)
 )

222-239: Enhance type safety for workflow items completion states.

While the completion states are correctly implemented, consider these improvements for better type safety and maintainability:

  1. Create a type for workflow items
  2. Add runtime validation to ensure stepValidity length matches workflow items
  3. Use tuple type for stepValidity to ensure exact length
type WorkflowItem = {
  title: string
  tooltip: string
  tooltipDisabled?: string
  completed: boolean
}

// Ensure exact length with tuple type
const [stepValidity, setStepValidity] = useState<[boolean, boolean, boolean, boolean]>(
  Array(4).fill(!!initialValues) as [boolean, boolean, boolean, boolean]
)

// Add runtime validation
if (workflowItems.length !== stepValidity.length) {
  console.error('Workflow items length does not match step validity length')
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d82f896 and a5fc918.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (16)
  • apps/auth/package.json (1 hunks)
  • apps/backend-docker/package.json (1 hunks)
  • apps/docs/package.json (1 hunks)
  • apps/frontend-control/package.json (1 hunks)
  • apps/frontend-manage/package.json (1 hunks)
  • apps/frontend-manage/src/components/sessions/creation/groupActivity/GroupActivityWizard.tsx (2 hunks)
  • apps/frontend-manage/src/components/sessions/creation/liveQuiz/LiveSessionWizard.tsx (2 hunks)
  • apps/frontend-manage/src/components/sessions/creation/microLearning/MicroLearningWizard.tsx (2 hunks)
  • apps/frontend-manage/src/components/sessions/creation/practiceQuiz/PracticeQuizWizard.tsx (2 hunks)
  • apps/frontend-pwa/package.json (1 hunks)
  • apps/func-incoming-responses/package.json (1 hunks)
  • apps/func-response-processor/package.json (1 hunks)
  • apps/office-addin/package.json (1 hunks)
  • packages/markdown/package.json (1 hunks)
  • packages/shared-components/package.json (1 hunks)
  • packages/transactional/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (8)
  • apps/auth/package.json
  • apps/backend-docker/package.json
  • apps/frontend-control/package.json
  • apps/frontend-pwa/package.json
  • apps/func-incoming-responses/package.json
  • apps/func-response-processor/package.json
  • packages/markdown/package.json
  • packages/transactional/package.json
🔇 Additional comments (6)
apps/docs/package.json (1)

24-24: LGTM! Verify documentation updates.

The dependency update to @uzh-bf/design-system@3.0.0-alpha.34 aligns with the PR's objective of enhancing workflow components.

Let's verify if the documentation for the new workflow completeness states exists:

packages/shared-components/package.json (1)

38-38: Version update looks consistent, but verify alpha version changes.

The update of @uzh-bf/design-system from 3.0.0-alpha.32 to 3.0.0-alpha.34 aligns with the PR objectives for enhancing workflow components. However, since this is an alpha version:

  1. Ensure you've reviewed the changelog between alpha.32 and alpha.34 for any breaking changes
  2. Consider setting up a migration plan to a stable release when available

Let's verify the consistency of this update across the monorepo:

✅ Verification successful

Version update is consistently applied across all packages

The verification confirms that @uzh-bf/design-system version 3.0.0-alpha.34 is consistently used across all package.json files in the monorepo:

  • 3 packages: transactional, shared-components, markdown
  • 9 apps: office-addin, func-response-processor, backend-docker, func-incoming-responses, frontend-pwa, auth, frontend-control, docs, frontend-manage
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent @uzh-bf/design-system version across all package.json files
# Expected: All occurrences should show version 3.0.0-alpha.34

# Search for @uzh-bf/design-system version declarations
rg -A 1 '"@uzh-bf/design-system":'

Length of output: 1780

apps/office-addin/package.json (1)

6-6: Verify compatibility with the design system update.

The update to @uzh-bf/design-system@3.0.0-alpha.34 looks good. However, since this is an alpha version update that includes workflow component changes:

  1. Please verify that the new workflow completeness states work correctly in your Office Add-in implementation
  2. Given your IE 11 support requirement, ensure the new features are compatible with legacy browsers

Let's check the changelog or commits for potential breaking changes:

apps/frontend-manage/package.json (2)

24-24: Verify breaking changes in design system upgrade.

Since this is an alpha version upgrade, please review the changelog of @uzh-bf/design-system for any breaking changes between alpha.32 and alpha.34, particularly around workflow components.

Let's check for a changelog:

#!/bin/bash
# Description: Look for changelog entries in design system
# Expected: Find changelog entries for versions alpha.32 to alpha.34

# Search for changelog files
fd -i changelog

# If not found directly, check README or docs
fd -e md -e mdx | xargs rg -i "changelog|breaking changes"

24-24: LGTM! Verify version consistency across workspace.

The version bump of @uzh-bf/design-system to 3.0.0-alpha.34 aligns with the PR objective to enhance workflow components.

Let's verify that all workspace packages use the same version:

✅ Verification successful

Version consistency verified across workspace

All packages in the workspace are using the same version 3.0.0-alpha.34 of @uzh-bf/design-system. The version bump is consistent across:

  • All frontend apps (manage, control, pwa)
  • Backend services and functions
  • Shared packages (components, markdown, transactional)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for version consistency of @uzh-bf/design-system across workspace
# Expected: All occurrences should show version 3.0.0-alpha.34

rg '"@uzh-bf/design-system": "([^"]+)"' -g 'package.json'

Length of output: 460


Script:

#!/bin/bash
# Let's try again with ripgrep to find @uzh-bf/design-system dependencies
# Using a different pattern that's more specific
rg -U '@uzh-bf/design-system.*"([0-9]+\.[0-9]+\.[0-9]+[^"]*)"' --type json

Length of output: 1041

apps/frontend-manage/src/components/sessions/creation/practiceQuiz/PracticeQuizWizard.tsx (1)

200-217: LGTM! Well-structured workflow step definitions.

The addition of the completed property to each workflow item, mapped to stepValidity indices, provides a clean way to track step completion. The tooltip system enhances user experience by providing clear feedback on both enabled and disabled states.

@sjschlapbach sjschlapbach merged commit 2e80627 into v3 Nov 8, 2024
24 of 26 checks passed
@sjschlapbach sjschlapbach deleted the wizard-workflow-states branch November 8, 2024 13:38
Copy link

cypress bot commented Nov 8, 2024

klicker-uzh    Run #3614

Run Properties:  status check passed Passed #3614  •  git commit 9bbc01e6a5 ℹ️: Merge a5fc918b0e7368917bc2a0e52b9462c2e31f643c into d82f89621a5b1faf25ca0748e5dc...
Project klicker-uzh
Branch Review wizard-workflow-states
Run status status check passed Passed #3614
Run duration 11m 54s
Commit git commit 9bbc01e6a5 ℹ️: Merge a5fc918b0e7368917bc2a0e52b9462c2e31f643c into d82f89621a5b1faf25ca0748e5dc...
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 140
View all changes introduced in this branch ↗︎

Copy link

cypress bot commented Nov 8, 2024

klicker-uzh    Run #3615

Run Properties:  status check passed Passed #3615  •  git commit 2e8062782c: enhance(apps/frontend-manage): add completeness states to workflow component in ...
Project klicker-uzh
Branch Review v3
Run status status check passed Passed #3615
Run duration 11m 22s
Commit git commit 2e8062782c: enhance(apps/frontend-manage): add completeness states to workflow component in ...
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 140
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