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

HP-2352: new featrue export link with stock locations for model index #186

Merged
merged 1 commit into from
Mar 19, 2025

Conversation

tafid
Copy link
Member

@tafid tafid commented Mar 19, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced location management now lets users dynamically update and retrieve location data, including a quick reset option for applied filters.
    • Improved export functionality offers additional, clearly structured export options.
    • Upgraded stock locations interface features a refreshed layout and styling, providing a smoother and more responsive user experience.

Copy link

coderabbitai bot commented Mar 19, 2025

Walkthrough

The changes update the controller’s functionality by employing modern PHP syntax and adding new actions for managing locations and export variants. The modifications include renaming and adding methods in the ModelController, integrating request data into the StockLocationsProvider, and enhancing view files with improved parameter passing and annotations. The widget now enforces strict typing, registers additional Vue.js functionality, and updates AJAX endpoints. Overall, the changes refine code readability, update dependencies, and adjust control flows for handling export links and dynamic location data.

Changes

File(s) Summary of Changes
src/controllers/ModelController.php Added imports (Closure, Response, Html); updated actions method with short closure syntax and included a call to new getExportVariants(); renamed actionSaveLocations to actionSetLocations; added new actionGetLocations() method and protected getExportVariants() method.
src/helpers/StockLocationsProvider.php Updated constructor to include Request dependency; simplified constructor body; enhanced getLocations to extract location data from the request’s 'ModelSearch' parameter.
src/views/model/_search.php, src/views/model/index.php Added PHPDoc annotations for variables in _search.php; in index.php, introduced a new Closure $exportVariants variable and passed parameters explicitly to IndexPage::begin().
src/widgets/StockLocationsListTreeSelect.php Enforced strict types; added import for yii\helpers\Url; adjusted constructor formatting; modified run() to include additional CSS and a reset button; added methods locationsInQueryParams() and resetQueryLocations(); updated AJAX endpoint from save-locations to set-locations and simplified option building.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant W as StockLocationsListTreeSelect
    participant MC as ModelController
    participant SP as StockLocationsProvider

    U->>W: Interact with stock locations widget
    W->>MC: AJAX POST to "set-locations" (via onChange)
    MC->>SP: Retrieve locations from Request
    SP-->>MC: Return processed location data
    MC->>W: Respond with JSON (updated locations)
    U->>W: Click reset button (if query params exist)
    W->>MC: (Optionally) Request default locations via actionGetLocations
    MC->>SP: Get default location data
    SP-->>MC: Return default locations
    MC->>W: JSON response with default locations
Loading
sequenceDiagram
    participant V as IndexView
    participant MC as ModelController
    participant EV as getExportVariants()

    V->>MC: Request index page rendering
    MC->>EV: Invoke getExportVariants() to obtain export link info
    EV-->>MC: Return export variants array
    MC->>V: Render index page with explicit exportVariants parameter
Loading

Poem

I’m a rabbit in a code-filled glade,
Hopping through functions with a keen parade.
Export links and locations, fresh and bright,
New closures and resets make my world light.
With each neat change and AJAX hop,
I celebrate code that just won’t stop! 🐇🎉
Happy hops to cleaner code and joyful updates!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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

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

🧹 Nitpick comments (2)
src/controllers/ModelController.php (2)

189-192: Good addition of new method for AJAX functionality.

The new actionGetLocations() method provides an endpoint to retrieve locations as JSON, supporting AJAX functionality.

Consider adding try/catch error handling to make the endpoint more robust:

public function actionGetLocations(): Response
{
+   try {
        return $this->asJson($this->locationsProvider->getLocations());
+   } catch (\Exception $e) {
+       return $this->asJson(['error' => $e->getMessage()]);
+   }
}

194-209: Well-structured method for export variants.

The new getExportVariants() method properly constructs an array that includes export link information with stock locations.

Consider using \Closure instead of Closure for the return type hint to be more explicit about the namespace:

-protected function getExportVariants(): Closure
+protected function getExportVariants(): \Closure
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 68b9f93 and b2e192f.

📒 Files selected for processing (5)
  • src/controllers/ModelController.php (6 hunks)
  • src/helpers/StockLocationsProvider.php (4 hunks)
  • src/views/model/_search.php (1 hunks)
  • src/views/model/index.php (2 hunks)
  • src/widgets/StockLocationsListTreeSelect.php (9 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/controllers/ModelController.php (3)
src/controllers/PartController.php (3) (3)
  • getTypes (533-536)
  • getBrands (544-547)
  • getStates (538-541)
src/controllers/MoveController.php (1) (1)
  • getTypes (65-68)
src/helpers/StockLocationsProvider.php (1) (1)
  • getLocations (41-59)
🔇 Additional comments (20)
src/views/model/index.php (2)

19-19: Good addition of PHPDoc type annotation.

Adding the @var Closure $exportVariants annotation improves code documentation and IDE support.


32-32: Properly updated parameter passing.

The code correctly passes the new $exportVariants parameter to the IndexPage::begin() method using an associative array, which is more explicit than the previous compact() approach.

src/views/model/_search.php (1)

5-9: Good addition of type annotations.

Adding PHPDoc type annotations for the variables $search, $types, $brands, and $states improves code clarity and IDE support.

src/helpers/StockLocationsProvider.php (3)

3-3: Good use of strict typing.

Adding declare(strict_types=1); is a good practice to enforce type checking and catch potential type-related issues.


20-25: Proper use of modern PHP constructor property promotion.

The constructor has been updated to use readonly properties and property promotion, which makes the code more concise and less error-prone.


43-46: Correctly handles request data for locations.

The code now checks if locations are available in the request and updates the internal state accordingly. This provides more flexibility in how locations are managed.

src/controllers/ModelController.php (4)

14-14: Good addition of necessary imports.

The imports for Closure, Response, and Html are properly added to support the new functionality.

Also applies to: 29-30


68-73: Improved code with modern PHP arrow functions.

The data callback has been updated to use the more concise arrow function syntax, and now includes the exportVariants in the returned array, which is needed for the new export functionality.


75-75: Simplified response variant with arrow function.

The get-total-count response variant has been simplified using arrow function syntax, which is more readable.


180-180:

❓ Verification inconclusive

Method renamed for better semantics.

Renaming actionSaveLocations() to actionSetLocations() better reflects the purpose of the method.

This method renaming might break existing code if it's referenced elsewhere. Let's verify if there are any references to the old method name:


🏁 Script executed:

#!/bin/bash
# Search for references to the old "actionSaveLocations" method
rg -l "actionSaveLocations|save-locations"

Length of output: 44


Renaming verified but manual confirmation recommended.
The automated search for references to the old method name (actionSaveLocations/save-locations) in the repository returned no matches, indicating that there appear to be no remaining dependencies on the deprecated method name. However, given the ambiguous search output, please manually verify across the codebase to ensure no lingering calls to the old method.

  • File to check: src/controllers/ModelController.php (line 180 and surrounding context)
  • Ensure that no external modules, documentation, or tests reference actionSaveLocations.
src/widgets/StockLocationsListTreeSelect.php (10)

16-16: New import for URL handling:

The Url helper is now imported to support new functionality for handling URLs, particularly for the reset query locations feature.


34-34: Formatting improvement:

Code consistency improvement by moving the constructor's opening brace to the same line as the function declaration.


62-82: Enhanced CSS styling implementation:

Good addition of CSS styles for the tree select component that improves layout with flexbox properties. The Vue cloak directive ensures content is hidden until Vue.js is fully loaded, preventing flash of unstyled content.


84-118: Improved method structure and UI enhancement:

The run method now includes better documentation and a reset button for query locations. The button provides better UX by allowing users to easily revert to preferred stock locations.


123-141: New export functionality:

Good implementation of export functionality that captures current locations and appends them to the export URL. The code correctly prevents default link behavior and uses modern JavaScript features.


161-169: Well-structured query parameter check:

This method efficiently checks if locations exist in the URL query parameters, which is used to conditionally display the reset button.


170-172: Simple and effective query location reset:

The reset functionality is implemented cleanly, redirecting to the current URL with location parameters removed.


205-206: Proper URL generation for reset functionality:

Good use of Url::current() with the locations parameter nullified to ensure a clean URL state when resetting.


220-220: Simplified return statement:

The return statement in buildOptions() has been simplified by removing unnecessary code, improving readability.


178-178:

✅ Verification successful

API endpoint renamed:

The endpoint has been changed from 'save-locations' to 'set-locations'. This likely corresponds with a renamed controller action elsewhere in the codebase.

Ensure that the corresponding controller action has been renamed from actionSaveLocations to actionSetLocations in the related controller file.


🏁 Script executed:

#!/bin/bash
# Check if the endpoint exists in controllers
rg -A 5 -B 5 "actionSetLocations|actionSaveLocations" --type php

Length of output: 808


Endpoint rename confirmed: 'set-locations' correctly calls actionSetLocations

The verification confirms that the controller action has indeed been renamed from actionSaveLocations to actionSetLocations in src/controllers/ModelController.php. The widget code calling $.post('set-locations', {locations: value}) aligns with the updated endpoint without any discrepancies.

Comment on lines +110 to +112
<button class="btn btn-xs btn-danger btn-flat" v-cloak v-show="locationsInQueryParams()" @click="resetQueryLocations">
<i class="fa fa-fw fa-undo"></i> %s
</buttonl>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

UI issue in reset button HTML:

There's a typo in the HTML tag - </buttonl> should be </button>.

-                </buttonl>
+                </button>
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<button class="btn btn-xs btn-danger btn-flat" v-cloak v-show="locationsInQueryParams()" @click="resetQueryLocations">
<i class="fa fa-fw fa-undo"></i> %s
</buttonl>
<button class="btn btn-xs btn-danger btn-flat" v-cloak v-show="locationsInQueryParams()" @click="resetQueryLocations">
<i class="fa fa-fw fa-undo"></i> %s
</button>

@SilverFire SilverFire merged commit feddbca into hiqdev:master Mar 19, 2025
1 check passed
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