-
Notifications
You must be signed in to change notification settings - Fork 112
core: frontend: modelHelper code cleanup #3498
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
core: frontend: modelHelper code cleanup #3498
Conversation
It's not important to check the connected vehicle type if you're intending to ignore it anyway.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR refactors modelHelper.ts by cleaning up switch-case indentation in vehicle_folder and optimizing the checkModelOverrides function to attempt a global override before awaiting vehicle metadata, improving code readability and slight performance. Sequence diagram for the updated checkModelOverrides logicsequenceDiagram
participant ModelHelper
participant Axios
participant Autopilot
participant Sleep
ModelHelper->>Axios: HEAD /userdata/modeloverrides/ALL.glb
alt Global override exists
Axios-->>ModelHelper: Success
ModelHelper-->>ModelHelper: Return master_override
else Global override missing
Axios-->>ModelHelper: Error
ModelHelper->>Autopilot: Check vehicle_type and frame_type
loop Until vehicle_type and frame_type are available
ModelHelper->>Sleep: sleep(100)
end
ModelHelper->>Axios: HEAD /userdata/modeloverrides/{vehicle_folder}/{frame_name}.glb
alt Vehicle override exists
Axios-->>ModelHelper: Success
ModelHelper-->>ModelHelper: Return vehicle_override
else Vehicle override missing
Axios-->>ModelHelper: Error
end
end
Class diagram for updated modelHelper functionsclassDiagram
class modelHelper {
+vehicle_folder(): string
+frame_name(vehicle_type: string, frame_type?: number, frame_subtype?: number): string
+checkModelOverrides(): Promise<string | undefined>
}
class autopilot {
+vehicle_type: string
}
modelHelper --> autopilot: uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey there - I've reviewed your changes - here's some feedback:
- Consider adding a timeout or max retry count to the polling loop waiting on autopilot.vehicle_type and frame_type to avoid potential infinite blocking.
- Extract the polling logic into a reusable helper to improve clarity and reduce duplication if used elsewhere.
- Add an explicit default return or error throw at the end of checkModelOverrides to handle the case where neither master nor vehicle-specific override is found.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider adding a timeout or max retry count to the polling loop waiting on autopilot.vehicle_type and frame_type to avoid potential infinite blocking.
- Extract the polling logic into a reusable helper to improve clarity and reduce duplication if used elsewhere.
- Add an explicit default return or error throw at the end of checkModelOverrides to handle the case where neither master nor vehicle-specific override is found.
## Individual Comments
### Comment 1
<location> `core/frontend/src/components/vehiclesetup/viewers/modelHelper.ts:27` </location>
<code_context>
+ case MavType.MAV_TYPE_GROUND_ROVER:
+ return 'rover'
default:
- return autopilot.vehicle_type?.toLowerCase() || 'unknown'
+ return autopilot.vehicle_type?.toLowerCase() || 'unknown'
}
</code_context>
<issue_to_address>
Returning 'unknown' may mask unexpected vehicle types.
Consider adding a warning or error log when 'unknown' is returned to help identify unsupported or misconfigured vehicle types.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
default:
return autopilot.vehicle_type?.toLowerCase() || 'unknown'
=======
default:
console.warn(
`Unknown or unsupported vehicle type encountered: mav_type=${mav_type}, autopilot.vehicle_type=${autopilot.vehicle_type}`
);
return autopilot.vehicle_type?.toLowerCase() || 'unknown'
>>>>>>> REPLACE
</suggested_fix>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary by Sourcery
Refactor modelHelper to tidy up indentation and optimize the model override lookup by checking for a global override before awaiting vehicle and frame readiness.
Enhancements: