Skip to content

Commit 10fa754

Browse files
joystick: extension-suggestions: Add protocol filtering and use under-case on API
1 parent a98a3bd commit 10fa754

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

src/components/ExternalFeaturesDiscoveryModal.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,9 @@ const applyAllSuggestions = (): void => {
842842
843843
// Apply each suggestion
844844
extensionGroup.suggestions.forEach((suggestion) => {
845-
const matchingAction = availableActions.find((action) => action.id === suggestion.actionId)
845+
const matchingAction = availableActions.find(
846+
(action) => action.id === suggestion.actionId && action.protocol === suggestion.actionProtocol
847+
)
846848
if (matchingAction) {
847849
// Apply to selected profiles
848850
selectedProfiles.value.forEach((profileHash) => {
@@ -893,7 +895,10 @@ const applyJoystickSuggestion = (): void => {
893895
894896
// Find a matching action from available actions
895897
const availableActions = allAvailableButtons()
896-
const matchingAction = availableActions.find((action) => action.id === selectedSuggestion.value!.actionId)
898+
const matchingAction = availableActions.find(
899+
(action) =>
900+
action.id === selectedSuggestion.value!.actionId && action.protocol === selectedSuggestion.value!.actionProtocol
901+
)
897902
898903
if (!matchingAction) {
899904
openSnackbar({

src/libs/blueos.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { type ActionConfig } from '@/libs/joystick/protocols/cockpit-actions'
55
import { useMainVehicleStore } from '@/stores/mainVehicle'
66
import { useMissionStore } from '@/stores/mission'
77
import { type RawCpuLoadInfo, type RawCpuTempInfo, type RawNetworkInfo } from '@/types/blueos'
8-
import { JoystickMapSuggestion, JoystickMapSuggestionsFromExtension } from '@/types/joystick'
8+
import { JoystickMapSuggestion, JoystickMapSuggestionAPI, JoystickMapSuggestionsFromExtension } from '@/types/joystick'
99
import { ExternalWidgetSetupInfo } from '@/types/widgets'
1010

1111
/**
@@ -31,7 +31,7 @@ interface ExtrasJson {
3131
/**
3232
* A list of joystick map suggestions offered by the extension.
3333
*/
34-
joystick_suggestions?: JoystickMapSuggestion[]
34+
joystick_suggestions?: JoystickMapSuggestionAPI[]
3535
}
3636

3737
/**
@@ -231,7 +231,10 @@ export const getJoystickSuggestionsFromBlueOS = async (): Promise<JoystickMapSug
231231

232232
const suggestions: JoystickMapSuggestion[] = extraJson.joystick_suggestions.map((suggestion, index) => ({
233233
...suggestion,
234-
id: `${extensionName}-${index}-${suggestion.actionName.replace(/\s+/g, '-').toLowerCase()}`,
234+
actionProtocol: suggestion.action_protocol,
235+
actionName: suggestion.action_name,
236+
actionId: suggestion.action_id,
237+
id: `${extensionName}-${index}-${suggestion.action_protocol}-${suggestion.action_id}`,
235238
}))
236239

237240
suggestionsMap.set(extensionName, {

src/types/joystick.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ export interface JoystickMapSuggestion {
539539
* Unique identifier for this suggestion
540540
*/
541541
id: string
542+
/**
543+
* Protocol of the action to be mapped (e.g. cockpit-action, data-lake-variable, etc.)
544+
*/
545+
actionProtocol: JoystickProtocol
542546
/**
543547
* Human-readable name of the action to be mapped
544548
*/
@@ -561,6 +565,22 @@ export interface JoystickMapSuggestion {
561565
description?: string
562566
}
563567

568+
/* eslint-disable jsdoc/require-jsdoc */
569+
/**
570+
* Interface for the API response of a Joystick map suggestion from BlueOS extensions
571+
* Replicates the JoystickMapSuggestion interface, but with snake_case field names to match the API response
572+
*/
573+
export interface JoystickMapSuggestionAPI {
574+
id: string
575+
action_protocol: JoystickProtocol
576+
action_name: string
577+
action_id: string
578+
button: number
579+
modifier: CockpitModifierKeyOption
580+
description?: string
581+
}
582+
/* eslint-enable jsdoc/require-jsdoc */
583+
564584
/**
565585
* Joystick map suggestions grouped by extension
566586
*/

0 commit comments

Comments
 (0)