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

Add plugin dashboard page sample #2937

Merged
merged 7 commits into from
Nov 13, 2024
Merged

Conversation

acicovic
Copy link
Collaborator

@acicovic acicovic commented Nov 12, 2024

Description

This PR adds a sample plugin dashboard page.

Motivation and context

We want to add a plugin dashboard page from which the Traffic Boost feature (and possibly other features) will be available.

How has this been tested?

Manually tested that the React app renders, as seen in the screenshot.

Screenshots

image

Summary by CodeRabbit

  • New Features

    • Introduced a new dashboard page for the Parsely plugin in the WordPress admin interface.
    • Added a user-friendly layout with a welcoming message on the dashboard.
  • Bug Fixes

    • Streamlined imports by removing unused classes, enhancing plugin performance.
  • Documentation

    • Improved comments for better clarity on the new dashboard functionality.
  • Chores

    • Updated build configuration to support new TypeScript files and dashboard page styling.

@acicovic acicovic added this to the 3.18.0 milestone Nov 12, 2024
Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

📝 Walkthrough

Walkthrough

The pull request introduces a new dashboard feature for the Parsely plugin in WordPress. It includes the creation of a Dashboard_Page class to manage the dashboard's rendering and functionality. The associated SCSS and TypeScript files are added to support styling and interactivity. The webpack.config.js is updated to handle these new files, and modifications are made to the main plugin file to integrate the new dashboard feature while cleaning up unused imports.

Changes

File Change Summary
src/UI/class-dashboard-page.php Added Dashboard_Page class with methods for running, adding to menu, rendering, and enqueuing scripts.
src/content-helper/dashboard-page/dashboard-page.scss Added imports for shared variables and functions from the common CSS directory.
src/content-helper/dashboard-page/dashboard-page.tsx Created new TypeScript file for rendering the dashboard page in WordPress.
webpack.config.js Added new entry for dashboard page and updated module rules to include TypeScript support.
wp-parsely.php Imported Dashboard_Page, instantiated it, and called its run method; removed unused class imports.

Possibly related PRs

  • Add the Excerpt Suggestions feature to the PCH sidebar #2811: The changes in this PR involve the introduction of a new feature related to the sidebar in the WordPress editor, which may share user interface considerations with the dashboard page functionality introduced in the main PR. However, there is no direct code-level connection to the Dashboard_Page class or its methods.

Suggested labels

Changelog: Added


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.

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.

@acicovic acicovic marked this pull request as ready for review November 13, 2024 07:54
@acicovic acicovic requested a review from a team as a code owner November 13, 2024 07:54
@acicovic
Copy link
Collaborator Author

The SonarCloud fail can be ignored, it's about code duplication that will be insignificant after merge.

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 (5)
webpack.config.js (1)

Line range hint 38-43: Consider enhancing TypeScript configuration for better type safety.

While the basic TypeScript loader is configured correctly, consider adding TypeScript-specific webpack configurations for improved type checking and compatibility.

Add these configurations to enhance TypeScript support:

 module: {
   rules: defaultConfig.module.rules.concat(
     [
       {
         test: /\.tsx?$/,
-        use: 'ts-loader',
+        use: {
+          loader: 'ts-loader',
+          options: {
+            transpileOnly: false,
+            compilerOptions: {
+              module: 'es6',
+              target: 'es5',
+              jsx: 'react',
+              moduleResolution: 'node',
+              allowSyntheticDefaultImports: true,
+            },
+          },
+        },
       },
     ]
   ),
 },
+resolve: {
+  ...defaultConfig.resolve,
+  extensions: ['.tsx', '.ts', '.js', '.jsx'],
+},
wp-parsely.php (1)

Line range hint 1-24: Consider updating plugin metadata to reflect new dashboard feature.

Since this PR introduces a significant new feature (plugin dashboard), consider updating the plugin description to mention this capability.

Apply this diff to the plugin metadata:

 * @wordpress-plugin
 * Plugin Name:       Parse.ly
 * Plugin URI:        https://docs.parse.ly/wordpress
-* Description:       This plugin makes it a snap to add Parse.ly tracking code and metadata to your WordPress blog.
+* Description:       This plugin makes it a snap to add Parse.ly tracking code and metadata to your WordPress blog, with a centralized dashboard for managing features.
src/UI/class-dashboard-page.php (3)

18-23: Consider enhancing the class documentation.

While the documentation follows WordPress standards, it could be more descriptive by including:

  • The purpose of the dashboard page
  • How it integrates with WordPress admin
  • Any dependencies or requirements

40-42: Consider moving the SVG icon to a separate file.

