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

fix(web): add placeholder for no model on overview page #1309

Merged
merged 5 commits into from
Nov 18, 2024

Conversation

caichi-t
Copy link
Contributor

@caichi-t caichi-t commented Nov 14, 2024

Overview

This PR adds the placeholder for no model on overview page.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced UI feedback with a placeholder message when no models are present on the Overview page.
    • Added a new test case for model creation via the "plus New Model" button.
  • Improvements

    • Improved internationalization support by integrating the Trans component for better translation handling in various components.
    • Expanded translation files to include new keys and updated existing translations for clarity and accuracy in both English and Japanese.
  • Bug Fixes

    • Adjusted test cases to ensure UI reflects changes after model deletion.

@caichi-t caichi-t requested a review from nourbalaha as a code owner November 14, 2024 05:01
Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request enhance the functionality and internationalization of the Re:Earth CMS application. Key modifications include improved test cases for model creation and deletion, updates to the IntegrationTable, WebhookList, and ProjectList components to utilize the Trans component for translations, and the introduction of new styled components in the ProjectOverview. Additionally, new translation keys were added to the English and Japanese localization files to support these updates.

Changes

File Path Change Summary
web/e2e/project/overview.spec.ts Enhanced test cases for model creation and deletion, added assertions for visibility of "No Models yet."
web/src/components/molecules/Integration/IntegrationTable/index.tsx Updated import to include Trans, replaced t function for translations.
web/src/components/molecules/MyIntegrations/Webhook/WebhookList/index.tsx Updated import to include Trans, replaced t function for translations.
web/src/components/molecules/ProjectList/ProjectList.tsx Updated import to include Trans, replaced t function for translations.
web/src/components/molecules/ProjectOverview/index.tsx Added conditional rendering for model availability, introduced new styled components for placeholders.
web/src/i18n/translations/en.yml Added new translation keys: readDocument, No Models yet, Create a new model, and updated existing keys.
web/src/i18n/translations/ja.yml Added new translation entries and updated existing translations for clarity and accuracy.

Possibly related PRs

Suggested reviewers

  • nourbalaha

🐇 In the garden where models grow,
A button clicked, the magic flows.
With translations bright, our paths align,
New models bloom, in code they shine.
Let's celebrate this joyful spree,
For every change, a victory! 🌼


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.

@github-actions github-actions bot added the web label Nov 14, 2024
Copy link

netlify bot commented Nov 14, 2024

Deploy Preview for reearth-cms ready!

Name Link
🔨 Latest commit 581cf28
🔍 Latest deploy log https://app.netlify.com/sites/reearth-cms/deploys/673b195e85d7f80008e38018
😎 Deploy Preview https://deploy-preview-1309--reearth-cms.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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: 4

🧹 Outside diff range and nitpick comments (4)
web/e2e/project/overview.spec.ts (2)

16-17: LGTM! Consider making button selector more specific

The changes properly verify the placeholder visibility both before model creation and after deletion. However, using .first() for button selection suggests multiple "New Model" buttons exist, which could make the test brittle.

Consider using a more specific selector to target the exact button:

-await page.getByRole("button", { name: "plus New Model" }).first().click();
+await page.getByRole("button", { name: "plus New Model" }).filter({ hasText: "New Model" }).click();

Also applies to: 48-48


Line range hint 6-13: Improve test isolation in setup/teardown

The current setup doesn't ensure a clean state for model testing. Consider enhancing the test isolation:

  1. Ensure no models exist in the beforeEach hook
  2. Clean up any created models in the afterEach hook
  3. Add test isolation flags to prevent parallel execution
 test.beforeEach(async ({ reearth, page }) => {
   await reearth.goto("/", { waitUntil: "domcontentloaded" });
   await createProject(page);
+  // Ensure no models exist
+  await expect(page.getByText("No Models yet")).toBeVisible();
 });

 test.afterEach(async ({ page }) => {
+  // Clean up any created models
+  const modelExists = await page.getByRole("menuitem").count() > 0;
+  if (modelExists) {
+    await page.getByRole("menuitem").click();
+    await page.getByText("Delete").click();
+    await page.getByRole("button", { name: "Delete Model" }).click();
+    await closeNotification(page);
+  }
   await deleteProject(page);
 });

+// Prevent parallel execution
+test.describe.configure({ mode: 'serial' });
web/src/components/molecules/ProjectOverview/index.tsx (2)

74-81: Consider consolidating duplicate "New Model" buttons

There are two "New Model" buttons with identical functionality - one in the header and one in the placeholder. This might confuse users and violates the DRY principle.

Consider showing only the placeholder button when there are no models, and only the header button when models exist:

-headerActions={
-  <Button
-    type="primary"
-    icon={<Icon icon="plus" />}
-    onClick={onModelModalOpen}
-    disabled={!hasCreateRight}>
-    {t("New Model")}
-  </Button>
-}
+headerActions={models?.length ? (
+  <Button
+    type="primary"
+    icon={<Icon icon="plus" />}
+    onClick={onModelModalOpen}
+    disabled={!hasCreateRight}>
+    {t("New Model")}
+  </Button>
+) : null}

103-128: Enhance styling consistency

While the styled components are well-structured, there are a few improvements that could be made for better maintainability:

  1. Consider using design system tokens for consistent spacing and colors:
const Content = styled.div`
  display: flex;
  flex-direction: column;
  align-items: center;
-  gap: 12px;
-  color: rgba(0, 0, 0, 0.45);
+  gap: ${theme.spacing.md};
+  color: ${theme.colors.textSecondary};
`;
  1. Consider extracting common spacing values into theme constants for better maintainability.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b34b98e and 7405777.

📒 Files selected for processing (7)
  • web/e2e/project/overview.spec.ts (2 hunks)
  • web/src/components/molecules/Integration/IntegrationTable/index.tsx (2 hunks)
  • web/src/components/molecules/MyIntegrations/Webhook/WebhookList/index.tsx (2 hunks)
  • web/src/components/molecules/ProjectList/ProjectList.tsx (2 hunks)
  • web/src/components/molecules/ProjectOverview/index.tsx (3 hunks)
  • web/src/i18n/translations/en.yml (2 hunks)
  • web/src/i18n/translations/ja.yml (2 hunks)
🔇 Additional comments (10)
web/src/components/molecules/MyIntegrations/Webhook/WebhookList/index.tsx (1)

6-6: LGTM!

The addition of the Trans import alongside useT is appropriate for the enhanced translation implementation.

web/src/components/molecules/ProjectList/ProjectList.tsx (2)

8-8: LGTM: Clean import statement addition

The addition of the Trans component import is clean and properly aligned with the internationalization improvements.


45-45: ⚠️ Potential issue

Add the missing documentation URL

The anchor tag's href attribute is empty, which makes the documentation link non-functional. Please add the appropriate documentation URL.

-            <Trans i18nKey="readDocument" components={{ l: <a href="" /> }} />
+            <Trans i18nKey="readDocument" components={{ l: <a href="https://docs.reearth.io/cms/..." target="_blank" rel="noopener noreferrer" /> }} />

Let's verify if the documentation URL exists in other files:

web/src/components/molecules/ProjectOverview/index.tsx (1)

8-8: LGTM: Import changes are appropriate

The addition of the Trans component import is correct and aligns with its usage in the documentation link section.

web/src/components/molecules/Integration/IntegrationTable/index.tsx (2)

18-18: LGTM: Clean import addition

The addition of the Trans component import alongside useT is a good practice for handling translations with embedded components.


206-208: Verify the PR objective alignment

The changes appear to be updating the empty state in the IntegrationTable component, but the PR objective mentions "add placeholder for no model on overview page". Could you verify if:

  1. These changes are intended for this component
  2. Additional changes are needed in the overview page
  3. The PR description needs to be updated
web/src/i18n/translations/en.yml (2)

275-276: LGTM! Translation keys align with PR objectives

The new translation keys "No Models yet" and "Create a new model" provide clear messaging for the empty state, directly addressing the PR objective of adding a placeholder for no model on the overview page.


212-212: Verify HTML tag rendering implementation

The translation key uses an HTML-like <l> tag. Ensure that the component rendering this translation properly handles these tags.

✅ Verification successful

HTML tag rendering is properly implemented

The <l> tag is correctly handled by the Trans component across multiple components. The implementation shows consistent usage where the tag is properly mapped to an anchor element:

  • ProjectOverview/index.tsx: <Trans i18nKey="readDocument" components={{ l: <a href="" /> }} />
  • IntegrationTable/index.tsx: <Trans i18nKey="readDocument" components={{ l: <a href="" /> }} />
  • ProjectList/ProjectList.tsx: <Trans i18nKey="readDocument" components={{ l: <a href="" /> }} />
  • WebhookList/index.tsx: <Trans i18nKey="readDocument" components={{ l: <a href="" /> }} />
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for Trans component usage with readDocument key
rg -A 2 "readDocument" --type ts --type tsx

Length of output: 71


Script:

#!/bin/bash
# Search for readDocument key usage in all files
rg -A 2 "readDocument"

# Search for components that might handle <l> tags
rg -A 5 "<l>" --type ts
rg -A 5 "<l>" --type typescript

Length of output: 5074

web/src/i18n/translations/ja.yml (2)

275-276: LGTM! Translations align with PR objectives.

The translations for "No Models yet" and "Create a new model" are grammatically correct and consistent with the application's terminology. These additions properly support the PR's objective of adding placeholders for no model scenarios.


212-212: LGTM! Verify tag handling in the translation system.

The translation is correct, but ensure that the <l> tags are properly handled by the translation system and rendered correctly in the UI.

✅ Verification successful

Based on the search results, I can see that the <l> tags are properly handled by the translation system using the Trans component from react-i18next. The usage is consistent across files, and there are three instances where it's used with the "readDocument" translation key:

  1. web/src/components/molecules/ProjectOverview/index.tsx: <Trans i18nKey="readDocument" components={{ l: <a href="" /> }} />
  2. web/src/components/molecules/ProjectList/ProjectList.tsx: <Trans i18nKey="readDocument" components={{ l: <a href="" /> }} />
  3. web/src/components/molecules/Integration/IntegrationTable/index.tsx: <Trans i18nKey="readDocument" components={{ l: <a href="" /> }} />

The translation system is properly set up with i18next and react-i18next, and the <l> tags are correctly transformed into anchor (<a>) elements in the UI.

The translation and tag handling are properly implemented.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent usage of <l> tags in translations
# Test: Search for similar tag usage in other translation files
rg -g '*.yml' '<l>'

Length of output: 197


Script:

#!/bin/bash
# Check how these <l> tags are processed in the codebase
ast-grep --pattern 'const $_ = $$.replace(/<l>.*?<\/l>/g, $_)'

# Also check for any component or utility that handles these tags
rg -g '*.{ts,tsx,js,jsx}' '<l>' -B 2 -A 2

Length of output: 108


Script:

#!/bin/bash
# Look for translation handling components or utilities
rg -g '*.{ts,tsx,js,jsx}' -i 'translate|i18n' -B 2 -A 2

# Check for any link or text processing utilities
fd -e ts -e tsx -e js -e jsx --exec grep -l -i "link\|text\|format"

Length of output: 101197

@caichi-t caichi-t enabled auto-merge (squash) November 18, 2024 10:39
@caichi-t caichi-t merged commit f17321e into main Nov 18, 2024
19 checks passed
@caichi-t caichi-t deleted the fix-web/no-model-ui branch November 18, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants