Skip to content

Add Monetary Contribution Tabs#441

Merged
tarunnjoshi merged 2 commits intodevelopfrom
add-tabs-for-contribution
Nov 12, 2024
Merged

Add Monetary Contribution Tabs#441
tarunnjoshi merged 2 commits intodevelopfrom
add-tabs-for-contribution

Conversation

@tarunnjoshi
Copy link
Copy Markdown
Member

@tarunnjoshi tarunnjoshi commented Nov 12, 2024

Add Monetary Contribution Tabs

Summary by CodeRabbit

  • New Features

    • Introduced a new tab for 'Monetary Contribution' in the Dropping Center interface.
    • Added a 'monetaryContribution' tab for monetary contributions within the Collection Camp context.
    • Implemented a method for populating Indian state options for the 'Eck_Collection_Camp' entity.
  • Bug Fixes

    • No bug fixes were included in this release.
  • Documentation

    • Updated method signatures to reflect new tab configurations.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes in this pull request enhance the CollectionCampService and DroppingCenterService classes by introducing new tab configurations. Specifically, a new tab for 'monetaryContribution' is added to the CollectionCampService, while the DroppingCenterService receives a new tab labeled "Monetary Contribution." Additionally, a new method, setIndianStateOptions, is introduced in the CollectionCampService to populate state options for the 'Eck_Collection_Camp' entity. The modifications maintain existing logic while expanding user interface options.

Changes

File Path Change Summary
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php - Added method: setIndianStateOptions for populating Indian state options.
- Updated collectionCampTabset to include a new tab for 'monetaryContribution'.
wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php - Updated droppingCenterTabset to add a new tab labeled "Monetary Contribution".

Possibly related PRs

Suggested labels

status : ready for review

Suggested reviewers

  • pokhiii

🌟 In the code where tabs now gleam,
New features added, like a dream!
From camps to contributions, oh what a sight,
Enhancing the service, making it bright!
With states and tabs, all in a row,
Here’s to the changes, let the progress flow! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ac8ba7d and 26e11fe.

📒 Files selected for processing (2)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php
  • wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php

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
Copy Markdown

@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

🧹 Outside diff range and nitpick comments (5)
wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php (2)

528-533: Consider refactoring tab configuration for better maintainability.

The tab configuration array has grown quite large and contains repetitive structures. Consider these improvements:

  1. Extract common configuration to reduce duplication
  2. Move 'is_active' out of the loop as it's constant (as per previous feedback)

Here's a suggested refactor:

  private static $DEFAULT_TAB_CONFIG = [
    'is_active' => 1,
    'template' => 'CRM/Goonjcustom/Tabs/CollectionCamp.tpl',
  ];

  public static function droppingCenterTabset($tabsetName, &$tabs, $context) {
    if (!self::isViewingDroppingCenter($tabsetName, $context)) {
      return;
    }
    $tabConfigs = [
      'monetary' => [
        'title' => ts('Monetary Contribution'),
        'module' => 'afsearchMonetaryContribution',
        'directive' => 'afsearch-monetary-contribution',
      ],
      // ... other tabs
    ];

    foreach ($tabConfigs as $key => $config) {
      $tabs[$key] = array_merge(
        self::$DEFAULT_TAB_CONFIG,
        [
          'id' => $key,
          'title' => $config['title'],
          'module' => $config['module'],
          'directive' => $config['directive'],
        ]
      );

      \Civi::service('angularjs.loader')->addModules($config['module']);
    }
  }

Also applies to: 534-547


Missing Angular.js module implementation

The code references an Angular.js module afsearchMonetaryContribution and directive afsearch-monetary-contribution, but their implementations are missing from the codebase. This will cause runtime errors when the tab is loaded.

  • Add the Angular.js module implementation in a new JavaScript file under wp-content/civi-extensions/goonjcustom/ang/
  • Implement the corresponding directive afsearch-monetary-contribution
  • Register the new JavaScript file in the extension's info.xml
🔗 Analysis chain

Line range hint 528-547: Verify Angular.js module implementation.

The new tab requires a corresponding Angular.js module. Let's verify its implementation.


The previous search might have been too specific. Let's broaden our search to find Angular.js related implementations and the associated template files to verify the integration points.


Let's verify the template file's content and search for the Angular.js module implementation in the extension directory.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the Angular.js module implementation
rg -l "afsearchMonetaryContribution" --type js

Length of output: 46


Script:

#!/bin/bash
# Let's try a broader search for Angular module definitions and related files
rg -l "angular\.module" --type js

# Also search for the template file mentioned in the config
fd "CollectionCamp.tpl"

# Search for any monetary contribution related files
rg -l "monetary.*contribution" -i

Length of output: 22661


Script:

#!/bin/bash
# Let's check the content of the template file and search for any Angular.js directives
cat "wp-content/civi-extensions/goonjcustom/templates/CRM/Goonjcustom/Tabs/CollectionCamp.tpl"

# Let's also search for any JavaScript files in the goonjcustom extension that might contain the Angular module
fd -e js . wp-content/civi-extensions/goonjcustom/

# Search for any files containing afsearch-monetary-contribution directive
rg "afsearch-monetary-contribution"

Length of output: 695

wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (3)

Line range hint 516-551: Consider optimizing state options retrieval

While the implementation is correct, consider caching the state options to improve performance, especially if this method is called frequently.

 public static function setIndianStateOptions(string $entity, string $field, array &$options, array $params) {
+    static $cachedStateOptions = null;
     if ($entity !== 'Eck_Collection_Camp') {
       return;
     }

     $intentStateFields = CustomField::get(FALSE)
       ->addWhere('custom_group_id:name', '=', 'Collection_Camp_Intent_Details')
       ->addWhere('name', '=', 'State')
       ->execute();

     $stateField = $intentStateFields->first();
     $statefieldId = $stateField['id'];

     if ($field !== "custom_$statefieldId") {
       return;
     }

+    if ($cachedStateOptions !== null) {
+      $options = $cachedStateOptions;
+      return;
+    }

     $indianStates = StateProvince::get(FALSE)
       ->addWhere('country_id.iso_code', '=', 'IN')
       ->addOrderBy('name', 'ASC')
       ->execute();

     $stateOptions = [];
     foreach ($indianStates as $state) {
       if ($state['is_active']) {
         $stateOptions[$state['id']] = $state['name'];
       }
     }

+    $cachedStateOptions = $stateOptions;
     $options = $stateOptions;
 }

Line range hint 789-793: Enhance error logging with context

The catch block suppresses the exception with @IgnoreException comment. Consider logging the error with proper context for better debugging.

     }
-    catch (\Exception $e) {
-      // @ignoreException
+    catch (\Exception $e) {
+      \Civi::log()->error(sprintf(
+        'Failed to regenerate QR code for collection camp ID %d: %s',
+        $collectionCampId,
+        $e->getMessage()
+      ));
     }

Line range hint 1-1200: Consider splitting the class into smaller, focused services

The CollectionCampService class has grown to handle multiple responsibilities including:

  • Collection camp management
  • QR code generation
  • Email notifications
  • State management
  • Activity tracking

Consider extracting these into separate service classes to improve maintainability and testability.

Suggested structure:

namespace Civi\Service;

class CollectionCampService { /* core camp management */ }
class CampNotificationService { /* email handling */ }
class CampQRCodeService { /* QR code generation */ }
class CampActivityService { /* activity tracking */ }
class StateManagementService { /* state options */ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 38671fe and ac8ba7d.

📒 Files selected for processing (2)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1 hunks)
  • wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php (1 hunks)
🧰 Additional context used
📓 Learnings (1)
wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php (4)
Learnt from: belwalshubham
PR: ColoredCow/goonj#338
File: wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php:69-70
Timestamp: 2024-11-12T05:35:07.895Z
Learning: In `DroppingCenterService.php` (PHP, CiviCRM framework), when the `is_active` property remains constant (`1`) for all tabs in the `droppingCenterTabset` method, it's preferred to hardcode `is_active` in the loop instead of including it in the `$tabConfigs` array to reduce redundancy.
Learnt from: belwalshubham
PR: ColoredCow/goonj#338
File: wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php:69-70
Timestamp: 2024-11-12T05:35:07.895Z
Learning: In `DroppingCenterService.php` (PHP, CiviCRM framework), when the `is_active` property remains constant (`1`) for all tabs in the `droppingCenterTabset` method, it's preferred to hardcode `is_active` in the loop instead of including it in the `$tabConfigs` array to reduce redundancy.
Learnt from: belwalshubham
PR: ColoredCow/goonj#338
File: wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php:69-70
Timestamp: 2024-11-12T05:35:07.895Z
Learning: In `DroppingCenterService.php` (PHP, CiviCRM framework), when the `is_active` property remains constant (`1`) for all tabs in the `droppingCenterTabset` method, it's preferred to hardcode `is_active` in the loop instead of including it in the `$tabConfigs` array to reduce redundancy.
Learnt from: belwalshubham
PR: ColoredCow/goonj#338
File: wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php:69-70
Timestamp: 2024-11-12T05:35:07.894Z
Learning: In `DroppingCenterService.php` (PHP, CiviCRM framework), when the `is_active` property remains constant (`1`) for all tabs in the `droppingCenterTabset` method, it's preferred to hardcode `is_active` in the loop instead of including it in the `$tabConfigs` array to reduce redundancy.
🔇 Additional comments (2)
wp-content/civi-extensions/goonjcustom/Civi/DroppingCenterService.php (1)

528-533: LGTM! New tab configuration follows established patterns.

The new monetary contribution tab configuration maintains consistency with existing tabs and follows the established naming conventions.

wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1)

130-135: LGTM: New monetary contribution tab configuration is well-structured

The new tab configuration follows the established pattern and includes all required fields.

@tarunnjoshi
Copy link
Copy Markdown
Member Author

Merging as only adding tabs on the Collection camp and Dropping centre

@tarunnjoshi tarunnjoshi merged commit e0d4dce into develop Nov 12, 2024
@tarunnjoshi tarunnjoshi deleted the add-tabs-for-contribution branch November 12, 2024 09:30
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.

1 participant