The base64-encoded SVG icon makes the code harder to maintain. Consider:

  1. Moving it to a separate asset file
  2. Loading it dynamically using WordPress asset functions

60-62: Enhance the dashboard placeholder with loading state.

The empty div could benefit from:

  1. A loading indicator
  2. Error boundary
  3. Accessibility attributes
-		echo '<div id="parsely-dashboard-page"></div>';
+		echo '<div id="parsely-dashboard-page" aria-busy="true" role="main">
+			<div class="parsely-dashboard-loading">Loading Parse.ly Dashboard...</div>
+		</div>';
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8760356 and a6f1b07.

⛔ Files ignored due to path filters (4)
  • build/content-helper/dashboard-page-rtl.css is excluded by !build/**
  • build/content-helper/dashboard-page.asset.php is excluded by !build/**
  • build/content-helper/dashboard-page.css is excluded by !build/**
  • build/content-helper/dashboard-page.js is excluded by !build/**
📒 Files selected for processing (5)
  • src/UI/class-dashboard-page.php (1 hunks)
  • src/content-helper/dashboard-page/dashboard-page.scss (1 hunks)
  • src/content-helper/dashboard-page/dashboard-page.tsx (1 hunks)
  • webpack.config.js (1 hunks)
  • wp-parsely.php (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/content-helper/dashboard-page/dashboard-page.scss
  • src/content-helper/dashboard-page/dashboard-page.tsx
🧰 Additional context used
📓 Path-based instructions (3)
src/UI/class-dashboard-page.php (1)

Pattern **/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
  • Ensure the code follows WordPress coding standards and is well-documented.
  • Confirm the code is secure and free from vulnerabilities.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
webpack.config.js (1)

Pattern **/*.{js,ts,tsx,jsx}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the code to ensure it is well-structured and adheres to best practices.
  • Verify compliance with WordPress coding standards.
  • Ensure the code is well-documented.
  • Check for security vulnerabilities and confirm the code is secure.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate JSDoc comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Confirm every JSDoc comment includes a @SInCE tag indicating the next version of the plugin to include the code.
  • Guarantee compatibility with the latest version of WordPress, avoiding deprecated functions or features."
wp-parsely.php (1)

Pattern **/*.{html,php}: "Perform a detailed review of the provided code with following key aspects in mind:

  • Review the HTML and PHP code to ensure it is well-structured and adheres to best practices.
  • Ensure the code follows WordPress coding standards and is well-documented.
  • Confirm the code is secure and free from vulnerabilities.
  • Optimize the code for performance, removing any unnecessary elements.
  • Validate comments for accuracy, currency, and adherence to WordPress coding standards.
  • Ensure each line comment concludes with a period.
  • Verify code compatibility with the latest version of WordPress, avoiding deprecated functions or features."
🔇 Additional comments (5)
webpack.config.js (1)

12-15: LGTM! Entry point configuration follows established patterns.

The new dashboard page entry point is well-structured and consistent with other content-helper entries in the configuration.

wp-parsely.php (1)

39-39: LGTM!

The import follows the established pattern and maintains alphabetical ordering within the UI namespace imports.

src/UI/class-dashboard-page.php (3)

1-17: LGTM! Well-structured file header and imports.

The file follows WordPress coding standards with proper documentation, strict typing, and organized imports.


29-32: LGTM! Proper WordPress action hook implementation.

The method correctly hooks into WordPress admin actions for menu registration and script enqueuing.


47-47: Verify the capability constant usage.

The use of Parsely::CAPABILITY should be verified to ensure proper access control.

✅ Verification successful

Let me search for more context about how this capability is being used across the codebase.


Capability constant usage is properly defined and consistently used

The Parsely::CAPABILITY is correctly defined as manage_options in the main class and is consistently used across the codebase for access control in dashboard, settings, and network admin pages. This is a standard WordPress capability that restricts access to administrative users only.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the CAPABILITY constant definition and usage
rg -A 2 "const CAPABILITY" 

Length of output: 262


Script:

#!/bin/bash
# Search for usage of CAPABILITY constant
rg "Parsely::CAPABILITY"

Length of output: 424

wp-parsely.php Show resolved Hide resolved
src/UI/class-dashboard-page.php Show resolved Hide resolved
@acicovic
Copy link
Collaborator Author

@vaurdan, I think we should review/merge this in order to avoid having too many PRs based on other PRs.

Copy link
Contributor

@vaurdan vaurdan left a comment

Choose a reason for hiding this comment

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

Let's merge!

@acicovic acicovic merged commit 22a3772 into add/traffic-boost Nov 13, 2024
36 of 37 checks passed
@acicovic acicovic deleted the add/plugin-dashboard-page branch November 13, 2024 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants