-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
WalkthroughThe 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
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
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
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 ofClosure
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
📒 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 theIndexPage::begin()
method using an associative array, which is more explicit than the previouscompact()
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
, andHtml
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()
toactionSetLocations()
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
toactionSetLocations
in the related controller file.
🏁 Script executed:
#!/bin/bash # Check if the endpoint exists in controllers rg -A 5 -B 5 "actionSetLocations|actionSaveLocations" --type phpLength of output: 808
Endpoint rename confirmed: 'set-locations' correctly calls actionSetLocations
The verification confirms that the controller action has indeed been renamed from
actionSaveLocations
toactionSetLocations
insrc/controllers/ModelController.php
. The widget code calling$.post('set-locations', {locations: value})
aligns with the updated endpoint without any discrepancies.
<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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
<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> |
Summary by CodeRabbit