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

enhanced(ui): UI package extensions with components and calls in demo-game #47

Merged
merged 34 commits into from
Aug 12, 2024

Conversation

jajakob
Copy link
Collaborator

@jajakob jajakob commented Jul 31, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced UI with new components including Layout, PlayerDisplay, ProbabilityChart, TradingForm, and more.
    • Improved game list display with sorting and a new flex layout.
    • Added a new Achievement component to showcase user achievements.
    • Introduced a TradingForm for handling trading actions.
    • Added ProbabilityChart for visualizing dice roll probabilities.
    • New storage overview component to display storage metrics.
  • Bug Fixes

    • Adjusted spacing in player entries for better readability.
  • Improvements

    • Overall layout and design enhancements for better user experience across components.
    • Integrated new UI styles from the @gbl-uzh/ui package for a consistent look and feel.

Copy link

vercel bot commented Jul 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gbl-uzh ❌ Failed (Inspect) Aug 7, 2024 0:56am

Copy link
Contributor

coderabbitai bot commented Jul 31, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Base branches to auto review (4)
  • main
  • master
  • dev
  • v3

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The recent updates enhance the functionality and visual appeal of the demo game application. Key changes include the integration of the @gbl-uzh/ui package for improved styling and component usage, a restructured layout for several components to improve user experience, and the introduction of new components for displaying player data and game interactions. These modifications collectively create a more engaging and responsive user interface.

Changes

File(s) Change Summary
apps/demo-game/next.config.js Uncommented transpilePackages for @gbl-uzh/ui, enabling its transpilation.
apps/demo-game/src/components/... Redesigned layout for PlayerCompact, Games, and other components to enhance usability and organization.
apps/demo-game/src/globals.css Added import for @gbl-uzh/ui/dist/style.css to incorporate new styles.
apps/demo-game/src/pages/... Enhanced Home and Games components with new features and improved layouts.
packages/ui/package.json Added new dependencies to enhance functionality, including formik and recharts.
packages/ui/src/components/... Introduced new components like Achievement, Dice, TradingForm, and others to improve game interaction.
packages/ui/src/lib/constants.ts Added COLORS object for consistent styling management.
packages/ui/tsconfig.json Simplified path mapping for the TypeScript configuration.
packages/ui/vite.config.ts Updated Rollup config to treat react and react-dom as external dependencies.
turbo.json Modified dependencies to include @gbl-uzh/ui#build in the build process.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant GameLogic
    participant API

    User->>UI: Interacts with components
    UI->>GameLogic: Sends user actions (e.g., trading, player info)
    GameLogic->>API: Fetches game data
    API-->>GameLogic: Returns game state
    GameLogic-->>UI: Updates component with new data
    UI-->>User: Displays updated information
Loading

🐰 In the meadow, changes sprout,
New components, no room for doubt.
With colors bright and layouts neat,
The game now feels like a real treat! 🌼
Hops of joy with each new view,
A world of fun, all waiting for you! 🐇


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.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@jajakob jajakob requested a review from rschlaefli July 31, 2024 08:48
@jajakob jajakob self-assigned this Jul 31, 2024
@jajakob jajakob changed the title UI package and calls in demo-game chore(ui): UI package extensions with components and calls in demo-game Jul 31, 2024
@jajakob jajakob changed the title chore(ui): UI package extensions with components and calls in demo-game enhanced(ui): UI package extensions with components and calls in demo-game Jul 31, 2024
Copy link
Contributor

@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: 14

Outside diff range, codebase verification and nitpick comments (3)
packages/ui/src/components/XpBar.tsx (2)

3-6: Ensure prop types are validated.

The XpBarProps interface defines the props for the XpBar component. Ensure that the props are validated, especially if the component is used in a larger application.

Consider using PropTypes or TypeScript's type checking to ensure the props are correctly validated.


8-14: Lack of test coverage for XpBar component

The XpBar component is being used in the codebase but is not covered by any tests. It is important to add tests for this component to ensure its functionality is properly verified.

  • packages/ui/src/components/PlayerDisplay.tsx: The component is used here but not tested.
Analysis chain

LGTM! Ensure proper usage and testing.

The XpBar component is correctly implemented using the Progress component. Ensure that the component is properly used and tested in the application.

However, ensure that the component is being used correctly in the codebase and is covered by tests.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `XpBar` component in the codebase.

# Test: Search for the component usage. Expect: Occurrences of the component being imported and used.
rg --type js --type ts --type jsx --type tsx 'XpBar'

Length of output: 80


Script:

#!/bin/bash
# Description: Verify the usage of the `XpBar` component in the codebase.

# Test: Search for the component usage. Expect: Occurrences of the component being imported and used.
rg --type js --type ts --type tsx 'XpBar'

Length of output: 69


Script:

#!/bin/bash
# Description: Verify the usage of the `XpBar` component in the codebase.

# Test: Search for the component usage. Expect: Occurrences of the component being imported and used.
rg 'XpBar' --glob '*.{js,ts,tsx}'

Length of output: 495


Script:

#!/bin/bash
# Description: Verify the test coverage for the `XpBar` component in the codebase.

# Test: Search for test files or test cases that include the `XpBar` component.
rg 'XpBar' --glob '*.{js,ts,tsx}' --glob 'test/**/*' --glob '**/*.test.*' --glob '**/__tests__/**/*'

Length of output: 562

packages/ui/src/components/ProbabilityChart.tsx (1)

92-157: The ProbabilityChart component is not tested.

The absence of tests for the ProbabilityChart component is a significant issue. Please ensure that the component is properly tested to verify its rendering logic and functionality.

  • Add unit tests for the ProbabilityChart component.
  • Ensure that the component's rendering logic is covered by the tests.
Analysis chain

Ensure the ProbabilityChart component is working correctly.

The component uses the distribution volatility function and renders a bar chart. Verify the correctness of the rendering logic and ensure the component is tested.


Let's correct the file type and search for the ProbabilityChart component usage within TypeScript/JavaScript files.


Let's search for any test files related to index.tsx or ProbabilityChart to ensure the component is tested.


Let's search for any test files in the entire codebase to confirm if the ProbabilityChart component is covered indirectly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the ProbabilityChart component rendering logic.

# Test: Search for the component usage. Expect: Correctness of the rendering logic.
rg --type python -A 5 $'ProbabilityChart'

Length of output: 71


Script:

#!/bin/bash
# Description: Verify the ProbabilityChart component rendering logic.

# Test: Search for the component usage. Expect: Correctness of the rendering logic.
rg --type js --type ts -A 5 'ProbabilityChart'

Length of output: 1915


Script:

#!/bin/bash
# Description: Verify if the ProbabilityChart component is tested.

# Search for test files related to index.tsx or ProbabilityChart.
rg --type js --type ts -l 'ProbabilityChart' | grep -E 'test|spec'

Length of output: 66


Script:

#!/bin/bash
# Description: Verify if the ProbabilityChart component is tested indirectly.

# Search for test files in the entire codebase.
fd -e js -e ts | grep -E 'test|spec'

Length of output: 38

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dc0c305 and f04a645.

Files ignored due to path filters (3)
  • apps/demo-game/public/avatars/avatar_placeholder.png is excluded by !**/*.png
  • apps/demo-game/public/locations/ZH.svg is excluded by !**/*.svg
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (25)
  • apps/demo-game/next.config.js (1 hunks)
  • apps/demo-game/src/components/PlayerCompact.tsx (1 hunks)
  • apps/demo-game/src/globals.css (1 hunks)
  • apps/demo-game/src/pages/admin/games.tsx (1 hunks)
  • apps/demo-game/src/pages/admin/games/[id].tsx (1 hunks)
  • apps/demo-game/src/pages/index.tsx (1 hunks)
  • packages/ui/package.json (2 hunks)
  • packages/ui/src/components/Achievement.tsx (1 hunks)
  • packages/ui/src/components/Dice.tsx (1 hunks)
  • packages/ui/src/components/Layout.tsx (1 hunks)
  • packages/ui/src/components/ListItem.tsx (1 hunks)
  • packages/ui/src/components/Logo.tsx (1 hunks)
  • packages/ui/src/components/NavBar.tsx (1 hunks)
  • packages/ui/src/components/PlayerDisplay.tsx (1 hunks)
  • packages/ui/src/components/ProbabilityChart.tsx (1 hunks)
  • packages/ui/src/components/StorageOverview.tsx (1 hunks)
  • packages/ui/src/components/Timeline.tsx (1 hunks)
  • packages/ui/src/components/TimelineEntry.tsx (1 hunks)
  • packages/ui/src/components/TradingForm.tsx (1 hunks)
  • packages/ui/src/components/XpBar.tsx (1 hunks)
  • packages/ui/src/index.ts (1 hunks)
  • packages/ui/src/lib/constants.ts (1 hunks)
  • packages/ui/tsconfig.json (1 hunks)
  • packages/ui/vite.config.ts (1 hunks)
  • turbo.json (1 hunks)
Files skipped from review due to trivial changes (4)
  • apps/demo-game/src/globals.css
  • apps/demo-game/src/pages/admin/games/[id].tsx
  • packages/ui/src/lib/constants.ts
  • packages/ui/tsconfig.json
Additional context used
Biome
packages/ui/src/components/NavBar.tsx

[error] 22-22: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

packages/ui/src/components/Timeline.tsx

[error] 64-64: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

Additional comments not posted (50)
apps/demo-game/next.config.js (1)

12-12: LGTM! Verify the package usage.

The transpilePackages line has been uncommented to include @gbl-uzh/ui in the build process. This change ensures that the package is properly transpiled during the build, which is necessary for compatibility and feature usage.

However, ensure that the package is being used correctly in the codebase.

Verification successful

Package usage verified.

The @gbl-uzh/ui package is being correctly imported and utilized in the Home component within apps/demo-game/src/pages/index.tsx.

  • apps/demo-game/src/pages/index.tsx: The components from @gbl-uzh/ui are imported and used within the Home component.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `@gbl-uzh/ui` package in the codebase.

# Test: Search for the package usage. Expect: Occurrences of the package being imported and used.
rg --type js --type ts --type jsx --type tsx '@gbl-uzh/ui'

Length of output: 86


Script:

#!/bin/bash
# Description: Verify the usage of the `@gbl-uzh/ui` package in the codebase.

# Define jsx and tsx file types for ripgrep
rg --type-add 'jsx:*.jsx' --type-add 'tsx:*.tsx' --type js --type ts --type jsx --type tsx '@gbl-uzh/ui'

Length of output: 228


Script:

#!/bin/bash
# Extract lines around the import statement in index.tsx to verify usage
rg --type tsx --context 10 '@gbl-uzh/ui' apps/demo-game/src/pages/index.tsx

