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

feat: add JSON format button in apollo-portal #5287

Merged
merged 6 commits into from
Dec 1, 2024

Conversation

WTIFS
Copy link
Contributor

@WTIFS WTIFS commented Nov 26, 2024

What's the purpose of this PR

Add a JSON format button under the configuration value textarea.
The reason is when user uses compact JSON format, all the content is inline and it's hard to find the differences when publishing. By formatting the content into separated lines, it's easier to read for human.

Which issue(s) this PR fixes:

Fixes #5285

Brief changelog

  1. Add a format link in item-modal.html and formatContent function in item-modal-directive.js
  2. Add a format button in namespace-panel-master-tab.html and formatContent function in namespace-panel-directive.js
  3. Add an icon for format button. The icon is from fontawesome and is free to use. Original link: https://fontawesome.com/icons/brush?f=classic&s=solid

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

Summary by CodeRabbit

Release Notes for Apollo Version 2.4.0

  • New Features

    • Enhanced server configuration link on the system info page.
    • Introduced REST template client connection pool configuration.
    • Global search capability for administrators.
    • JSON format support in the Apollo portal for better readability.
    • New formatting options for JSON content in item modal and namespace panel.
    • Limits and whitelists for namespace count per app ID and cluster.
    • Support for observing status access keys for pre-check and logging.
    • Added internationalization support for formatting configuration item values.
  • Bug Fixes

    • Resolved issues with duplicate comments and blank lines in configuration management.
    • Fixed missing items in the published namespace link.
    • Addressed a CVE vulnerability by updating the xstream library.
  • Documentation

    • Updated CHANGES.md to reflect all recent updates and features.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Nov 26, 2024
Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

Walkthrough

The pull request introduces several enhancements and fixes for Apollo version 2.4.0, including new features for server configuration, REST template client connection pooling, and global search capabilities. It also implements limits on namespace counts and adds JSON formatting support in the Apollo portal. The changes include updates to internationalization files for English and Chinese, new utility functions for formatting JSON content in directives, and a new button for formatting within the namespace panel. Additionally, the update addresses multiple fixes and refactoring efforts, including security improvements.

Changes

File Change Summary
CHANGES.md Documented updates for Apollo version 2.4.0, including new features, fixes, and enhancements.
apollo-portal/src/main/resources/static/i18n/en.json Added entry "Component.ConfigItem.FormatItemValue": "Format Content" for English localization.
apollo-portal/src/main/resources/static/i18n/zh-CN.json Added entry "Component.ConfigItem.FormatItemValue": "格式化" for Chinese localization.
apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js Added formatContent function to format JSON content in item modal.
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js Added formatContent function to format JSON content in namespace panel.
apollo-portal/src/main/resources/static/views/component/item-modal.html Introduced a link for formatting JSON content in the item modal.
apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html Added a button to format JSON content in the namespace panel.

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • nobodyiam

🐰 In the land of code where rabbits play,
New features hop in, brightening the day.
JSON content, formatted with care,
Enhancements and fixes, a joyful affair!
With limits and whitelists, we leap with glee,
In Apollo's garden, there's magic to see! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2a8e2fc and 4da6877.

📒 Files selected for processing (2)
  • apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js (2 hunks)
  • apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js
  • apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js

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.

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

🧹 Outside diff range and nitpick comments (4)
CHANGES.md (1)

25-25: Consider enhancing the changelog entry description.

While the entry follows the correct format, consider making it more descriptive to better reflect the functionality and user benefit:

