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

GO: Builds indicator for artifacts #2620

Merged
merged 10 commits into from
Jan 26, 2025

Conversation

failchon
Copy link
Contributor

@failchon failchon commented Jan 25, 2025

Describe your changes

Added a Builds indicator for artifacts that are used in a specific build.

Issue or discord link

Testing/validation

builds
usage builds

Checklist before requesting a review (leave this PR as draft if any part of this list is not done.)

  • I have commented my code in hard-to understand areas.
  • I have made corresponding changes to README or wiki.
  • For front-end changes, I have updated the corresponding English translations.
  • I have run yarn run mini-ci locally to validate format and lint.
  • If I have added a new library or app, I have updated the deployment scripts to ignore changes as needed

Summary by CodeRabbit

  • New Features

    • Added localization support for artifact build count display.
    • Introduced artifact usage tracking with a modal to show builds using a specific artifact.
  • Improvements

    • Enhanced artifact card interactivity by adding a badge to show the number of builds.
    • Implemented ability to view builds associated with an artifact.
    • Added dynamic text for artifact usage based on the count of builds.
    • Integrated new identifier for builds to improve data management.

Copy link
Contributor

coderabbitai bot commented Jan 25, 2025

Walkthrough

This pull request enhances the artifact management system by adding localization support for build count and artifact usage. It introduces new localization keys for pluralizing "Build" and displaying artifact usage context. In the ArtifactCard component, a new feature is implemented to show the number of builds an artifact is used in, with a modal that can be triggered to display the specific build names. Additionally, the Build interface is updated to include an id property for better identification.

Changes

File Change Summary
libs/gi/localization/assets/locales/en/artifact.json Added localization keys: builds_one, builds_other for pluralization, and artifactUsage for context.
libs/gi/ui/src/components/artifact/ArtifactCard.tsx Added ArtifactBuildUsageModal, implemented build usage tracking, added useDatabase import, enhanced artifact card interactivity.
libs/gi/db/src/Database/DataManagers/BuildDataManager.ts Updated Build interface to include a new id property.

Sequence Diagram

sequenceDiagram
    participant User
    participant ArtifactCard
    participant ArtifactBuildUsageModal
    participant Database

    User->>ArtifactCard: View Artifact
    ArtifactCard->>Database: Fetch Build Data
    Database-->>ArtifactCard: Return Build Names
    ArtifactCard->>ArtifactCard: Display Build Count Badge
    User->>ArtifactCard: Click Build Count Badge
    ArtifactCard->>ArtifactBuildUsageModal: Show Modal
    ArtifactBuildUsageModal->>User: Display Build Names
Loading

Possibly related PRs

Suggested labels

SRO, ZO

Suggested reviewers

  • frzyc

Poem

🐰 Builds and badges, oh so neat,
Artifacts dancing to a localized beat.
Clicks reveal stories untold,
Of builds where artifacts boldly unfold.
A rabbit's code, precise and light! 🏷️

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
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: 1

🧹 Nitpick comments (3)
libs/gi/ui/src/components/artifact/ArtifactCard.tsx (3)

161-170: Consider optimizing build counting performance.

The current implementation could be optimized to prevent unnecessary calculations on each render:

  1. Memoize the buildNames array and numberOfBuilds calculation
  2. Consider using Object.entries() for cleaner iteration
 const database = useDatabase()
-const builds = database.builds.data
-const buildNames = []
-for (const buildId in builds) {
-  if (builds[buildId]?.artifactIds[artifact.slotKey] === artifact.id) {
-    buildNames.push(builds[buildId].name)
-  }
-}
-const numberOfBuilds = buildNames.length
+const { buildNames, numberOfBuilds } = useMemo(() => {
+  const builds = database.builds.data
+  const names = Object.entries(builds)
+    .filter(([_, build]) => build?.artifactIds[artifact.slotKey] === artifact.id)
+    .map(([_, build]) => build.name)
+  return { buildNames: names, numberOfBuilds: names.length }
+}, [database.builds.data, artifact.id, artifact.slotKey])

531-564: Enhance modal accessibility and UX.

Consider the following improvements:

  1. Add proper accessibility attributes
  2. Handle long lists of builds
  3. Pass build names as an array for more flexible formatting
 function ArtifactBuildUsageModal({
   show,
   onHide,
-  buildNames,
+  buildNames: string[],
 }: {
   show: boolean
   onHide: () => void
-  buildNames: string
+  buildNames: string[]
 }) {
   return (
-    <ModalWrapper open={show} onClose={onHide}>
+    <ModalWrapper
+      open={show}
+      onClose={onHide}
+      aria-labelledby="build-usage-title"
+      aria-describedby="build-usage-description"
+    >
       <CardThemed>
         <CardHeader
+          id="build-usage-title"
           title={
             <Typography
               variant="h6"
               flexGrow={1}
               display="flex"
               alignItems="center"
             >
-              {buildNames}
+              {t('artifact:usage')}
             </Typography>
           }
           action={
-            <IconButton onClick={onHide}>
+            <IconButton onClick={onHide} aria-label="close">
               <CloseIcon />
             </IconButton>
           }
         />
         <Divider />
+        <Box
+          id="build-usage-description"
+          sx={{
+            maxHeight: '60vh',
+            overflowY: 'auto',
+            p: 2
+          }}
+        >
+          {buildNames.map((name, index) => (
+            <Typography key={index}>
+              {name}
+            </Typography>
+          ))}
+        </Box>
       </CardThemed>
     </ModalWrapper>
   )
 }

161-170: Consider optimizing build counting logic for better performance.

The current implementation iterates through all builds using a for...in loop. Consider using array methods for better readability and potentially better performance.

Here's a suggested optimization:

-  const builds = database.builds.data
-  const buildNames = []
-  for (const buildId in builds) {
-    if (builds[buildId]?.artifactIds[artifact.slotKey] === artifact.id) {
-      buildNames.push(builds[buildId].name)
-    }
-  }
-  const numberOfBuilds = buildNames.length
+  const builds = database.builds.data
+  const buildNames = Object.values(builds)
+    .filter(build => build?.artifactIds[artifact.slotKey] === artifact.id)
+    .map(build => build.name)
+  const numberOfBuilds = buildNames.length
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a030cc0 and a91a98c.

📒 Files selected for processing (2)
  • libs/gi/localization/assets/locales/en/artifact.json (1 hunks)
  • libs/gi/ui/src/components/artifact/ArtifactCard.tsx (10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: typecheck
  • GitHub Check: test
  • GitHub Check: lint
  • GitHub Check: gen-file
  • GitHub Check: call-build / build
  • GitHub Check: call-build / build
🔇 Additional comments (5)
libs/gi/ui/src/components/artifact/ArtifactCard.tsx (4)

3-3: LGTM: Import changes align with new feature requirements.

The added imports support the new build indicator functionality.

Also applies to: 12-12, 14-14, 29-29


390-399: LGTM: Well-implemented build count badge.

The implementation:

  • Provides clear visual feedback through cursor and color changes
  • Uses proper localization for pluralization
  • Has appropriate click handling

3-3: LGTM! Clean import organization and hook usage.

The new imports are well-organized, and the hook implementation follows React best practices with clear, descriptive naming.

Also applies to: 12-12, 14-14, 29-29, 104-104


390-399: LGTM! Well-implemented build count badge.

The badge implementation is clean with:

  • Proper accessibility considerations (cursor styling)
  • Correct translation usage for pluralization
  • Appropriate conditional styling
libs/gi/localization/assets/locales/en/artifact.json (1)

125-127: LGTM: Proper localization support for build counts.

The added translations:

  • Support pluralization for build counts
  • Include context for build usage

libs/gi/ui/src/components/artifact/ArtifactCard.tsx Outdated Show resolved Hide resolved
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: 1

🧹 Nitpick comments (2)
libs/gi/ui/src/components/artifact/ArtifactCard.tsx (2)

393-402: Enhance badge accessibility.

The badge acts as a button but lacks proper accessibility attributes.

 <SqBadge
   sx={{
     ml: 'auto',
     cursor: numberOfBuilds ? 'pointer' : 'default',
   }}
   color={numberOfBuilds ? 'success' : 'secondary'}
   onClick={numberOfBuilds ? onShowUsage : undefined}
+  role="button"
+  tabIndex={numberOfBuilds ? 0 : undefined}
+  aria-label={t('builds', { count: numberOfBuilds })}
 >
   {t('builds', { count: numberOfBuilds })}
 </SqBadge>

534-574: Enhance modal robustness.

The modal implementation could benefit from handling edge cases and improving user experience for long lists.

 function ArtifactBuildUsageModal({
   show,
   onHide,
   buildNames,
   usageText,
 }: {
   show: boolean
   onHide: () => void
   buildNames: string[]
   usageText: string
 }) {
+  if (!buildNames.length) {
+    return null
+  }
   return (
     <ModalWrapper open={show} onClose={onHide}>
       <CardThemed>
         <CardHeader
           title={
             <Typography
               variant="h6"
               flexGrow={1}
               display="flex"
               alignItems="center"
             >
               {usageText}
             </Typography>
           }
           action={
             <IconButton onClick={onHide}>
               <CloseIcon />
             </IconButton>
           }
         />
-        <List>
+        <List sx={{ maxHeight: '60vh', overflow: 'auto' }}>
           {buildNames.map((name, index) => (
             <ListItem key={index}>
               <ListItemText primary={name} />
             </ListItem>
           ))}
         </List>
       </CardThemed>
     </ModalWrapper>
   )
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a91a98c and 807fb42.

📒 Files selected for processing (2)
  • libs/gi/localization/assets/locales/en/artifact.json (1 hunks)
  • libs/gi/ui/src/components/artifact/ArtifactCard.tsx (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/gi/localization/assets/locales/en/artifact.json
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: call-build / build
  • GitHub Check: lint
🔇 Additional comments (1)
libs/gi/ui/src/components/artifact/ArtifactCard.tsx (1)

3-3: LGTM! Clean import organization.

The new imports are properly organized and necessary for implementing the build usage feature.

Also applies to: 12-12, 14-14, 29-29

libs/gi/ui/src/components/artifact/ArtifactCard.tsx Outdated Show resolved Hide resolved
@failchon failchon changed the title Failchon/go/artifacts builds usage GO: Builds indicator for artifacts Jan 25, 2025
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: 0

🧹 Nitpick comments (1)
libs/gi/ui/src/components/artifact/ArtifactCard.tsx (1)

394-403: Consider adding a tooltip to the badge.

While the badge implementation is good, adding a tooltip would improve user experience by clarifying that clicking shows the list of builds.

 <SqBadge
   sx={{
     ml: 'auto',
     cursor: numberOfBuilds ? 'pointer' : 'default',
   }}
   color={numberOfBuilds ? 'success' : 'secondary'}
   onClick={numberOfBuilds ? onShowUsage : undefined}
+  title={numberOfBuilds ? t('artifact:clickToShowBuilds') : undefined}
 >
   {t('builds', { count: numberOfBuilds })}
 </SqBadge>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 807fb42 and 9e3b0a0.

📒 Files selected for processing (1)
  • libs/gi/ui/src/components/artifact/ArtifactCard.tsx (9 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: call-build / build
  • GitHub Check: lint
🔇 Additional comments (4)
libs/gi/ui/src/components/artifact/ArtifactCard.tsx (4)

3-3: LGTM! Clean import additions.

The new imports and hooks are well-chosen for implementing the build indicator feature.

Also applies to: 12-12, 14-14, 29-29


163-173: Well-implemented build counting logic with memoization!

The code efficiently uses useMemo to prevent unnecessary recalculations, and properly tracks both build names and count.


198-205: LGTM! Good use of Suspense for modal loading.

The modal implementation properly handles loading states and receives the necessary props.


535-576: Well-structured modal component!

The implementation follows the suggested improvements from previous reviews, with proper typing and a clean UI layout using Material-UI components.

Copy link
Contributor

github-actions bot commented Jan 25, 2025

[frontend] [Sat Jan 25 23:24:03 UTC 2025] - Deployed fad2bb3 to https://genshin-optimizer-prs.github.io/pr/2620/frontend (Takes 3-5 minutes after this completes to be available)

[frontend] [Sun Jan 26 19:10:18 UTC 2025] - Deployed 9e9c529 to https://genshin-optimizer-prs.github.io/pr/2620/frontend (Takes 3-5 minutes after this completes to be available)

[Sun Jan 26 19:24:37 UTC 2025] - Deleted deployment

libs/gi/ui/src/components/artifact/ArtifactCard.tsx Outdated Show resolved Hide resolved
libs/gi/ui/src/components/artifact/ArtifactCard.tsx Outdated Show resolved Hide resolved
libs/gi/ui/src/components/artifact/ArtifactCard.tsx Outdated Show resolved Hide resolved
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: 0

🧹 Nitpick comments (3)
libs/gi/db/src/Database/DataManagers/BuildDataManager.ts (1)

Line range hint 32-69: Add type validation for the id property.

While the id is correctly extracted and included in the validated object, consider adding type validation to ensure it's a non-empty string.

 override validate(obj: unknown): Build | undefined {
   let { name, description, weaponId, artifactIds } = obj as Build
   const { id } = obj as Build
+  if (typeof id !== 'string' || !id) {
+    return undefined
+  }
   if (typeof name !== 'string') name = 'Build Name'
libs/gi/ui/src/components/artifact/ArtifactCard.tsx (2)

549-602: Enhance modal list items with hover state.

Consider adding hover state styling to list items for better user experience.

 <ListItem key={index}
+  sx={{
+    '&:hover': {
+      backgroundColor: 'action.hover',
+      cursor: 'pointer',
+    },
+  }}

212-219: Optimize Suspense implementation.

The nested Suspense with fallback={false} can be simplified since it doesn't provide meaningful loading state.

-      <Suspense fallback={false}>
         <ArtifactBuildUsageModal
           show={showUsage}
           onHide={onHideUsage}
           usageText={t('artifact:artifactUsage')}
           builds={builds}
         />
-      </Suspense>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e3b0a0 and 0095942.

📒 Files selected for processing (3)
  • libs/gi/db/src/Database/DataManagers/BuildDataManager.ts (3 hunks)
  • libs/gi/localization/assets/locales/en/artifact.json (1 hunks)
  • libs/gi/ui/src/components/artifact/ArtifactCard.tsx (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/gi/localization/assets/locales/en/artifact.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint
🔇 Additional comments (3)
libs/gi/db/src/Database/DataManagers/BuildDataManager.ts (1)

11-13: LGTM! The Build interface update is well-structured.

The addition of the id property enables unique identification of builds, which is essential for the new builds indicator feature.

libs/gi/ui/src/components/artifact/ArtifactCard.tsx (2)

165-187: LGTM! Efficient implementation of build counting.

The build counting logic is well-optimized:

  • Uses useMemo to prevent unnecessary recalculations
  • Correctly filters builds based on artifact usage
  • Effectively maps the relationship between builds and team characters

408-417: LGTM! Well-implemented build indicator UI.

The build indicator implementation:

  • Follows accessibility best practices with conditional interactivity
  • Uses proper translation for build count
  • Has clear visual feedback with color changes

Copy link
Owner

@frzyc frzyc left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for iterating on this solution.

@frzyc frzyc merged commit 2c56ff8 into frzyc:master Jan 26, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GO Create an artifact card indicator showing its build count.
3 participants