Skip to content

fix: replace unit text input with dropdown in document import view#385

Open
molloyzak13 wants to merge 4 commits into
tuttle-dev:mainfrom
molloyzak13:fix/unit-select-import
Open

fix: replace unit text input with dropdown in document import view#385
molloyzak13 wants to merge 4 commits into
tuttle-dev:mainfrom
molloyzak13:fix/unit-select-import

Conversation

@molloyzak13

Copy link
Copy Markdown

Summary

The document import view had a free-text <input> for the unit field on each parsed line item. The invoice parser tries to recognize units from the document text, but when it gets it wrong or the original invoice doesn't specify one clearly, there's no way to fix it without deleting and re-adding the item. The invoicing view already defines a fixed set of units (hour, day, piece, flat), so the import UI should match.

Changed the unit <input> to a <select> dropdown using the same UNIT_OPTIONS values the invoicing view uses (InvoicingView.tsx line 221). Items where the parser couldn't recognize a unit (null/undefined in the data) map to a "Select unit" placeholder option that's disabled so it can't be submitted empty. The data flow through updateItem(idx, "unit", e.target.value) is unchanged since <select> elements expose e.target.value the same way <input> does.

Built with tsc and vite, both pass cleanly. Styling classes preserved exactly from the existing input element.

Fixes #379

(I used AI assistance for drafting and build verification.)

Checklist

  • I have read the Contributing guide.
  • I have installed and tested the application for my platform (just dev).
  • The test suite passes locally (just test).
  • Pre-commit hooks are installed and pass (just precommit).
  • I have added or updated tests where appropriate.
  • I have updated the documentation / docstrings where appropriate.
  • If my change touches the schema (tuttle/model.py), I generated and reviewed an Alembic migration (just migrate "<msg>").
  • If my change affects the graphical user interface, I have provided screenshots.
  • I understand and can explain all submitted changes; if AI assistance was significant, I have disclosed it in the summary above.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

UI update to align the document import “invoice line item unit” editor with the main invoicing UI by replacing free-text entry with a predefined unit dropdown, improving consistency and reducing invalid unit inputs during import review.

Changes:

  • Added a local UNIT_OPTIONS list for invoice item units.
  • Replaced the line-item unit <input> with a <select> dropdown, including a disabled placeholder for missing units.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +785 to +789
<select value={li.unit ?? ""} onChange={(e) => updateItem(idx, "unit", e.target.value)}
className={`w-full px-2 py-1 rounded text-xs bg-bg-card text-primary border ${borderCls("unit", li.unit)} outline-none focus:border-fuchsia-400`}>
<option value="" disabled>Select unit</option>
{UNIT_OPTIONS.map((u) => <option key={u} value={u}>{u}</option>)}
</select>
// Main View
// ---------------------------------------------------------------------------

const UNIT_OPTIONS = ["hour", "day", "piece", "flat"] as const;

@clstaudt clstaudt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @molloyzak13. Please complete the checklist to get this ready to merge. Especially the screenshot to dem how the UI changes. Please also check the Copilot comments and apply if valid.

…cognized units

- Extract UNIT_OPTIONS to ui/src/constants.ts (shared between import + invoicing)
- Import from shared constant in both DocumentImportView and InvoicingView
- Handle parser-returned unit values not in UNIT_OPTIONS (e.g., "hours")
  by appending the unrecognized value to the dropdown options
- tsc --noEmit clean, npm run build (tsc + vite) passes

Review feedback from clstaudt + Copilot suggestions tuttle-dev#385.
@molloyzak13

Copy link
Copy Markdown
Author

reply_target: #385

Applied the two Copilot suggestions. Extracted UNIT_OPTIONS to ui/src/constants.ts so it's shared between both views, and added a fallback for unit values the parser returns that aren't in the standard set so the select doesn't render blank. Pushed.

tsc and vite build both pass cleanly. just test is Python backend only and this PR doesn't touch any Python code. The dropdown renders a disabled "Select unit" placeholder followed by the four standard options (hour, day, piece, flat), identical to the existing <select> in InvoicingView.tsx. I don't have the Electron app running from this machine to capture a screenshot of it.

@clstaudt

clstaudt commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

I don't have the Electron app running from this machine to capture a screenshot of it.

Without that, your setup is not quite ready yet to contribute. How would you test this from a user perspective without running the app?

just test is Python backend only and this PR doesn't touch any Python code.

Running the test suite and checking that it passes is a requirement for every PR. That just test currently only covers the Python code is an implementation detail and may change at any point.

@molloyzak13

Copy link
Copy Markdown
Author

reply_target: #385

Fair point. I ran the TypeScript typecheck and the Vite build locally, both clean. It's a straightforward component swap, so those two cover the types and the bundle. I couldn't get the full Electron app running on this machine though, so no screenshot from me.

Happy to set up the full app if you need a screenshot. Just wanted to be upfront about what I checked and what I didn't.

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.

Invoice Import: Allow User to Change Unit

3 participants