Skip to content

Add shared material auto-fill and type-to-search across all writer pages#16

Merged
sjordan0228 merged 1 commit into
devfrom
feature/auto-fill-temps
Mar 24, 2026
Merged

Add shared material auto-fill and type-to-search across all writer pages#16
sjordan0228 merged 1 commit into
devfrom
feature/auto-fill-temps

Conversation

@sjordan0228
Copy link
Copy Markdown
Contributor

@sjordan0228 sjordan0228 commented Mar 24, 2026

Summary

  • All material fields changed from dropdown to type-to-search (input + datalist)
  • All brand fields now type-to-search (TigerTag was last holdout)
  • Selecting a material auto-fills nozzle temps (±10°C), bed temps (±5°C), and density
  • User edits are tracked — auto-fill won't overwrite manually entered values
  • Shared logic in SharedJS.h: TigerTag API fetch with hardcoded offline fallback (15 common materials)
  • API expands material/brand lists when reachable (92 materials from TigerTag SpoolmanDB)
  • Hidden ID fields maintain numeric IDs for formats that need them (OpenPrintTag, TigerTag)

Pages affected

  • OpenPrintTag Writer — material type-to-search + auto-fill temps/density
  • OpenTag3D Writer — material type-to-search + auto-fill temps/density (combines base + modifier for lookup)
  • TigerTag Writer — material + brand both type-to-search + auto-fill temps
  • NFC+ Registration — material type-to-search + auto-fill temps/density

Test plan

  • All four pages previewed in browser
  • Material type-to-search works — type "ABS", filters to match
  • Auto-fill fires on material selection (temps + density)
  • User edits preserved — manually typed value not overwritten by material change
  • Changing material updates auto-filled fields but not user-edited ones
  • TigerTag brand type-to-search works
  • Compile and test on scanner hardware

Closes #12

Summary by CodeRabbit

  • New Features
    • Replaced material selection dropdowns with searchable input fields across multiple forms for faster material discovery
    • Added automatic population of print temperature, bed temperature, and density fields based on selected material
    • Expanded material database with additional material options loaded dynamically
    • Manual temperature adjustments are preserved when auto-fill is active

- SharedJS.h: add loadMaterialDb(), lookupMaterial(), trackAutoFill(),
  autoFillMaterialData() with TigerTag API fetch + hardcoded fallback
- All writer pages: material field changed from dropdown to type-to-search
  (input + datalist). API expands options when reachable.
- All writer pages: selecting a material auto-fills temps (±10°C nozzle,
  ±5°C bed) and density. User edits are tracked and preserved.
- TigerTag: brand field changed from dropdown to type-to-search
- Hidden ID fields maintain numeric IDs for tag formats that need them
  (OpenPrintTag material_type, TigerTag material_id + brand_id)

Closes #12
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 24, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'instructions'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
📝 Walkthrough

Walkthrough

This pull request implements a material auto-fill feature across multiple writer pages by replacing fixed material dropdowns with searchable inputs backed by datalists, introducing a shared material database lookup system, and adding client-side synchronization and auto-population logic for temperature and density fields.

Changes

Cohort / File(s) Summary
Shared Material Infrastructure
src/SharedJS.h
Added global material database cache (_materialDb, _materialFallback, _materialDbLoaded), loadMaterialDb() to fetch materials from API endpoint, lookupMaterial(name) for normalized material name resolution with exact/dashed/prefix-matching rules, trackAutoFill(fieldIds) to mark fields as user-edited via listeners, and autoFillMaterialData(materialName, fieldMap) to populate temperature/density fields from material lookup results.
Writer UI Migration
src/OpenPrintTagWriterHTML.h, src/OpenTag3DWriterHTML.h, src/TigerTagWriterHTML.h, src/UIDRegistrationHTML.h
Replaced fixed material <select> dropdowns with searchable <input> fields paired with <datalist> elements; added client-side JavaScript to synchronize material selections with hidden ID fields via syncMaterialId(), trigger auto-fill on material input events, dynamically load and merge material database options, and mark auto-filled fields to prevent overwriting manual edits.

Sequence Diagram

sequenceDiagram
    participant User
    participant Form as Form UI
    participant SharedJS as SharedJS Functions
    participant API as Material API
    participant DOM as DOM / Datalist

    User->>Form: Select or type material name
    Form->>SharedJS: input event → autoFillMaterialData(materialName)
    SharedJS->>SharedJS: lookupMaterial(name) - normalize & search
    
    alt Material found in cache
        SharedJS->>Form: Return cached material data
    else Cache empty or miss
        SharedJS->>API: loadMaterialDb() fetch materials
        API-->>SharedJS: Return material records
        SharedJS->>DOM: Append new options to datalist
        SharedJS->>SharedJS: lookupMaterial(name) retry
        SharedJS->>Form: Return material data
    end
    
    Form->>Form: Check if field marked autoFilled
    Form->>Form: Populate min_print_temp, max_print_temp, etc.
    Form->>SharedJS: trackAutoFill(fieldIds) mark fields
    SharedJS->>DOM: Register input/change listeners
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: converting material fields to type-to-search inputs with auto-fill functionality across all writer pages.
Description check ✅ Passed The description covers summary, changes, pages affected, and test plan; however, it's missing the 'How to Test' section format and omits compilation verification steps.
Linked Issues check ✅ Passed All objectives from issue #12 are met: material API reused across pages, nozzle/bed temps auto-filled (±10°C/±5°C), shared logic in SharedJS.h, and offline fallback provided.
Out of Scope Changes check ✅ Passed All changes directly support the linked issue #12 objectives: type-to-search conversion, auto-fill implementation, shared JS logic, and material database expansion.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/auto-fill-temps

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
Copy Markdown

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/UIDRegistrationHTML.h (1)

341-341: ⚠️ Potential issue | 🔴 Critical

Runtime error: materialTypeEl is now an input, not a select.

After refactoring material_type from a <select> to an <input>, this line accesses .options and .selectedIndex which don't exist on input elements. This will throw a TypeError when registerFlow() executes.

🐛 Proposed fix
-      var materialTypeText = materialTypeEl.options[materialTypeEl.selectedIndex].text;
+      var materialTypeText = materialTypeEl.value || 'PLA';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/UIDRegistrationHTML.h` at line 341, The code in registerFlow() reads
materialTypeEl.options[materialTypeEl.selectedIndex].text but materialTypeEl is
now an <input>, causing a TypeError; change the logic that derives
materialTypeText to use the input's value (e.g., materialTypeEl.value or
materialTypeEl.value.trim()) instead of accessing .options/.selectedIndex, and
update any downstream uses that expect a string accordingly so materialTypeText
comes from materialTypeEl.value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/SharedJS.h`:
- Around line 163-168: The then-callback that populates _materialDb assumes each
item has a string material and directly calls m.material.toUpperCase(), which
can throw if m.material is missing or not a string; update the loop in the
.then(function(data) { ... }) handler to guard each item (e.g., verify m is
truthy and typeof m.material === 'string' or use a safe access) before calling
toUpperCase(), and only add entries to _materialDb when the validated uppercase
key is non-empty to avoid null/undefined key errors.

---

Outside diff comments:
In `@src/UIDRegistrationHTML.h`:
- Line 341: The code in registerFlow() reads
materialTypeEl.options[materialTypeEl.selectedIndex].text but materialTypeEl is
now an <input>, causing a TypeError; change the logic that derives
materialTypeText to use the input's value (e.g., materialTypeEl.value or
materialTypeEl.value.trim()) instead of accessing .options/.selectedIndex, and
update any downstream uses that expect a string accordingly so materialTypeText
comes from materialTypeEl.value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: cd3768e3-44c0-4af1-95cf-d100c84f3f36

📥 Commits

Reviewing files that changed from the base of the PR and between 77bd98e and 2d3a441.

📒 Files selected for processing (5)
  • src/OpenPrintTagWriterHTML.h
  • src/OpenTag3DWriterHTML.h
  • src/SharedJS.h
  • src/TigerTagWriterHTML.h
  • src/UIDRegistrationHTML.h

Comment thread src/SharedJS.h
Comment on lines +163 to +168
.then(function(data) {
if (Array.isArray(data)) {
data.forEach(function(m) {
if (m.material) _materialDb[m.material.toUpperCase()] = m;
});
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Potential null reference if API returns malformed material data.

The code assumes m.material exists when iterating API results. If the API returns an object without a material property, m.material.toUpperCase() will throw a TypeError.

🛡️ Proposed defensive fix
       if (Array.isArray(data)) {
         data.forEach(function(m) {
-          if (m.material) _materialDb[m.material.toUpperCase()] = m;
+          if (m && m.material) _materialDb[m.material.toUpperCase()] = m;
         });
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/SharedJS.h` around lines 163 - 168, The then-callback that populates
_materialDb assumes each item has a string material and directly calls
m.material.toUpperCase(), which can throw if m.material is missing or not a
string; update the loop in the .then(function(data) { ... }) handler to guard
each item (e.g., verify m is truthy and typeof m.material === 'string' or use a
safe access) before calling toUpperCase(), and only add entries to _materialDb
when the validated uppercase key is non-empty to avoid null/undefined key
errors.

@sjordan0228 sjordan0228 merged commit d76b505 into dev Mar 24, 2026
1 check passed
@sjordan0228 sjordan0228 deleted the feature/auto-fill-temps branch March 26, 2026 02:00
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