-* [Feature: add JSON format in apollo-portal](https://github.com/apolloconfig/apollo/pull/5287)
+* [Feature: add JSON formatting capability to improve configuration readability in apollo-portal](https://github.com/apolloconfig/apollo/pull/5287)
apollo-portal/src/main/resources/static/views/component/item-modal.html (1)

68-70: Enhance accessibility for the format link.

The format link should include proper ARIA attributes for better accessibility.

Consider applying this improvement:

-<a ng-show="item.type == '3'" ng-click="formatContent()">{{'Component.ConfigItem.FormatItemValue' | translate }}</a>
+<a ng-show="item.type == '3'" 
+   ng-click="formatContent()" 
+   role="button"
+   aria-label="{{'Component.ConfigItem.FormatItemValue' | translate }}"
+   title="{{'Component.ConfigItem.FormatItemValue' | translate }}">{{'Component.ConfigItem.FormatItemValue' | translate }}</a>
apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js (1)

248-257: Consider architectural improvements and add unit tests.

  1. The JSON formatting logic could be moved to a shared service to promote reuse across different components.
  2. As mentioned in the PR objectives, unit tests are missing. Consider adding tests for:
    • Formatting valid JSON
    • Handling invalid JSON
    • Handling empty/null values
    • Preserving original value on error

Would you like me to help with:

  1. Creating a shared service for JSON formatting?
  2. Generating unit test cases?
apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html (1)

193-199: LGTM! The format button implementation is well integrated.

The implementation follows the existing patterns for button styling, placement, and behavior. Good use of:

  • Conditional rendering with appropriate checks
  • Internationalization support
  • Consistent styling with other buttons
  • Tooltip for better UX

Consider adding keyboard shortcut support for the format action to improve accessibility. For example:

 <img src="img/brush.png" class="ns_btn cursor-pointer" data-tooltip="tooltip"
      data-placement="bottom"
      title="{{'Component.ConfigItem.FormatItemValue' | translate }}"
      ng-show="namespace.isTextEditing && namespace.viewType == 'text' && namespace.format == 'json'"
-     ng-click="formatContent(namespace)">
+     ng-click="formatContent(namespace)"
+     role="button"
+     tabindex="0"
+     ng-keydown="$event.keyCode === 13 && formatContent(namespace)">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8e4a73e and 65e9a36.

⛔ Files ignored due to path filters (1)
  • apollo-portal/src/main/resources/static/img/brush.png is excluded by !**/*.png
📒 Files selected for processing (7)
  • CHANGES.md (1 hunks)
  • apollo-portal/src/main/resources/static/i18n/en.json (1 hunks)
  • apollo-portal/src/main/resources/static/i18n/zh-CN.json (1 hunks)
  • apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js (2 hunks)
  • apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js (2 hunks)
  • apollo-portal/src/main/resources/static/views/component/item-modal.html (1 hunks)
  • apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • apollo-portal/src/main/resources/static/i18n/en.json
  • apollo-portal/src/main/resources/static/i18n/zh-CN.json
🔇 Additional comments (5)
apollo-portal/src/main/resources/static/views/component/item-modal.html (1)

68-70: LGTM! Well-placed formatting option for JSON content.

The formatting link is logically placed and correctly shown only for JSON type items (type='3'). The internationalization support ensures proper localization of the feature.

apollo-portal/src/main/resources/static/scripts/directive/item-modal-directive.js (1)

44-44: LGTM!

The formatContent function is correctly exposed to the directive's scope, following AngularJS best practices.

apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js (2)

89-89: LGTM! Appropriate scope function exposure

The function is correctly exposed to the directive's scope, maintaining consistency with other function declarations in the file.


738-747: Verify the template integration of formatContent

Let's ensure the function is properly integrated with the UI components.

✅ Verification successful

formatContent function is properly integrated with the UI

The function is correctly integrated in the template with a dedicated format button that appears when editing text in JSON format. The button is properly bound to the formatContent function through ng-click directive and has appropriate visibility conditions:

  • Button appears only when:
    • Text editing is active (namespace.isTextEditing)
    • View type is text (namespace.viewType == 'text')
    • Format is JSON (namespace.format == 'json')
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find the template file and verify the format button integration

# Search for the template file
echo "Searching for namespace panel template..."
fd "namespace-panel.html" --type f

# Search for formatContent usage in HTML files
echo "Checking formatContent usage in templates..."
rg -t html "formatContent"

Length of output: 693


Script:

#!/bin/bash
# Let's check the content of these files to understand the integration better

echo "Checking namespace-panel.html content..."
cat "apollo-portal/src/main/resources/static/views/component/namespace-panel.html"

echo -e "\nChecking namespace-panel-master-tab.html content..."
cat "apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html"

# Let's also check the directive file to see the complete context
echo -e "\nChecking namespace-panel-directive.js content..."
cat "apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js"

Length of output: 130961

apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html (1)

193-199: Verify required resources and dependencies.

Let's verify the existence of required resources:

  1. Translation key: Component.ConfigItem.FormatItemValue
  2. Image asset: img/brush.png
  3. Function: formatContent(namespace)
✅ Verification successful

All required resources and dependencies are present

All necessary components have been verified:

  • Translation key Component.ConfigItem.FormatItemValue exists in both en.json and zh-CN.json
  • Image asset brush.png is present at the correct location
  • formatContent(namespace) function is properly implemented in namespace-panel-directive.js with JSON formatting functionality
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for translation key
echo "Checking translation files..."
fd -e json . | xargs rg "Component\.ConfigItem\.FormatItemValue"

# Check for brush icon
echo "Checking for brush icon..."
fd "brush.png" .

# Check for formatContent function
echo "Checking for formatContent implementation..."
rg "formatContent.*function" -A 5

Length of output: 624


Script:

#!/bin/bash
# Let's try a different approach to find formatContent function
# Search for formatContent in JavaScript files
echo "Searching for formatContent in JS files..."
rg "formatContent" -t js -B 2 -A 5

# Also search in controller files specifically
echo "Searching in controller files..."
fd "controller.js" | xargs rg "formatContent" -B 2 -A 5

# Search in namespace related files
echo "Searching in namespace related files..."
rg "formatContent" --type-add 'web:*.{js,html}' -t web -g '*namespace*' -B 2 -A 5

Length of output: 7697

@WTIFS WTIFS changed the title feat: add JSON format in apollo-portal feat: add JSON format button in apollo-portal Nov 26, 2024
@nobodyiam nobodyiam requested a review from Copilot November 28, 2024 11:33
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 8 changed files in this pull request and generated 1 suggestion.

Files not reviewed (4)
  • apollo-portal/src/main/resources/static/i18n/en.json: Language not supported
  • apollo-portal/src/main/resources/static/i18n/zh-CN.json: Language not supported
  • apollo-portal/src/main/resources/static/views/component/item-modal.html: Language not supported
  • apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html: Language not supported

// 格式化
function formatContent() {
if (scope.showJsonError) {
return
Copy link
Member

Choose a reason for hiding this comment

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

This is a valid suggestion.

@WTIFS WTIFS requested a review from nobodyiam November 29, 2024 08:03
Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 1, 2024
@nobodyiam nobodyiam merged commit 5659fa5 into apolloconfig:master Dec 1, 2024
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants