Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: new component jsonViewer #5544

Merged
merged 3 commits into from
Feb 16, 2025
Merged

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Feb 16, 2025

Description

添加新组件JsonViewer,用于展示JSON结构数据

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features

    • Introduced an interactive JSON viewer that supports customizable display settings, copy functionality, and robust error handling.
    • Added a dedicated demo page showcasing the JSON viewer with sample data.
    • Expanded UI language support with updated copy action texts in multiple languages.
  • Style

    • Enhanced the visual presentation of JSON data with a refined theme that improves readability.
  • Chores

    • Added a new dependency for vue-json-viewer to support the JSON viewer functionality.

Copy link

changeset-bot bot commented Feb 16, 2025

⚠️ No Changeset found

Latest commit: b1a8aad

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Feb 16, 2025

Warning

Rate limit exceeded

@mynetfan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f6c9174 and b1a8aad.

📒 Files selected for processing (3)
  • packages/effects/common-ui/src/components/json-viewer/index.vue (1 hunks)
  • packages/effects/common-ui/src/components/json-viewer/types.ts (1 hunks)
  • playground/src/views/examples/json-viewer/index.vue (1 hunks)

Walkthrough

This pull request adds a new JSON viewer feature. A new dependency for vue-json-viewer is introduced, and a corresponding component is implemented in the common UI package. The JSON viewer component is defined with TypeScript using the Composition API, includes styling via SCSS, and exports necessary types. Language translations for copy actions are added for English and Chinese locales. Additionally, a new route and demo page with sample JSON data are introduced in the playground, with the dependency also registered in the workspace configuration.

Changes

File(s) Change Summary
packages/effects/common-ui/package.json Added new dependency "vue-json-viewer": "catalog:"
packages/effects/common-ui/src/components/index.ts Added export: export * from './json-viewer';
packages/effects/common-ui/src/components/json-viewer/{index.ts,index.vue,style.scss,types.ts} Introduced new JsonViewer component with a default export, computed properties, SCSS styling, and a new interface JsonViewerProps
packages/locales/src/langs/{en-US,zh-CN}/ui.json Added new "jsonViewer" section with copy texts ("copy" and "copied")
playground/src/router/routes/modules/examples.ts, playground/src/views/examples/json-viewer/{data.ts,index.vue} Added new route for JsonViewer, demo page component, and sample JSON data (json1, json2)
pnpm-workspace.yaml Added workspace dependency vue-json-viewer: ^3.0.4

Suggested labels

feature

Suggested reviewers

  • anncwb
  • vince292007

Poem

Hopping through code in the moonlight glow,
I found a JSON viewer ready to show.
Dependencies and routes all in a row,
With SCSS style and props that flow.
From a rabbit’s heart, let the changes grow!
🐇✨


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

🧹 Nitpick comments (5)
packages/effects/common-ui/src/components/json-viewer/types.ts (2)

2-14: Convert documentation to English for international collaboration.

The property documentation is currently in Chinese. For better international collaboration, consider translating the comments to English:

-  /** 展开深度 */
+  /** Expansion depth */
   expandDepth?: number;
-  /** 是否可复制 */
+  /** Enable copy functionality */
   copyable?: boolean;
-  /** 是否排序 */
+  /** Enable sorting */
   sort?: boolean;
-  /** 显示边框 */
+  /** Show border */
   boxed?: boolean;
-  /** 主题 */
+  /** Theme */
   theme?: string;
-  /** 是否展开 */
+  /** Initially expanded */
   expanded?: boolean;

11-11: Add theme validation using string literal type.

Consider defining allowed theme values using a string literal type for better type safety and developer experience.

-  theme?: string;
+  theme?: 'light' | 'dark';
playground/src/views/examples/json-viewer/index.vue (1)

9-12: Convert description to English for international collaboration.

The component description is in Chinese. For better international collaboration, consider translating it to English:

   <Page
     title="Json Viewer"
-    description="一个渲染 JSON 结构数据的组件,支持复制、展开等,简单易用"
+    description="A component for rendering JSON structured data with support for copying, expansion, and more. Simple and easy to use."
   >
playground/src/views/examples/json-viewer/data.ts (1)

1-27: Consider adding TypeScript interfaces for the data structure.

The json1 object has a well-defined structure that would benefit from TypeScript interfaces for better type safety and documentation.

+interface Tool {
+  description: string;
+  name: string;
+}
+
+interface AdditionalInfo {
+  author: string;
+  debug: boolean;
+  version: string;
+  versionCode: number;
+}
+
+interface JsonData {
+  additionalInfo: AdditionalInfo;
+  additionalNotes: string;
+  tools: Tool[];
+}
+
 export const json1 = {
   additionalInfo: {
packages/effects/common-ui/src/components/json-viewer/index.vue (1)

63-69: Add error state rendering in the template.

Show parsing errors to users when they occur.

 <template>
+  <div v-if="parseError" class="text-red-500 mb-2">
+    {{ $t('ui.jsonViewer.parseError') }}: {{ parseError.message }}
+  </div>
   <VueJsonViewer :value="jsonToShow" v-bind="bindProps">
     <template #copy="slotProps">
       <slot name="copy" v-bind="slotProps"></slot>
     </template>
   </VueJsonViewer>
 </template>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f9504ce and 3413b0f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • packages/effects/common-ui/package.json (1 hunks)
  • packages/effects/common-ui/src/components/index.ts (1 hunks)
  • packages/effects/common-ui/src/components/json-viewer/index.ts (1 hunks)
  • packages/effects/common-ui/src/components/json-viewer/index.vue (1 hunks)
  • packages/effects/common-ui/src/components/json-viewer/style.scss (1 hunks)
  • packages/effects/common-ui/src/components/json-viewer/types.ts (1 hunks)
  • packages/locales/src/langs/en-US/ui.json (1 hunks)
  • packages/locales/src/langs/zh-CN/ui.json (1 hunks)
  • playground/src/router/routes/modules/examples.ts (1 hunks)
  • playground/src/views/examples/json-viewer/data.ts (1 hunks)
  • playground/src/views/examples/json-viewer/index.vue (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
🔇 Additional comments (14)
packages/effects/common-ui/src/components/json-viewer/index.ts (1)

1-3: LGTM! Clean and well-structured exports.

The exports follow best practices, with a clear default export for the component and proper type exports.

packages/effects/common-ui/src/components/index.ts (1)

6-6: LGTM! Clean export addition.

The json-viewer export follows the existing pattern and maintains alphabetical order.

playground/src/router/routes/modules/examples.ts (1)

258-266: LGTM! Route configuration follows existing patterns.

The JsonViewer route is properly configured with:

  • Lazy loading for better performance
  • Consistent meta information
  • Proper placement in the examples section
packages/effects/common-ui/package.json (1)

38-38:

✅ Verification successful

Verify vue-json-viewer compatibility with Vue 3.

Let's check if the specified version of vue-json-viewer is compatible with Vue 3 and if there are any known issues.


🌐 Web query:

What is the latest version of vue-json-viewer and is it compatible with Vue 3?

💡 Result:

The latest version of vue-json-viewer compatible with Vue 3 depends on which specific package you use:

  1. Original vue-json-viewer

    • Latest version: v3.x (explicitly designed for Vue 3)[5][6]
    • Installed via:
      npm install vue-json-viewer@3 --save
  2. Forked vue3-json-viewer

    • Latest version: v2.3.2 (as of December 2023)[4]
    • A dedicated Vue 3 fork of the original library[1][4]
    • Installed via:
      npm install vue3-json-viewer --save

Key Differences

Feature vue-json-viewer (v3.x) vue3-json-viewer (v2.x)
Vue Compatibility Vue 3 Vue 3
Dark Theme Support Yes[5] Yes[1][4]
Image Display No Extended fork adds this[2]
Maintenance Status Actively maintained[6] Community fork[1][4]

Both packages support core features like JSON syntax highlighting, collapsible nodes, copy-to-clipboard functionality, and theme customization[1][5]. For projects requiring advanced features like image previews, consider forks like vue3-json-source-viewer[2].

Citations:


Vue 3 Compatibility Verified for vue-json-viewer Dependency

The web query confirms that the official vue-json-viewer (v3.x) is explicitly designed for Vue 3. Ensure that the "catalog:" version specifier in your package.json resolves to this compatible version. If additional features (like image display) become necessary, you might also consider the forked vue3-json-viewer.

packages/effects/common-ui/src/components/json-viewer/style.scss (7)

1-7: JSON Viewer Base Theme Styling
The base .default-json-theme class is well-structured with clear settings for font-family, font-size, and color using CSS variables. The choice of white-space: nowrap reinforces a code-oriented display; however, verify that this setting is intentional for all JSON content, as very long lines may not wrap on smaller viewports.


8-10: Boxed Container Styling
The nested style for .jv-container.boxed is concise and applies a solid border that aligns with the theme’s color variables. This enhances the container’s visual separation without introducing complexity.


12-23: Ellipsis Element Styling
The .jv-ellipsis class is styled thoughtfully with inline-block display, specific padding, and a slight font-size reduction. The applied background-color, border-radius, and cursor settings effectively indicate interactivity.


25-27: Button Text Styling
The declaration for .jv-button that sets the text color using the primary color variable is straightforward and fits well within the theme’s overall style.


29-31: Key Element Styling
The .jv-key class applies a heavy foreground color to JSON keys, ensuring they stand out in the viewer. This clear emphasis aids in readability and aligns with typical code-editor styling.


33-71: JSON Data Types Styling via .jv-item
The nested selectors under .jv-item handle different JSON data types (arrays, booleans, functions, numbers, objects, undefined, strings) well. The repeated use of similar colors for number types is explicit and may be beneficial for future customization; if duplication becomes an issue, consider refactoring common styles into a shared mixin.


73-89: Embedded Code Block & Toggle Styling
The styling for .jv-code and its nested .jv-toggle (including hover effects on the pseudo-element) is clearly defined and enhances interactivity. The use of !important on padding should be double-checked against potential overrides later in the application, but it seems appropriate for enforcing the desired appearance.

packages/locales/src/langs/zh-CN/ui.json (1)

28-31: New Localization for JSON Viewer (zh-CN)
The addition of the "jsonViewer" section with "copy": "复制" and "copied": "已复制" is clear and aligns well with the user interface requirements for the new JSON viewer feature. The entry is consistent with existing localization structure.

packages/locales/src/langs/en-US/ui.json (1)

28-31: New Localization for JSON Viewer (en-US)
The newly added "jsonViewer" section containing "copy": "Copy" and "copied": "Copied" integrates seamlessly with the existing localization content. This ensures a consistent user experience across supported languages.

pnpm-workspace.yaml (1)

178-178: New Dependency for vue-json-viewer
The addition of vue-json-viewer: ^3.0.4 to the catalog is properly formatted and essential for the operation of the new JsonViewer component. Ensure that any related documentation or dependency management scripts are updated accordingly.

@mynetfan mynetfan merged commit 6cba181 into vbenjs:main Feb 16, 2025
11 checks passed
@mynetfan mynetfan deleted the feat/json-viewer branch February 16, 2025 14:57
@coderabbitai coderabbitai bot mentioned this pull request Feb 17, 2025
16 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant