Skip to content

Conversation

Williangalvani
Copy link
Member

@Williangalvani Williangalvani commented Jul 29, 2025

Screenshot 2025-07-29 at 12 52 45

Summary by Sourcery

Add a reverse direction toggle to the servo function editor and introduce a reusable ParameterCheckbox component for editing checkbox-style parameters.

New Features:

  • Add reverse direction checkbox in ServoFunctionEditorDialog to toggle servo reversal.

Enhancements:

  • Extract ParameterCheckbox component to unify parameter editing via checkboxes.

Copy link

sourcery-ai bot commented Jul 29, 2025

Reviewer's Guide

This PR adds a reverse-direction toggle to the ServoFunctionEditorDialog by introducing a new ParameterCheckbox component and integrating it into the dialog layout with a computed reverse_param binding.

Sequence diagram for toggling the reverse direction checkbox

sequenceDiagram
    actor User
    participant ServoFunctionEditorDialog
    participant ParameterCheckbox
    participant mavlink2rest
    participant autopilot_data
    User->>ServoFunctionEditorDialog: Open dialog
    ServoFunctionEditorDialog->>ParameterCheckbox: Render with reverse_param
    User->>ParameterCheckbox: Toggle checkbox
    ParameterCheckbox->>ParameterCheckbox: onCheckboxChange(value)
    ParameterCheckbox->>ParameterCheckbox: saveEditedParam()
    alt param.rebootRequired
        ParameterCheckbox->>autopilot_data: setRebootRequired(true)
    end
    ParameterCheckbox->>mavlink2rest: setParam(param.name, value, system_id, paramType)
    mavlink2rest-->>ParameterCheckbox: Confirmation
    ParameterCheckbox-->>User: Checkbox reflects new state
Loading

Class diagram for new ParameterCheckbox component and integration

classDiagram
    class ServoFunctionEditorDialog {
        +Parameter reverse_param
    }
    class ParameterCheckbox {
        +Parameter param
        +string label
        +number checkedValue
        +number uncheckedValue
        -number internal_value
        -number last_sent_value
        +onCheckboxChange(value: number): void
        +saveEditedParam(): Promise<void>
    }
    ServoFunctionEditorDialog --> ParameterCheckbox : uses
    ParameterCheckbox --> Parameter : param
Loading

File-Level Changes

Change Details Files
Integrate reverse-direction checkbox into ServoFunctionEditorDialog
  • Replaced single inline-parameter-editor with a two-column v-row layout
  • Inserted parameter-checkbox next to the inline editor with label and value props
  • Imported and registered the ParameterCheckbox component
  • Added reverse_param computed property to fetch the '_REVERSED' parameter
core/frontend/src/components/parameter-editor/ServoFunctionEditorDialog.vue
Create reusable ParameterCheckbox component
  • Added new ParameterCheckbox.vue with v-checkbox template for parameter toggling
  • Defined props for param, label, checkedValue, and uncheckedValue
  • Managed internal_value and last_sent_value in component data
  • Computed waiting_for_param_update and param_value to reflect sync state
  • Watched param and param_value to update internal_value on changes
  • Implemented onCheckboxChange and saveEditedParam methods with MAVLink2Rest API call
core/frontend/src/components/parameter-editor/ParameterCheckbox.vue

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Williangalvani - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `core/frontend/src/components/parameter-editor/ParameterCheckbox.vue:63` </location>
<code_context>
+      }
+      return this.param?.value !== this.internal_value
+    },
+    param_value(): number {
+      return this.param?.value ?? this.uncheckedValue
+    },
+  },
</code_context>

<issue_to_address>
Defaulting 'param_value' to 'uncheckedValue' could mask issues.

Defaulting to 'uncheckedValue' when 'param' is undefined may hide errors. Consider returning undefined or throwing to surface issues during development.

Suggested implementation:

```
    param_value(): number | undefined {
      return this.param?.value
    },

```

If you prefer to throw an error instead of returning `undefined`, replace the body of `param_value` with:
```js
if (!this.param) {
  throw new Error("Parameter 'param' is undefined in ParameterCheckbox");
}
return this.param.value;
```
You may also need to update any code that uses `param_value` to handle the possibility of `undefined` or the thrown error.
</issue_to_address>

### Comment 2
<location> `core/frontend/src/components/parameter-editor/ParameterCheckbox.vue:68` </location>
<code_context>
+    },
+  },
+  watch: {
+    param(newParam) {
+      if (newParam) {
+        this.internal_value = newParam.value
+      }
+    },
</code_context>

<issue_to_address>
The watcher on 'param' may overwrite user input.

If 'param' changes during user interaction, 'internal_value' may be reset and overwrite user input. Consider updating 'internal_value' only for external changes, not user actions.
</issue_to_address>

### Comment 3
<location> `core/frontend/src/components/parameter-editor/ParameterCheckbox.vue:91` </location>
<code_context>
+      this.saveEditedParam()
+    },
+
+    async saveEditedParam(): Promise<void> {
+      if (this.param_value === this.internal_value) {
+        return
+      }
+      if (this.param === undefined || this.internal_value === undefined) {
+        return
+      }
+      if (this.param?.rebootRequired) {
+        autopilot_data.setRebootRequired(true)
+      }
+      this.last_sent_value = this.internal_value
+
+      await mavlink2rest.setParam(
+        this.param.name,
+        this.internal_value,
</code_context>

<issue_to_address>
No error handling for failed parameter save.

Add error handling for 'mavlink2rest.setParam' failures to provide user feedback or implement a retry mechanism.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
      await mavlink2rest.setParam(
        this.param.name,
        this.internal_value,
        autopilot_data.system_id,
        this.param.paramType.type,
      )
=======
      try {
        await mavlink2rest.setParam(
          this.param.name,
          this.internal_value,
          autopilot_data.system_id,
          this.param.paramType.type,
        )
      } catch (error) {
        // Provide user feedback on failure
        // Replace with your preferred notification system if available
        // For now, use alert as a placeholder
        alert('Failed to save parameter. Please try again.');
        // Optionally, you could implement a retry mechanism here
      }
>>>>>>> REPLACE

</suggested_fix>

### Comment 4
<location> `core/frontend/src/components/parameter-editor/ServoFunctionEditorDialog.vue:20` </location>
<code_context>
-        />
-
+        <v-row>
+          <v-col cols="6">
+            <inline-parameter-editor
+              :auto-set="true"
+              :label="param.name"
+              :param="param"
+            />
+          </v-col>
+          <v-col cols="6">
+            <parameter-checkbox
</code_context>

<issue_to_address>
Splitting the editor and checkbox into two columns may cause layout issues on small screens.

Consider applying Vuetify's grid breakpoints to stack these components vertically on small screens for better responsiveness.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
          <v-col cols="6">
            <inline-parameter-editor
              :auto-set="true"
              :label="param.name"
              :param="param"
            />
          </v-col>
          <v-col cols="6">
            <parameter-checkbox
              :param="reverse_param"
              label="Reverse Direction"
              :checked-value="1"
              :unchecked-value="0"
            />
          </v-col>
=======
          <v-col cols="12" sm="6">
            <inline-parameter-editor
              :auto-set="true"
              :label="param.name"
              :param="param"
            />
          </v-col>
          <v-col cols="12" sm="6">
            <parameter-checkbox
              :param="reverse_param"
              label="Reverse Direction"
              :checked-value="1"
              :unchecked-value="0"
            />
          </v-col>
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +63 to +64
param_value(): number {
return this.param?.value ?? this.uncheckedValue
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Defaulting 'param_value' to 'uncheckedValue' could mask issues.

Defaulting to 'uncheckedValue' when 'param' is undefined may hide errors. Consider returning undefined or throwing to surface issues during development.

Suggested implementation:

    param_value(): number | undefined {
      return this.param?.value
    },

If you prefer to throw an error instead of returning undefined, replace the body of param_value with:

if (!this.param) {
  throw new Error("Parameter 'param' is undefined in ParameterCheckbox");
}
return this.param.value;

You may also need to update any code that uses param_value to handle the possibility of undefined or the thrown error.

Comment on lines +68 to +70
param(newParam) {
if (newParam) {
this.internal_value = newParam.value
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): The watcher on 'param' may overwrite user input.

If 'param' changes during user interaction, 'internal_value' may be reset and overwrite user input. Consider updating 'internal_value' only for external changes, not user actions.

Comment on lines +103 to +108
await mavlink2rest.setParam(
this.param.name,
this.internal_value,
autopilot_data.system_id,
this.param.paramType.type,
)
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): No error handling for failed parameter save.

Add error handling for 'mavlink2rest.setParam' failures to provide user feedback or implement a retry mechanism.

Suggested change
await mavlink2rest.setParam(
this.param.name,
this.internal_value,
autopilot_data.system_id,
this.param.paramType.type,
)
try {
await mavlink2rest.setParam(
this.param.name,
this.internal_value,
autopilot_data.system_id,
this.param.paramType.type,
)
} catch (error) {
// Provide user feedback on failure
// Replace with your preferred notification system if available
// For now, use alert as a placeholder
alert('Failed to save parameter. Please try again.');
// Optionally, you could implement a retry mechanism here
}

Comment on lines +20 to +34
<v-col cols="6">
<inline-parameter-editor
:auto-set="true"
:label="param.name"
:param="param"
/>
</v-col>
<v-col cols="6">
<parameter-checkbox
:param="reverse_param"
label="Reverse Direction"
:checked-value="1"
:unchecked-value="0"
/>
</v-col>
Copy link

Choose a reason for hiding this comment

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

suggestion: Splitting the editor and checkbox into two columns may cause layout issues on small screens.

Consider applying Vuetify's grid breakpoints to stack these components vertically on small screens for better responsiveness.

Suggested change
<v-col cols="6">
<inline-parameter-editor
:auto-set="true"
:label="param.name"
:param="param"
/>
</v-col>
<v-col cols="6">
<parameter-checkbox
:param="reverse_param"
label="Reverse Direction"
:checked-value="1"
:unchecked-value="0"
/>
</v-col>
<v-col cols="12" sm="6">
<inline-parameter-editor
:auto-set="true"
:label="param.name"
:param="param"
/>
</v-col>
<v-col cols="12" sm="6">
<parameter-checkbox
:param="reverse_param"
label="Reverse Direction"
:checked-value="1"
:unchecked-value="0"
/>
</v-col>

@Williangalvani Williangalvani marked this pull request as draft July 29, 2025 16:14
@Williangalvani
Copy link
Member Author

we need to be context-aware here. motors currently have their own reverse parameter, for example

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.

1 participant