Allow pre-selecting vehicle, version, and board via URL parameters#229
Allow pre-selecting vehicle, version, and board via URL parameters#229ryanbasic1 wants to merge 1 commit intoArduPilot:mainfrom
Conversation
Adds support for pre-selecting vehicle, version, and board from URL parameters. Example: ?vehicle=copter&version=stable&board=pixhawk - Frontend-only change - No backend changes - Safe fallback if parameters are invalid - Does not affect existing behavior This allows external links to directly open pre-configured build selections.
|
This PR still has huge diff. I will suggest you to get to the root cause instead of resubmitting the PR. Do not close existing PR. The same branch after fixing things in this PR itself. You need to get rid of your last commit I think. Please check diff before pushing. |
f39ece1 to
9a111be
Compare
shiv-tyagi
left a comment
There was a problem hiding this comment.
Thanks for contributing. The direction is correct. It just needs a little more polishing. PTAL.
| if (typeof rebuildFromBuildId !== 'undefined') { | ||
| await initRebuild(rebuildFromBuildId); | ||
| } else { | ||
| initFromUrlParams(); |
There was a problem hiding this comment.
Can we rename initRebuild to initPreSelect and do both in same function (and get rid of initFromUrlParams altogether). We first check if rebuild_from param is there, if not we check vehicle_id, board_id and version_id are present, and set those properties.
The only difference would be that we would not be setting selected_features[], in second case.
| if (params.has('vehicle')) rebuildConfig.vehicleId = params.get('vehicle'); | ||
| if (params.has('board')) rebuildConfig.boardId = params.get('board'); | ||
| if (params.has('version')) rebuildConfig.versionId = params.get('version'); |
There was a problem hiding this comment.
| if (params.has('vehicle')) rebuildConfig.vehicleId = params.get('vehicle'); | |
| if (params.has('board')) rebuildConfig.boardId = params.get('board'); | |
| if (params.has('version')) rebuildConfig.versionId = params.get('version'); | |
| if (params.has('vehicle_id')) rebuildConfig.vehicleId = params.get('vehicle'); | |
| if (params.has('board_id')) rebuildConfig.boardId = params.get('board'); | |
| if (params.has('version_id')) rebuildConfig.versionId = params.get('version'); |
Let us call it vehicle_id and similar at all places.
| if (params.has('version')) rebuildConfig.versionId = params.get('version'); | ||
|
|
||
| // Set flag to indicate URL parameters were provided | ||
| rebuildConfig.fromUrlParams = hasParams; |
There was a problem hiding this comment.
Can this be avoided? This won't be needed if we have a common error handling as described in the other comment.
| if (rebuildConfig.isRebuildMode) { | ||
| console.warn(`Rebuild vehicle '${rebuildConfig.vehicleId}' not found in available vehicles`); | ||
| alert(`Warning: The vehicle from the original build is no longer available.\n\nRedirecting to new build page...`); | ||
| window.location.href = '/add_build'; | ||
| return; | ||
| } else if (rebuildConfig.fromUrlParams) { | ||
| console.warn(`URL parameter vehicle '${rebuildConfig.vehicleId}' not found. Defaulting to first available vehicle.`); | ||
| rebuildConfig.vehicleId = null; | ||
| } else { | ||
| rebuildConfig.vehicleId = null; | ||
| } |
There was a problem hiding this comment.
Can we have one common error message for both cases? That way we can also avoid multiple if-else cases.
Maybe something like, "Vehicle XXX is no longer listed for building. Redirecting to new build page...".
| if (rebuildConfig.isRebuildMode) { | ||
| console.warn(`Rebuild board '${rebuildConfig.boardId}' not found for version '${version_id}'`); | ||
| alert(`Warning: The board from the original build is no longer available.\n\nRedirecting to new build page...`); | ||
| window.location.href = '/add_build'; | ||
| return; | ||
| } else if (rebuildConfig.fromUrlParams) { | ||
| console.warn(`URL parameter board '${rebuildConfig.boardId}' not found for version '${version_id}'. Defaulting to first available board.`); | ||
| rebuildConfig.boardId = null; | ||
| } else { | ||
| rebuildConfig.boardId = null; | ||
| } |
There was a problem hiding this comment.
Similar to the other comment for vehicles.
| if (rebuildConfig.isRebuildMode) { | ||
| console.warn(`Rebuild version '${rebuildConfig.versionId}' not found for vehicle '${new_vehicle_id}'`); | ||
| alert(`Warning: The version from the original build is no longer available.\n\nRedirecting to new build page...`); | ||
| window.location.href = '/add_build'; | ||
| return; | ||
| } else if (rebuildConfig.fromUrlParams) { | ||
| console.warn(`URL parameter version '${rebuildConfig.versionId}' not found for vehicle '${new_vehicle_id}'. Defaulting to first available version.`); | ||
| rebuildConfig.versionId = null; | ||
| } else { | ||
| rebuildConfig.versionId = null; | ||
| } |
There was a problem hiding this comment.
Similar to the other comment for vehicles.
Adds support for pre-selecting vehicle, version, and board from URL parameters.
Example:
?vehicle=copter&version=stable&board=pixhawk
Details
Frontend-only change
No backend changes required
Safe fallback if parameters are invalid
Does not affect existing behavior
This allows external links to directly open pre-configured build ### ### selections.
Closes #181