Length of output: 103


Script:

#!/bin/bash
# Define tsx file type and extract lines around the import statement in index.tsx to verify usage
rg --type-add 'tsx:*.tsx' --type tsx --context 10 '@gbl-uzh/ui' apps/demo-game/src/pages/index.tsx

Length of output: 450

packages/ui/src/components/XpBar.tsx (1)

1-1: LGTM! Verify the package usage.

The Progress component is imported from @uzh-bf/design-system. Ensure that the package is correctly installed and used.

However, ensure that the package is being used correctly in the codebase.

turbo.json (1)

25-26: LGTM! Verify the dependency usage.

The dependsOn section has been modified to include @gbl-uzh/ui#build. This change ensures that the project builds correctly with the new UI components.

However, ensure that the dependency is being used correctly in the codebase.

Verification successful

Dependency usage verified.

The @gbl-uzh/ui#build dependency is being used correctly in the codebase as evidenced by its presence in various configuration files, source files, and style imports.

  • turbo.json
  • pnpm-lock.yaml
  • packages/ui/package.json
  • apps/demo-game/next.config.js
  • apps/demo-game/src/globals.css
  • apps/demo-game/src/pages/index.tsx
  • apps/demo-game/package.json
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `@gbl-uzh/ui#build` dependency in the codebase.

# Test: Search for the dependency usage. Expect: Occurrences of the dependency being used in the build process.
rg --type json '@gbl-uzh/ui#build'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify the usage of the `@gbl-uzh/ui` dependency in the codebase.

# Test: Search for the dependency usage across the entire codebase. Expect: Occurrences of the dependency being used in build scripts, configuration files, or source code.
rg '@gbl-uzh/ui'

Length of output: 396

packages/ui/vite.config.ts (2)

16-16: LGTM! Including react-dom as an external dependency.

This change ensures react-dom is treated as an external dependency, which can help reduce the bundle size.


17-22: LGTM! Defining global variable mappings for react and react-dom.

Uncommenting and modifying the output section ensures that both React libraries are correctly recognized and referenced in the UMD build, improving compatibility.

packages/ui/src/index.ts (3)

2-11: LGTM! Importing new UI components.

These imports enhance the modularity and reusability of the UI components.


14-25: LGTM! Exporting new UI components.

These exports make the new UI components available for use in other parts of the application.


26-26: LGTM! Commented-out export for Dice.

This comment suggests that the Dice component might be under consideration for future inclusion or removal.

packages/ui/src/components/Achievement.tsx (3)

1-6: LGTM! Defining AchievementProps interface.

The interface defines the expected properties and their types, ensuring type safety.


8-24: LGTM! Implementing Achievement component.

The component uses the properties to render an achievement badge with the name, XP reward, image, and count. The usage of Tailwind CSS classes ensures a responsive design.


27-27: LGTM! Exporting Achievement component.

This change makes the Achievement component available for use in other parts of the application.

packages/ui/src/components/TimelineEntry.tsx (1)

17-47: LGTM!

The TimelineEntry component is well-structured and uses Tailwind CSS for styling. The props and class names are used correctly.

apps/demo-game/src/components/PlayerCompact.tsx (1)

12-34: LGTM!

The PlayerCompact component is well-structured with improved layout and readability. The flexbox layout enhances the visual hierarchy and alignment of player information.

packages/ui/src/components/Layout.tsx (1)

1-45: LGTM!

The Layout component is well-structured and uses Tailwind CSS for styling. The props and class names are used correctly.

packages/ui/package.json (10)

17-17: Peer Dependency Addition Approved: @radix-ui/react-avatar.

The addition of @radix-ui/react-avatar with version ^1.1.0 is appropriate for enhancing avatar components.


21-21: Peer Dependency Addition Approved: react-dice-complete.

The addition of react-dice-complete with version 2.2.0 is appropriate for enhancing dice rolling components.


27-27: Dev Dependency Addition Approved: @types/react-dom.

The addition of @types/react-dom with version ^18.3.0 is appropriate for improving type safety and development experience.


46-46: Dependency Addition Approved: @fortawesome/free-solid-svg-icons.

The addition of @fortawesome/free-solid-svg-icons with version 6.4.2 is appropriate for enhancing the visual appeal of the UI components.


47-47: Dependency Addition Approved: @fortawesome/react-fontawesome.

The addition of @fortawesome/react-fontawesome with version 0.2.0 is appropriate for enhancing the visual appeal of the UI components.


48-48: Dependency Addition Approved: @types/ramda.

The addition of @types/ramda with version ^0.28.25 is appropriate for improving type safety and development experience.


49-49: Dependency Addition Approved: formik.

The addition of formik with version 2.4.3 is appropriate for enhancing form handling capabilities in React.


50-50: Dependency Addition Approved: next.

The addition of next with version ^14.2.5 is appropriate for enhancing the performance and SEO of the application through server-side rendering and static site generation.


51-51: Dependency Addition Approved: ramda.

The addition of ramda with version 0.29.0 is appropriate for enhancing the functional programming capabilities of the codebase.


52-52: Dependency Addition Approved: recharts.

The addition of recharts with version 2.8.0 is appropriate for enhancing the data visualization capabilities of the application.

packages/ui/src/components/PlayerDisplay.tsx (1)

32-61: LGTM! Well-structured return statement.

The return statement of the PlayerDisplay component is well-structured and uses appropriate JSX elements and class names.

packages/ui/src/components/Logo.tsx (3)

6-13: LGTM! Well-defined props.

The props for the Logo component are well-defined and appropriate for the component.


23-52: LGTM! Well-structured return statement.

The return statement of the Logo component is well-structured and uses appropriate JSX elements and class names.


25-28: LGTM! Appropriate usage of twMerge.

The usage of twMerge to merge Tailwind CSS class names is appropriate and well-implemented.

packages/ui/src/components/StorageOverview.tsx (3)

15-24: Memoize storageEmpty calculation.

The useMemo hook is correctly used to memoize the calculation of storageEmpty.


1-3: Remove unused imports.

The twMerge import is used, but ensure all imports are necessary. If not, remove unused imports to keep the code clean.


8-13: Ensure prop types are correctly defined.

The props interface is clear, but ensure storageUsed and storageTotal are always numbers and imgPathEmpty and imgPathFull are valid URLs or paths.

Verification successful

Prop types are correctly defined and used.

The props storageUsed and storageTotal are passed as numbers, and imgPathEmpty and imgPathFull are passed as valid string paths, as expected.

  • packages/ui/src/components/Layout.tsx
  • apps/demo-game/src/pages/index.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the prop types for `StorageOverview`.

# Test: Search for the usage of `StorageOverview`. Expect: Correct types passed.
rg --type tsx 'StorageOverview'

Length of output: 59


Script:

#!/bin/bash
# Description: Find all .tsx files and search for the usage of `StorageOverview` within those files.

# Find all .tsx files
fd --extension tsx > tsx_files.txt

# Search for the usage of `StorageOverview` within those files
while IFS= read -r file; do
  rg 'StorageOverview' "$file"
done < tsx_files.txt

Length of output: 5020


Script:

#!/bin/bash
# Description: Extract and display lines where `StorageOverview` is used, with context.

# Search for the usage of `StorageOverview` and display 5 lines before and after each match.
rg 'StorageOverview' -A 5 -B 5 apps/demo-game/src/pages/index.tsx packages/ui/src/components/Layout.tsx

Length of output: 2429

packages/ui/src/components/TradingForm.tsx (3)

10-15: Ensure currency formatting is correct.

The optionalValueToCHFString function correctly formats numbers to CHF currency. Ensure this function is used consistently where needed.


27-34: Default prop values are correctly set.

The default values for disableButtonA and disableButtonB are set correctly.


18-25: Ensure prop types are correctly defined.

The props interface is clear, but ensure all props are passed correctly and are of the expected types.

Verification successful

Prop types are correctly defined and used.

The TradingForm component is used with the correct prop types in apps/demo-game/src/pages/index.tsx.

  • price is passed as a number.
  • nameButtonA and nameButtonB are passed as strings.
  • onSubmit is passed as a function with the expected signature.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the prop types for `TradingForm`.

# Test: Search for the usage of `TradingForm`. Expect: Correct types passed.
rg --type tsx 'TradingForm'

Length of output: 55


Script:

#!/bin/bash
# Description: Verify the prop types for `TradingForm`.

# Test: Search for the usage of `TradingForm`. Expect: Correct types passed.
rg 'TradingForm' --type-add 'tsx:*.{ts,tsx,js}'

Length of output: 462


Script:

#!/bin/bash
# Extract the relevant lines where `TradingForm` is used in `apps/demo-game/src/pages/index.tsx`

rg 'TradingForm' -A 5 apps/demo-game/src/pages/index.tsx

Length of output: 354

packages/ui/src/components/Timeline.tsx (9)

95-100: Ensure smooth scrolling works as expected.

The useEffect hook ensures smooth scrolling to the current entry. Verify this works as expected.


1-3: Remove unused imports.

Ensure all imports are necessary. If not, remove unused imports to keep the code clean.


5-10: Ensure prop types are correctly defined.

The Segment interface is clear, but ensure facts is correctly typed and used.


39-51: Ensure prop types are correctly defined.

The props for Timeline are clear, but ensure all props are passed correctly and are of the expected types.

Verification successful

Ensure prop types are correctly defined.

The Timeline component is used with the correct prop types in the codebase. The props periods, entries, activePeriodIx, activeSegmentIx, and formatter are passed as expected.

  • The periods prop is passed an array of objects with segments.
  • The entries prop is passed an array of data items.
  • The activePeriodIx and activeSegmentIx props are passed as numbers.
  • The formatter prop is passed as a function.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the prop types for `Timeline`.

# Test: Search for the usage of `Timeline`. Expect: Correct types passed.
rg --type tsx 'Timeline'

Length of output: 52


Script:

#!/bin/bash
# Description: Verify the prop types for `Timeline`.

# Find all .tsx files and search for the usage of `Timeline` component within those files.
fd --type f --extension tsx --exec rg 'Timeline' {}

Length of output: 342


Script:

#!/bin/bash
# Description: Verify the prop types for `Timeline`.

# Search for the usage of `Timeline` component and include surrounding lines for context.
fd --type f --extension tsx --exec rg 'Timeline' -A 5 -B 5 {}

Length of output: 2146


34-37: Ensure prop types are correctly defined.

The DataProps interface is clear, but ensure facts is correctly typed and used.


12-16: Ensure prop types are correctly defined.

The Period interface is clear, but ensure facts is correctly typed and used.

Verification successful

Ensure prop types are correctly defined.

The facts property in the Period interface is consistently typed as any or JSONObject across the codebase. This appears to be intentional. If a more specific type is required for facts, consider defining and using a dedicated type.

  • packages/ui/src/components/Timeline.tsx (lines 12-16)
  • packages/platform/src/types/Game.ts
  • apps/demo-game/src/types/Period.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the prop types for `Period`.

# Test: Search for the usage of `Period`. Expect: Correct types passed.
rg --type tsx 'Period'

Length of output: 50


Script:

#!/bin/bash
# Description: Verify the prop types for `Period`.

# Test: Search for the usage of `Period` in TypeScript files.
rg 'Period' -g '*.ts' -g '*.tsx' -A 5

Length of output: 202261


18-32: Ensure prop types are correctly defined.

The Entry interface is clear, but ensure facts is correctly typed and used.


69-90: Ensure correct handling of entry types.

The handling of entry types is clear, but ensure all possible types are covered and handled correctly.


102-122: Ensure unique keys for repeated elements.

Ensure unique keys for repeated elements to avoid rendering issues.

Verification successful

Keys for repeated elements are unique.

The combination of item.period.index and item.segment?.index ensures unique keys for the repeated elements in the Timeline component.

  • item.period.index and item.segment?.index are used to uniquely identify periods and segments, respectively.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify unique keys for repeated elements.

# Test: Search for the usage of `key` in the map function. Expect: Unique keys.
rg --type tsx 'key='

Length of output: 48


Script:

#!/bin/bash
# Description: Verify unique keys for repeated elements in Timeline.tsx.

# Test: Search for the usage of `key` in the map function within Timeline.tsx. Expect: Unique keys.
rg 'key=' packages/ui/src/components/Timeline.tsx

Length of output: 113


Script:

#!/bin/bash
# Description: Verify the structure and definition of `data` to ensure unique keys.

# Search for the definition of `data` in Timeline.tsx.
rg 'data' packages/ui/src/components/Timeline.tsx

# Search for the definition of `item.period.index` and `item.segment?.index` in the codebase to understand their uniqueness.
rg 'period.index' packages/ui/src/components/Timeline.tsx
rg 'segment?.index' packages/ui/src/components/Timeline.tsx

Length of output: 574


Script:

#!/bin/bash
# Description: Verify the structure and definition of `data`, `period`, and `segment` to ensure unique keys.

# Search for the structure and definition of `data` in Timeline.tsx.
rg 'const data' packages/ui/src/components/Timeline.tsx

# Search for the structure and definition of `period` in Timeline.tsx.
rg 'period' packages/ui/src/components/Timeline.tsx

# Search for the structure and definition of `segment` in Timeline.tsx.
rg 'segment' packages/ui/src/components/Timeline.tsx

Length of output: 1373

apps/demo-game/src/pages/admin/games.tsx (3)

97-99: Ensure the Flexbox layout is appropriate.

The change from a grid to a flexbox layout improves control over alignment and spacing. Ensure this change aligns with the overall design and responsiveness requirements.


100-115: Enhanced game information display looks good.

The enhanced display includes game ID, active period index, and status, improving readability and completeness.


99-99: Verify sorting logic correctness.

The sorting logic ensures that games are displayed in descending order by ID. Verify that the IDs are always numeric and the sorting works as expected.

Verification successful

Sorting logic is correct.

The id field in the Game type is defined as a string, but the sorting logic correctly converts these IDs to numbers before sorting. This ensures that the games are displayed in descending order by their numeric IDs.

  • apps/demo-game/src/graphql/generated/ops.ts: export type Game = { id: string, ... }
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that game IDs are numeric and sorting works as expected.

# Test: Search for game ID usage. Expect: IDs are numeric.
rg --type python -A 5 $'game.id'

Length of output: 62


Script:

#!/bin/bash
# Description: Verify that game IDs are numeric and sorting works as expected.

# Test: Search for game ID usage in TypeScript files. Expect: IDs are numeric.
rg --type ts -A 5 'game.id'

Length of output: 4387


Script:

#!/bin/bash
# Description: Verify that game IDs are numeric and sorting works as expected.

# Test: Search for the type definition or assignment of game.id in the relevant TypeScript files. Expect: IDs are numeric.
rg --type ts 'game.id'

Length of output: 848


Script:

#!/bin/bash
# Description: Verify that game IDs are numeric and sorting works as expected.

# Test: Search for the type definition or assignment of game.id in the relevant TypeScript files. Expect: IDs are numeric.
rg 'id' apps/demo-game/src/pages/admin/games.tsx

Length of output: 285


Script:

#!/bin/bash
# Description: Verify that game IDs are numeric and sorting works as expected.

# Test: Search for the type definition of the game object in the relevant TypeScript files. Expect: IDs are numeric.
rg 'type Game' --type ts

Length of output: 1984

packages/ui/src/components/ProbabilityChart.tsx (1)

32-74: Ensure correctness of distribution volatility calculation.

The function calculates the expected value and volatility of the distribution. Verify the correctness of the calculations and consider adding comments to explain the logic.

apps/demo-game/src/pages/index.tsx (3)

1-9: Ensure the imported components are used correctly.

The imports from the @gbl-uzh/ui library must be checked for correctness and relevance.


47-179: Ensure the new components are working correctly.

The new components such as ProbabilityChart, TimelineEntry, Timeline, and TradingForm must be checked for correctness and performance. Ensure these components are tested.

Verification successful

The new components are working correctly.

The components ProbabilityChart, TimelineEntry, Timeline, and TradingForm are correctly imported and used in apps/demo-game/src/pages/index.tsx. Their definitions in packages/ui/src/components/ align with their usage.

  • ProbabilityChart is defined in packages/ui/src/components/ProbabilityChart.tsx.
  • TimelineEntry is defined in packages/ui/src/components/TimelineEntry.tsx.
  • Timeline is defined in packages/ui/src/components/Timeline.tsx.
  • TradingForm is defined in packages/ui/src/components/TradingForm.tsx.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new components rendering logic.

# Test: Search for the components usage. Expect: Correctness of the rendering logic.
rg --type python -A 5 $'ProbabilityChart|TimelineEntry|Timeline|TradingForm'

Length of output: 108


Script:

#!/bin/bash
# Description: Verify the new components rendering logic.

# Test: Search for the components usage. Expect: Correctness of the rendering logic.
rg --type ts -A 5 $'ProbabilityChart|TimelineEntry|Timeline|TradingForm'

Length of output: 5858


14-38: Ensure the Home component is working correctly.

The Home component includes new UI elements such as PlayerDisplay and StorageOverview. Verify the correctness of the rendering logic and ensure the component is tested.

Verification successful

The Home component is working correctly.

The Home component includes new UI elements such as PlayerDisplay and StorageOverview. The rendering logic for these components is correctly implemented.

  • apps/demo-game/src/pages/index.tsx: Verified the usage and rendering logic of PlayerDisplay and StorageOverview within the Home component.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Home component rendering logic.

# Test: Search for the component usage. Expect: Correctness of the rendering logic.
rg --type python -A 5 $'Home'

Length of output: 59


Script:

#!/bin/bash
# Description: Verify the Home component rendering logic in TypeScript files.

# Test: Search for the Home component usage in TypeScript files.
rg --type tsx -A 5 'Home'

# Test: Verify the rendering logic of PlayerDisplay and StorageOverview within the Home component.
rg --type tsx -A 10 'PlayerDisplay' apps/demo-game/src/pages/index.tsx
rg --type tsx -A 10 'StorageOverview' apps/demo-game/src/pages/index.tsx

Length of output: 253


Script:

#!/bin/bash
# Description: Verify the Home component rendering logic in TypeScript files.

# Test: Search for the Home component usage in TypeScript files.
rg --type typescript -A 5 'Home'

# Test: Verify the rendering logic of PlayerDisplay and StorageOverview within the Home component.
rg --type typescript -A 10 'PlayerDisplay' apps/demo-game/src/pages/index.tsx
rg --type typescript -A 10 'StorageOverview' apps/demo-game/src/pages/index.tsx

Length of output: 295


Script:

#!/bin/bash
# Description: Verify the Home component rendering logic in TypeScript files.

# Test: Search for the Home component usage in TypeScript and TypeScript React files.
rg --type ts --type tsx -A 5 'Home'

# Test: Verify the rendering logic of PlayerDisplay and StorageOverview within the Home component.
rg --type ts --type tsx -A 10 'PlayerDisplay' apps/demo-game/src/pages/index.tsx
rg --type ts --type tsx -A 10 'StorageOverview' apps/demo-game/src/pages/index.tsx

Length of output: 283


Script:

#!/bin/bash
# Description: Verify the Home component rendering logic in the codebase.

# Test: Search for the Home component usage in the codebase.
rg -A 5 'Home'

# Test: Verify the rendering logic of PlayerDisplay and StorageOverview within the Home component.
rg -A 10 'PlayerDisplay' apps/demo-game/src/pages/index.tsx
rg -A 10 'StorageOverview' apps/demo-game/src/pages/index.tsx

Length of output: 17075

packages/ui/src/components/TimelineEntry.tsx Outdated Show resolved Hide resolved
apps/demo-game/src/components/PlayerCompact.tsx Outdated Show resolved Hide resolved
packages/ui/src/components/ListItem.tsx Outdated Show resolved Hide resolved
packages/ui/src/components/ListItem.tsx Outdated Show resolved Hide resolved
packages/ui/src/components/Dice.tsx Outdated Show resolved Hide resolved
packages/ui/src/components/PlayerDisplay.tsx Outdated Show resolved Hide resolved
packages/ui/src/components/PlayerDisplay.tsx Outdated Show resolved Hide resolved
Comment on lines 18 to 30
const PROB: { [key: string]: number } = {
2: 0.0278,
3: 0.0556,
4: 0.0833,
5: 0.1111,
6: 0.1389,
7: 0.1667,
8: 0.1389,
9: 0.1111,
10: 0.0833,
11: 0.0556,
12: 0.0278,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider externalizing the probability distribution.

The probability distribution is hardcoded. Consider externalizing it to a configuration file or a constant module for better maintainability.

- const PROB: { [key: string]: number } = {
-   2: 0.0278,
-   3: 0.0556,
-   4: 0.0833,
-   5: 0.1111,
-   6: 0.1389,
-   7: 0.1667,
-   8: 0.1389,
-   9: 0.1111,
-   10: 0.0833,
-   11: 0.0556,
-   12: 0.0278,
- }
+ import PROB from 'path_to_constants_module'
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const PROB: { [key: string]: number } = {
2: 0.0278,
3: 0.0556,
4: 0.0833,
5: 0.1111,
6: 0.1389,
7: 0.1667,
8: 0.1389,
9: 0.1111,
10: 0.0833,
11: 0.0556,
12: 0.0278,
}
import PROB from 'path_to_constants_module'

Comment on lines 36 to 101
<div className="flex w-max gap-4 rounded border p-8">
<Formik
initialValues={{
modifier: 1,
volume: 0,
}}
isInitialValid={false}
// validationSchema={yup.object({
// volume: yup.number().min(1).required(),
// })}
onSubmit={onSubmit}
>
{(tradeInterface: any) => (
<Form className="">
<FormikTextField
min={0}
type="number"
label="Volume"
name="volume"
/>
<div className="mt-2">
Trading {tradeInterface.values.volume}T for{' '}
{optionalValueToCHFString(tradeInterface.values.volume * price)}
</div>

{/* {!sufficientFunds && !sufficientStorage && (
<UserNotification
type="errornotificationType"
message="You do not have the funds or goods to trade this volume."
/>
)} */}

<div className="mt-2 flex flex-row gap-2">
<Button
disabled={
tradeInterface.isSubmitting ||
!tradeInterface.isValid ||
disableButtonA
}
type="button"
onClick={async () => {
await tradeInterface.setFieldValue('modifier', 1)
tradeInterface.handleSubmit()
}}
>
{nameButtonA}
</Button>
<Button
disabled={
tradeInterface.isSubmitting ||
!tradeInterface.isValid ||
disableButtonB
}
type="button"
onClick={async () => {
await tradeInterface.setFieldValue('modifier', -1)
tradeInterface.handleSubmit()
}}
>
{nameButtonB}
</Button>
</div>
</Form>
)}
</Formik>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve form validation and error handling.

  1. Uncomment and use the yup validation schema for better form validation.
  2. Ensure proper error handling and user notifications.
- // validationSchema={yup.object({
- //   volume: yup.number().min(1).required(),
- // })}
+ validationSchema={yup.object({
+   volume: yup.number().min(1).required(),
+ })}
- {/* {!sufficientFunds && !sufficientStorage && (
- <UserNotification
-   type="errornotificationType"
-   message="You do not have the funds or goods to trade this volume."
- />
- )} */}
+ {!sufficientFunds && !sufficientStorage && (
+ <UserNotification
+   type="error"
+   message="You do not have the funds or goods to trade this volume."
+ />
+ )}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className="flex w-max gap-4 rounded border p-8">
<Formik
initialValues={{
modifier: 1,
volume: 0,
}}
isInitialValid={false}
// validationSchema={yup.object({
// volume: yup.number().min(1).required(),
// })}
onSubmit={onSubmit}
>
{(tradeInterface: any) => (
<Form className="">
<FormikTextField
min={0}
type="number"
label="Volume"
name="volume"
/>
<div className="mt-2">
Trading {tradeInterface.values.volume}T for{' '}
{optionalValueToCHFString(tradeInterface.values.volume * price)}
</div>
{/* {!sufficientFunds && !sufficientStorage && (
<UserNotification
type="errornotificationType"
message="You do not have the funds or goods to trade this volume."
/>
)} */}
<div className="mt-2 flex flex-row gap-2">
<Button
disabled={
tradeInterface.isSubmitting ||
!tradeInterface.isValid ||
disableButtonA
}
type="button"
onClick={async () => {
await tradeInterface.setFieldValue('modifier', 1)
tradeInterface.handleSubmit()
}}
>
{nameButtonA}
</Button>
<Button
disabled={
tradeInterface.isSubmitting ||
!tradeInterface.isValid ||
disableButtonB
}
type="button"
onClick={async () => {
await tradeInterface.setFieldValue('modifier', -1)
tradeInterface.handleSubmit()
}}
>
{nameButtonB}
</Button>
</div>
</Form>
)}
</Formik>
</div>
<div className="flex w-max gap-4 rounded border p-8">
<Formik
initialValues={{
modifier: 1,
volume: 0,
}}
isInitialValid={false}
validationSchema={yup.object({
volume: yup.number().min(1).required(),
})}
onSubmit={onSubmit}
>
{(tradeInterface: any) => (
<Form className="">
<FormikTextField
min={0}
type="number"
label="Volume"
name="volume"
/>
<div className="mt-2">
Trading {tradeInterface.values.volume}T for{' '}
{optionalValueToCHFString(tradeInterface.values.volume * price)}
</div>
{!sufficientFunds && !sufficientStorage && (
<UserNotification
type="error"
message="You do not have the funds or goods to trade this volume."
/>
)}
<div className="mt-2 flex flex-row gap-2">
<Button
disabled={
tradeInterface.isSubmitting ||
!tradeInterface.isValid ||
disableButtonA
}
type="button"
onClick={async () => {
await tradeInterface.setFieldValue('modifier', 1)
tradeInterface.handleSubmit()
}}
>
{nameButtonA}
</Button>
<Button
disabled={
tradeInterface.isSubmitting ||
!tradeInterface.isValid ||
disableButtonB
}
type="button"
onClick={async () => {
await tradeInterface.setFieldValue('modifier', -1)
tradeInterface.handleSubmit()
}}
>
{nameButtonB}
</Button>
</div>
</Form>
)}
</Formik>
</div>

packages/ui/src/components/Timeline.tsx Outdated Show resolved Hide resolved
@jajakob jajakob changed the base branch from dev to jakob/demo-game-extensions July 31, 2024 08:55
@jajakob jajakob force-pushed the jakob/demo-game-extensions branch from 7ead421 to 8818bcb Compare July 31, 2024 11:41
@jajakob jajakob force-pushed the jakob/uicomponents branch from f04a645 to 97318ca Compare July 31, 2024 12:02
@jajakob jajakob force-pushed the jakob/demo-game-extensions branch from 9abf256 to b1d786c Compare July 31, 2024 12:11
Copy link

sonarqubecloud bot commented Aug 7, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@jajakob jajakob merged commit c964a36 into jakob/demo-game-extensions Aug 12, 2024
1 of 3 checks passed
@jajakob jajakob deleted the jakob/uicomponents branch August 12, 2024 13:09
jajakob added a commit that referenced this pull request Aug 14, 2024
…-game (#47)

* Adding dice as ui component

* added logo component

* Probability chart, tooltip missing, input could be extended

* fix css and Logo component

* generalize playerDisplay, Logo/Avatar

* adding xp bar

* Storage Overview adapting height size

* adjusted some todos for timeline entry

* timeline

* Trading

* adding price to trading form

* adding navbar

* sidebar structure

* remove duplicate style imports

* pin next peer dep in ui package

* remove redundant type in formik

* customize period and segment names in timeline entry

* remove redundant key reference in object

* add strings and booleans directly in components (here layout)

* direct inference of booleans in timeline entry

* some clean up

* remove hard-coded number of segments in timeline

* refining layout

* storage overview fallback if no images are provided

* rounded edges for avatar

* timeline admin prep

* change avatar to button

* providing react nodes for icons in storage overview

* trading form validation schema with yup

* TimelineEntry entryStatus, past, current and future

* adding segmentCount to periods in db and for fetching

* avoid spread syntax on accumulators

* providing types for achievements

* cleaning up rest of todos and comments for segment count and filtering

---------

Co-authored-by: Roland Schläfli <[email protected]>
jajakob added a commit that referenced this pull request Aug 22, 2024
* Adding dice as ui component

* added logo component

* adding player display as ui component

* some refinements for PlayerDisplay

* changing logo back to absolute positions, something is off

* adding achievement as component

* StorageOverview

* Probability chart, tooltip missing, input could be extended

* timeline entry

* adding timeline, not generic yet

* sort game list and beautify

* new player list visualization, needs to be moved to ui

* demo-game: initial modification of welcome page

* demo-game: initial display player

* Adding dice as ui component

* added logo component

* some refinements for PlayerDisplay

* changing logo back to absolute positions, something is off

* Probability chart, tooltip missing, input could be extended

* remove react types in tsconfig

* demo-game fixing transformer in cockpit

* order on db side when querying games

* remove indices when showing list of games

* removing redundant key tags in children

* wrap game links into buttons

* wrap button into link

* fix old typo

* added todo to welcome page

* demo-game: refetchQueries and cleaning cockpit

* adding player count and activeSegmentIx in data game for showing info

* starting showing transactions

* enhanced(ui): UI package extensions with components and calls in demo-game (#47)

* Adding dice as ui component

* added logo component

* Probability chart, tooltip missing, input could be extended

* fix css and Logo component

* generalize playerDisplay, Logo/Avatar

* adding xp bar

* Storage Overview adapting height size

* adjusted some todos for timeline entry

* timeline

* Trading

* adding price to trading form

* adding navbar

* sidebar structure

* remove duplicate style imports

* pin next peer dep in ui package

* remove redundant type in formik

* customize period and segment names in timeline entry

* remove redundant key reference in object

* add strings and booleans directly in components (here layout)

* direct inference of booleans in timeline entry

* some clean up

* remove hard-coded number of segments in timeline

* refining layout

* storage overview fallback if no images are provided

* rounded edges for avatar

* timeline admin prep

* change avatar to button

* providing react nodes for icons in storage overview

* trading form validation schema with yup

* TimelineEntry entryStatus, past, current and future

* adding segmentCount to periods in db and for fetching

* avoid spread syntax on accumulators

* providing types for achievements

* cleaning up rest of todos and comments for segment count and filtering

---------

Co-authored-by: Roland Schläfli <[email protected]>

* adding some missing keys in ui package and cockpit

* adding colors to the welcome page

* adding locations to demo-game

* page layout for demo-game

* adding more locations

* immutable getGames - let to const

* peerDependencies for the ui package

* refine ui layout with custom sidebar addons

* cleaner reexporting, named export

* tradingform adding max, removing min, which is 0

* ui trading from formiknumberfield

* timeline entry removing redundant code

* direct input string TimelineAdmin

* integrating a new design system

* integrating shadcn ui in the navbar

* fixing react and formik version in peerdependencies of packages

* shadcn line graph

* adding additonal info to the game list, player count, etc

* moving player color, avatar and location to facts

* transactions and decision history components

* cleaning transaction display component

* cards for decision and transactio history, some refactoring

* wrap histories

* sizing transaction history cards

* refactoring game header

* applied review suggestions

* refined welcome page

* adding playerfacts to platform

* demo-game welcome page, default bank name and additional todo

* fix ordering of games when creating a new one

* revert currentGame prisma obj copy

* fix admin next button

* add admin button segment result

---------

Co-authored-by: Roland Schläfli <[email protected]>
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