Skip to content

Conversation

@luiscbrenes
Copy link

@luiscbrenes luiscbrenes commented Sep 13, 2025

When using the multicheck option for configuration, the information is not being saved correctly in the database. With this change, it works as expected.

Summary by CodeRabbit

  • Bug Fixes

    • Multi-select checkboxes in the admin/settings now correctly initialize, reflect, update, and persist selected options, avoiding empty or incorrect states.
    • Previously saved multi-check selections are migrated so legacy data continues to work.
  • Refactor

    • Consolidated multi-check handling into a single array-based approach with normalization and deduplication for more reliable behavior.

@coderabbitai
Copy link

coderabbitai bot commented Sep 13, 2025

Walkthrough

Adds a new computed property multicheckValue to two Vue admin components. Fields.vue centralizes multicheck state as a normalized, deduplicated string-array with legacy-object migration; Settings.vue ensures fieldValue[fieldName] is an array and exposes a simple getter/setter.

Changes

Cohort / File(s) Summary of Changes
Admin multicheck — Settings
assets/src/admin/components/Settings.vue
Added computed multicheckValue with getter that, when fieldData.type === 'multicheck', ensures fieldValue[fieldData.name] is an array (initializing to [] if missing) and returns it; setter writes new array back to fieldValue.
Admin multicheck — Fields (migration & normalization)
assets/src/admin/components/Fields.vue
Replaced per-option boolean bindings with v-model="multicheckValue" and :value="String(optionKey)" plus array-style name attributes. Added computed multicheckValue that gates by type, migrates legacy object maps to arrays (treating truthy markers as selected), normalizes elements to strings, deduplicates, persists via this.$set, and no-ops for non-multicheck types.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I twitch my whiskers at options new,
Keys become lists in a dewy queue.
From maps to arrays my little paws sweep,
Keeping each value tidy and neat.
Hop, nibble, and stash—multichecks to keep 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately summarizes the primary change: it states that multicheck persistence is now fixed so information is saved correctly to the database. It is concise and specific to the bugfix, and it directly aligns with the PR objectives and the code changes (adding multicheckValue computed properties in Settings and Fields to centralize and normalize multicheck storage). A teammate scanning history would understand the main intent without extraneous detail.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16d8db1 and 46e18f7.

📒 Files selected for processing (1)
  • assets/src/admin/components/Fields.vue (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • assets/src/admin/components/Fields.vue

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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)
assets/src/admin/components/Fields.vue (1)

55-55: Normalize checkbox values to strings (avoids checked-state mismatches) and optionally align name to array semantics.

Vue compares checkbox v-model values strictly. If option keys can be numbers or booleans from the schema/backend, coercing to string prevents subtle mismatch when restoring selections. Optional: switch the name attribute to use [] to reflect array semantics (useful if the DOM is ever serialized).

- <input type="checkbox" class="checkbox" :id="sectionId + '[' + fieldData.name + '][' + optionKey + ']'" :name="sectionId + '[' + fieldData.name + '][' + optionKey + ']'" v-model="multicheckValue" :value="optionKey" />
+ <input
+   type="checkbox"
+   class="checkbox"
+   :id="sectionId + '[' + fieldData.name + '][' + optionKey + ']'"
+   :name="sectionId + '[' + fieldData.name + '][]'"
+   v-model="multicheckValue"
+   :value="String(optionKey)"
+ />
assets/js/admin.js (1)

31-31: Avoid eval() in distributed bundles; use non-eval source maps for production.

The bundle uses eval-based modules (likely devtool: eval-source-map). This triggers security linters and can conflict with CSP. Ship production builds with devtool set to 'source-map' (or false) and without eval.

Also applies to: 43-43

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dafcf5e and b60c872.

📒 Files selected for processing (2)
  • assets/js/admin.js (2 hunks)
  • assets/src/admin/components/Fields.vue (2 hunks)
🧰 Additional context used
🪛 Biome (2.1.2)
assets/js/admin.js

[error] 31-31: eval() exposes to security risks and performance issues.

See the MDN web docs for more details.
Refactor the code so that it doesn't need to call eval().

(lint/security/noGlobalEval)


[error] 43-43: eval() exposes to security risks and performance issues.

See the MDN web docs for more details.
Refactor the code so that it doesn't need to call eval().

(lint/security/noGlobalEval)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a 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

♻️ Duplicate comments (1)
assets/src/admin/components/Fields.vue (1)

202-236: LGTM: Legacy migration + normalization are handled well

Getter/settter correctly migrate object-map → array, normalize to strings, and dedupe. This addresses prior feedback.

🧹 Nitpick comments (3)
assets/src/admin/components/Fields.vue (3)

53-59: Add a stable key for v-for

Avoids Vue warnings and improves patching performance.

Apply this diff:

-                        <label :for="sectionId + '[' + fieldData.name + '][' + optionKey + ']'">
+                        <label :key="String(optionKey)" :for="sectionId + '[' + fieldData.name + '][' + optionKey + ']'">

221-226: Filter to allowed option keys and drop nullish values

Prevents persisting unknown/tainted keys and avoids accidental "undefined"/empty entries. Keeps UI and saved data consistent when options change.

Apply this diff:

-                    // Normalize to strings and dedupe to keep v-model stable
-                    const normalized = Array.from(new Set(raw.map(String)));
-                    if (normalized.length !== raw.length || normalized.some((v, i) => v !== raw[i])) {
-                        this.$set(this.fieldValue, this.fieldData.name, normalized);
-                    }
-                    return normalized;
+                    // Normalize (drop nullish), dedupe, and filter to allowed keys
+                    const normalized = Array.from(
+                        new Set(
+                            raw
+                                .filter(v => v !== undefined && v !== null && v !== '')
+                                .map(v => String(v))
+                        )
+                    );
+                    const allowedKeys = Array.isArray(this.fieldData.options)
+                        ? this.fieldData.options.map((_, i) => String(i))
+                        : Object.keys(this.fieldData.options || {});
+                    const finalNormalized = normalized.filter(v => allowedKeys.includes(v));
+                    if (finalNormalized.length !== raw.length || finalNormalized.some((v, i) => v !== raw[i])) {
+                        this.$set(this.fieldValue, this.fieldData.name, finalNormalized);
+                    }
+                    return finalNormalized;
@@
-                    const normalized = Array.isArray(newValue)
-                        ? Array.from(new Set(newValue.map(String)))
-                        : [];
-                    this.$set(this.fieldValue, this.fieldData.name, normalized);
+                    const normalized = Array.isArray(newValue)
+                        ? Array.from(
+                            new Set(
+                                newValue
+                                    .filter(v => v !== undefined && v !== null && v !== '')
+                                    .map(v => String(v))
+                            )
+                          )
+                        : [];
+                    const allowedKeys = Array.isArray(this.fieldData.options)
+                        ? this.fieldData.options.map((_, i) => String(i))
+                        : Object.keys(this.fieldData.options || {});
+                    const finalNormalized = normalized.filter(v => allowedKeys.includes(v));
+                    this.$set(this.fieldValue, this.fieldData.name, finalNormalized);

If backend sanitizes these already, feel free to skip—but please verify.

Also applies to: 229-234


202-236: Optional: avoid side-effects inside computed getters

Setting reactive state inside a computed getter can cause extra recomputations. Consider moving normalization/migration into watchers on fieldValue[fieldData.name] and fieldData.options.

Example (outside this block):

watch: {
  'fieldValue[fieldData.name]': {
    handler(val) { /* normalize/filter then this.$set(...) */ },
    deep: false,
  },
  'fieldData.options': {
    handler() { /* re-filter saved values against new options */ },
    deep: false,
  }
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b60c872 and 16d8db1.

📒 Files selected for processing (1)
  • assets/src/admin/components/Fields.vue (2 hunks)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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