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

PCC-59: Views integration with pcc site entity. #4

Merged
merged 2 commits into from
May 17, 2024
Merged

Conversation

sonvir249
Copy link
Collaborator

@sonvir249 sonvir249 commented May 16, 2024

Fixes - https://digitalpolygon.atlassian.net/browse/PCC-59

Things covered:

  1. Created a views integration with PCC site entity
  2. Added title, content, snipped, createdAt, and published at fields in views
  3. Added cache clear in PCC Site form to populate the updated pcc site in views content.
  4. PccSiteViewHelper.php helper class to get pcc entity related data.

Summary by CodeRabbit

  • New Features

    • Introduced a new Views query class for Config Entities, enhancing the customization of views related to PCC sites.
  • Improvements

    • Enhanced documentation and code clarity for the ApiStatusController class.
    • Improved cache management in the PccSite entity to ensure up-to-date views.
  • Bug Fixes

    • Corrected formatting issues in the ApiStatusController class documentation.

These updates aim to improve the functionality and maintainability of PCC site views and API status handling.

@sonvir249 sonvir249 requested a review from gauravgoyal May 16, 2024 15:39
Copy link

coderabbitai bot commented May 16, 2024

Walkthrough

The recent changes bring significant enhancements to the PCX Connect module in Drupal. These updates refine Views hook implementations, improve the PccSite entity with cache-clearing logic, introduce helper methods in PccSiteViewHelper, and create a new Views query class, PccSiteViewQuery, to manage Config Entities. These changes collectively optimize data handling, refine code documentation, and boost the module's performance and maintainability.

Changes

File Path Change Summary
pcx_connect.views.inc Added pcx_connect_views_data() function for Views hook implementations.
src/Controller/ApiStatusController.php Refined class documentation, updated return type hint, and removed an extra line break.
src/Entity/PccSite.php Added imports and cache-clearing logic in the postSave method.
src/PccSiteViewHelper.php Introduced helper methods for customizing views.
src/Plugin/views/query/PccSiteViewQuery.php Defined a new Views query class for Config Entities with methods for table checks and field addition.

In fields of code where data flows,
With hooks and helpers, our module grows.
Cache cleared, views refined,
In every line, improvements you'll find.
A rabbit's touch, in every byte,
Making Drupal shine so bright! 🐇✨

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

@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: 9

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between b4c8514 and 7f234fa.
Files selected for processing (5)
  • pcx_connect.views.inc (1 hunks)
  • src/Controller/ApiStatusController.php (1 hunks)
  • src/Entity/PccSite.php (2 hunks)
  • src/PccSiteViewHelper.php (1 hunks)
  • src/Plugin/views/query/PccSiteViewQuery.php (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/Controller/ApiStatusController.php
Additional comments not posted (7)
src/PccSiteViewHelper.php (2)

60-61: LGTM!


75-79: LGTM!

src/Plugin/views/query/PccSiteViewQuery.php (5)

34-36: LGTM!


41-47: LGTM!


56-57: LGTM!


77-78: LGTM!


84-91: Verify the necessity of the TODO comment.

Please confirm if the TODO comment is still relevant or if it can be removed.

Comment on lines 62 to 69
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);

// Clear cache to populate the PCC site in views.
if (\Drupal::moduleHandler()->moduleExists('views')) {
Views::viewsData()->clear();
\Drupal::cache('discovery')->delete('views:wizard');
}
Copy link

Choose a reason for hiding this comment

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

Use dependency injection for better testability and adherence to Drupal best practices.

-  if (\Drupal::moduleHandler()->moduleExists('views')) {
-    Views::viewsData()->clear();
-    \Drupal::cache('discovery')->delete('views:wizard');
-  }
+  $module_handler = \Drupal::service('module_handler');
+  $views_data = \Drupal::service('views.views_data');
+  $cache_discovery = \Drupal::service('cache.discovery');
+  if ($module_handler->moduleExists('views')) {
+    $views_data->clear();
+    $cache_discovery->delete('views:wizard');
+  }

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.

Suggested change
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
// Clear cache to populate the PCC site in views.
if (\Drupal::moduleHandler()->moduleExists('views')) {
Views::viewsData()->clear();
\Drupal::cache('discovery')->delete('views:wizard');
}
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
// Clear cache to populate the PCC site in views.
$module_handler = \Drupal::service('module_handler');
$views_data = \Drupal::service('views.views_data');
$cache_discovery = \Drupal::service('cache.discovery');
if ($module_handler->moduleExists('views')) {
$views_data->clear();
$cache_discovery->delete('views:wizard');
}

Comment on lines 16 to 17
* @return array|null
* Returns array of Entity attributes.
Copy link

Choose a reason for hiding this comment

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

Update the return type in the docblock to reflect the actual return type.

-  * @return array|null
+  * @return array

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.

Suggested change
* @return array|null
* Returns array of Entity attributes.
* @return array
* Returns array of Entity attributes.

src/PccSiteViewHelper.php Outdated Show resolved Hide resolved
pcx_connect.views.inc Outdated Show resolved Hide resolved
pcx_connect.views.inc Outdated Show resolved Hide resolved
pcx_connect.views.inc Outdated Show resolved Hide resolved
Comment on lines 69 to 70
'title' => t('Content'),
'help' => t('Article Content'),
Copy link

Choose a reason for hiding this comment

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

Replace the t() function with \Drupal::translation()->translate() for better performance.

-  $table['content'] = [
-    'title' => t('Content'),
-    'help' => t('Article Content'),
-    'field' => [
-      'id' => 'standard',
-      'click sortable' => FALSE,
-    ],
-    'filter' => [
-      'id' => 'string',
-    ],
-  ];
+  $table['content'] = [
+    'title' => \Drupal::translation()->translate('Content'),
+    'help' => \Drupal::translation()->translate('Article Content'),
+    'field' => [
+      'id' => 'standard',
+      'click sortable' => FALSE,
+    ],
+    'filter' => [
+      'id' => 'string',
+    ],
+  ];

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.

Suggested change
'title' => t('Content'),
'help' => t('Article Content'),
'title' => \Drupal::translation()->translate('Content'),
'help' => \Drupal::translation()->translate('Article Content'),

pcx_connect.views.inc Outdated Show resolved Hide resolved
pcx_connect.views.inc Outdated Show resolved Hide resolved
Copy link

@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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7f234fa and 5ebd91e.
Files selected for processing (3)
  • pcx_connect.views.inc (1 hunks)
  • src/Entity/PccSite.php (3 hunks)
  • src/PccSiteViewHelper.php (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • pcx_connect.views.inc
  • src/Entity/PccSite.php
  • src/PccSiteViewHelper.php

@gauravgoyal gauravgoyal merged commit 21f70cd into main May 17, 2024
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.

2 participants