Skip to content

Conversation

@prateekshourya29
Copy link
Member

@prateekshourya29 prateekshourya29 commented Feb 14, 2025

Description

Fixes an issue where the empty state group header was not appearing in settings when all states were deleted for a group. Ensures it renders correctly even when no items are present.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

image

Summary by CodeRabbit

  • New Features
    • Introduced localized empty state messages to inform users when no states are present and prompt them to create one.
  • Refactor
    • Updated the grouping logic to consistently display all state groups, ensuring a unified experience even when a group is empty.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2025

Walkthrough

This pull request adds an empty_state object with title and description fields under the states section of the project_settings in multiple translation files (English, Spanish, French, Japanese, and Chinese). It updates the GroupItem component to use a new shouldShowEmptyState variable based on state conditions and proper permission checks, and refines the state grouping logic in the store to include all groups defined in STATE_GROUPS.

Changes

File(s) Change Summary
packages/i18n/src/locales/{en, es, fr, ja, zh-CN}/translations.json Added a new empty_state object with locale-specific title and description under project_settings.states in each translation file.
web/core/components/.../group-item.tsx Introduced new imports (for user permissions and translation), declared shouldShowEmptyState, and updated rendering logic to display an empty state message based on conditions.
web/core/store/state.store.ts Added an import for STATE_GROUPS and modified the groupedProjectStates getter to ensure all state groups are included, initializing missing groups with an empty array.

Sequence Diagram(s)

sequenceDiagram
    participant UI as GroupItem Component
    participant Store as StateStore
    participant TS as Translation Service
    UI->>Store: Request grouped project states
    Store-->>UI: Return grouped states (including empty arrays)
    UI->>UI: Evaluate if empty state should render (using shouldShowEmptyState)
    alt Empty State Needed
        UI->>TS: Fetch localized empty state text
        TS-->>UI: Return translated title and description
        UI->>UI: Render empty state message
    else
        UI->>UI: Render existing states
    end
Loading

Possibly related PRs

Suggested labels

🐛bug, 🌐frontend

Suggested reviewers

  • sriramveeraghanta
  • rahulramesha
  • SatishGandham

Poem

I'm a little bunny, hopping through code with glee,
Adding empty states so none are left in misery.
In each locale, my message now sings,
Bringing clarity and cheer with simple strings.
With every line of code, my hops grow light—
Happy changes make my day so bright!
🐰🌟

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

@sriramveeraghanta sriramveeraghanta merged commit b62b271 into preview Feb 14, 2025
4 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-empty-state-group branch February 14, 2025 08:24
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 71b41fa and 08b5b21.

📒 Files selected for processing (7)
  • packages/i18n/src/locales/en/translations.json (1 hunks)
  • packages/i18n/src/locales/es/translations.json (1 hunks)
  • packages/i18n/src/locales/fr/translations.json (1 hunks)
  • packages/i18n/src/locales/ja/translations.json (1 hunks)
  • packages/i18n/src/locales/zh-CN/translations.json (1 hunks)
  • web/core/components/project-states/group-item.tsx (3 hunks)
  • web/core/store/state.store.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
web/core/store/state.store.ts

[error] 117-117: 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)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (9)
web/core/components/project-states/group-item.tsx (3)

6-8: Well-organized imports with clear separation!

Good practice using comments to separate imports into logical groups.


50-50: Good implementation of the empty state condition!

The shouldShowEmptyState variable effectively combines multiple conditions to determine when to show the empty state:

  • states.length === 0: No states exist
  • currentStateExpanded: Group is expanded
  • !createState: Not currently creating a new state

86-91: Well-implemented empty state UI with proper i18n support!

The empty state UI is well-structured:

  • Uses proper conditional rendering
  • Implements localization for better user experience
  • Shows additional description for users with edit permissions
web/core/store/state.store.ts (1)

111-123: Good implementation ensuring all state groups are present!

The logic correctly ensures that all state groups defined in STATE_GROUPS are represented in the returned object, even if they don't have any states. This aligns well with the PR's objective of fixing empty state visibility.

🧰 Tools
🪛 Biome (1.9.4)

[error] 117-117: 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)

packages/i18n/src/locales/zh-CN/translations.json (1)

1691-1694: Well-structured translations for empty state!

The Chinese translations are clear and maintain consistency with the application's messaging:

  • Title properly includes the dynamic {groupKey} parameter
  • Description provides a clear call-to-action
packages/i18n/src/locales/ja/translations.json (1)

1690-1694: LGTM! The empty state messages are well-structured and properly localized.

The added empty state messages effectively handle the case when a state group has no states, providing clear feedback to users in Japanese. The use of the {groupKey} placeholder allows for dynamic group names, making the messages reusable across different state groups.

packages/i18n/src/locales/en/translations.json (1)

1521-1525:

Details

✅ Verification successful

LGTM! The empty state messages are clear and well-structured.

The implementation follows i18n best practices with clear messages and proper dynamic content handling using the {groupKey} parameter.

Let's verify that the same structure exists in other language files:


🏁 Script executed:

#!/bin/bash
# Description: Check if the empty state structure is consistent across all language files.

# Search for empty_state structure in all language files
rg -A 3 '"empty_state":\s*{' packages/i18n/src/locales/

Length of output: 157


Below is a revised verification step using a simpler search pattern. The original regex caused an error, so please re-run the following shell script manually to verify that the "empty_state" structure is consistently defined across all language files:

Once you confirm that the structure (with its title and description) appears in the expected files, please update the review status accordingly.

Next Action:
• Manually verify the output of this script to ensure consistency of the empty state structure in all i18n locale files.


🏁 Script executed:

[run_scripts]
#!/bin/bash
# Re-run search for the "empty_state" key (and the following three lines) to verify consistency
rg -A 3 'empty_state' packages/i18n/src/locales/

Length of output: 54995


LGTM – the empty state translation changes for the states group look solid.
• The English translation now presents a clear and concise message with the dynamic {groupKey} placeholder as intended ("No states available for the {groupKey} group", "Please create a new state").
• A manual review across the locale files (ES, FR, JA, ZH-CN) confirms that similar structures with appropriate localized placeholders and descriptions have been implemented.

packages/i18n/src/locales/es/translations.json (1)

1690-1694: LGTM! Well-structured translations for empty states.

The translations are well-organized and follow good practices:

  • Proper nesting under the correct section
  • Clear and natural Spanish translations
  • Consistent placeholder usage for dynamic content
  • Maintains semantic meaning from English to Spanish
packages/i18n/src/locales/fr/translations.json (1)

1690-1694: LGTM! The French translation for empty state is accurate and well-formatted.

The added translation strings are properly formatted in French and maintain consistency with other language files. The {groupKey} placeholder is correctly preserved for dynamic content.

Comment on lines +115 to +121
const allGroups = Object.keys(STATE_GROUPS).reduce(
(acc, group) => ({
...acc,
[group]: groupedStates[group] || [],
}),
{} as Record<string, IState[]>
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize the reduce operation to avoid O(n²) complexity.

The spread operator in the reduce accumulator can lead to quadratic time complexity as it creates a new object and copies all properties in each iteration.

Consider this more efficient approach:

-    const allGroups = Object.keys(STATE_GROUPS).reduce(
-      (acc, group) => ({
-        ...acc,
-        [group]: groupedStates[group] || [],
-      }),
-      {} as Record<string, IState[]>
-    );
+    const allGroups = {} as Record<string, IState[]>;
+    for (const group of Object.keys(STATE_GROUPS)) {
+      allGroups[group] = groupedStates[group] || [];
+    }
📝 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 allGroups = Object.keys(STATE_GROUPS).reduce(
(acc, group) => ({
...acc,
[group]: groupedStates[group] || [],
}),
{} as Record<string, IState[]>
);
const allGroups = {} as Record<string, IState[]>;
for (const group of Object.keys(STATE_GROUPS)) {
allGroups[group] = groupedStates[group] || [];
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 117-117: 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)

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.

3 participants