Skip to content

Make product name mutable again - #1007

Merged
lodewiges merged 6 commits into
stagingfrom
fix/mutable_product_name
Oct 27, 2025
Merged

Make product name mutable again#1007
lodewiges merged 6 commits into
stagingfrom
fix/mutable_product_name

Conversation

@DrumsnChocolate

@DrumsnChocolate DrumsnChocolate commented Jan 19, 2025

Copy link
Copy Markdown
Contributor

fixes #937
Basically reverts #598

The concern with #595 was that users were modifying product names when they really just wanted to create a new product. Should we provide the user with a warning, like a tooltip or a dialog?

Summary by CodeRabbit

  • New Features

    • Added a confirmation prompt when changing an existing product's name to prevent accidental edits.
  • Bug Fixes

    • Product names are now editable in the inline form for existing products.
    • Updating a product name now succeeds where it previously could be blocked.
  • Style

    • Minor UI text refinement in the price list interface.

@lodewiges lodewiges 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.

Looks good, i would agree that we should implement a warning when somebody changes a product

subject(:product) { create(:product) }

it { expect(product.update(name: 'new_name')).to be false }
end

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.

instead of removing the test we could edit it

@lodewiges

Copy link
Copy Markdown
Contributor

bump

1 similar comment
@lodewiges

Copy link
Copy Markdown
Contributor

bump

@coderabbitai

coderabbitai Bot commented Oct 26, 2025

Copy link
Copy Markdown

Warning

Rate limit exceeded

@lodewiges has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e750d3d and eca3e5b.

📒 Files selected for processing (1)
  • app/javascript/packs/price_lists.js (1 hunks)

Walkthrough

Removed the Product model's name-readonly enforcement, enabled editing of product names in the price lists form, added a client-side confirmation when renaming an existing product, and updated the model spec expectation to accept name changes.

Changes

Cohort / File(s) Summary
Product Model Constraint Removal
app/models/product.rb
Deleted validate :name_readonly, removed the name_readonly method and the private visibility marker that enforced read-only product names.
View Input Enablement
app/views/price_lists/index.html.erb
Removed :disabled="product.id" from the product name input so existing products are editable; trimmed trailing whitespace from the label text.
Client-side Rename Confirmation
app/javascript/packs/price_lists.js
In saveProduct, added a guard that, when editing an existing product whose current name differs from the cached original, prompts the user for confirmation and aborts if canceled before proceeding with sanitization and the PUT request.
Test Expectation Update
spec/models/product_spec.rb
Changed the "when updating the name" spec expectation to expect a successful update (true) instead of failure (false), reflecting the removed restriction.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI as PriceLists Form (JS)
    participant Server as Rails App
    participant Product as Product Model

    rect rgb(240, 240, 255)
    Note over UI,Product: Old flow (before change)
    User->>UI: Edit product name and submit
    UI->>Server: PUT /products/:id (name: "new")
    Server->>Product: update(name: "new")
    Product->>Product: validate :name_readonly
    Product-->>Server: Validation error (reject)
    Server-->>UI: 422 Unprocessable Entity (show error)
    end

    rect rgb(240, 255, 240)
    Note over UI,Product: New flow (after change)
    User->>UI: Edit product name and submit
    UI->>UI: if product.id && name != original_name -> prompt confirm
    alt user cancels
        UI-->>User: abort save
    else user confirms
        UI->>Server: PUT /products/:id (name: "new")
        Server->>Product: update(name: "new")
        Product-->>Server: success
        Server-->>UI: 200 OK (update succeeded)
    end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Changes span model, view, client-side JS, and tests — moderate heterogeneity.
  • Review focus areas:
    • app/models/product.rb — ensure no remaining references rely on the removed validation.
    • app/javascript/packs/price_lists.js — confirm confirmation logic is accessible and correctly guards against unintended renames.
    • app/views/price_lists/index.html.erb — verify form state and accessibility when input is always editable.
    • spec/models/product_spec.rb — ensure tests reflect intended behavior and consider adding coverage for the new confirmation flow if relevant.

Poem

I hopped to the model, gave a cheerful spin,
Freed product names from a lock, let edits begin. 🐇
A prompt in the form asks kindly, "Are you sure?"
If you nod, the name changes — neat and pure. ✨
Sip your drink, rename with joy, and grin. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description does not follow the required template structure. The template specifies three main sections: a checklist for database migrations, a summary of changes with UI information if applicable, and other relevant information. The provided description only contains issue references ("fixes #937", "Basically reverts #598") and a question about adding a warning, but lacks an actual summary of the changes made, any UI screenshots or descriptions, and does not address the checklist items. While the description is concise, it is incomplete relative to the template requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Make product name mutable again" clearly and concisely describes the primary objective of the pull request. The changes confirm this: the removal of the readonly validation on product names, the enablement of the product name input field in the UI, and the addition of a confirmation dialog all work together to restore the ability for users to edit product names. The title is specific enough to convey the main change without unnecessary detail.
Linked Issues Check ✅ Passed The pull request successfully addresses the core requirement of issue #937 to allow users to change product names. The implementation removes the readonly validation on the Product model, updates the view to make the product name input field always editable, and adds a confirmation dialog when editing existing product names to address the original concern mentioned in PR #595 about accidental modifications. These changes directly fulfill the feature request to provide users with the capability to modify product names.
Out of Scope Changes Check ✅ Passed All substantive changes in the pull request are directly aligned with the objective to make product names mutable. The removal of the readonly validation, the enablement of the input field, the addition of a confirmation dialog, and the corresponding test updates all serve the stated purpose. The only tangential change is a trailing space removal in the UI label text, which is a trivial cosmetic adjustment that does not constitute a meaningful out-of-scope modification.

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/views/price_lists/index.html.erb (1)

63-63: Consider implementing the user warning mentioned in the PR description.

Removing :disabled="product.id" now allows users to edit existing product names, which aligns with the PR objective. However, the PR description notes that the original concern from PR #595 was users unintentionally modifying product names when they meant to create new products, and proposes considering a user-facing warning (tooltip or dialog) to address this.

No such warning mechanism appears to be implemented in this change. Consider adding a confirmation dialog or tooltip when users edit an existing product's name to prevent accidental modifications.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7330b68 and 7361f96.

📒 Files selected for processing (3)
  • app/models/product.rb (0 hunks)
  • app/views/price_lists/index.html.erb (2 hunks)
  • spec/models/product_spec.rb (1 hunks)
💤 Files with no reviewable changes (1)
  • app/models/product.rb
🧰 Additional context used
🧬 Code graph analysis (1)
spec/models/product_spec.rb (1)
app/controllers/products_controller.rb (1)
  • update (18-26)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (2)
spec/models/product_spec.rb (1)

21-25: LGTM! Test correctly validates the new mutable behavior.

The test now expects product.update(name: 'new_name') to return true, which aligns with the removal of the readonly validation on product names. This validates that the feature works as intended.

app/views/price_lists/index.html.erb (1)

28-28: Good fix for trailing whitespace.

@codecov

codecov Bot commented Oct 26, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.44%. Comparing base (0e6cd2a) to head (eca3e5b).
⚠️ Report is 85 commits behind head on staging.

Additional details and impacted files
@@             Coverage Diff             @@
##           staging    #1007      +/-   ##
===========================================
- Coverage    75.17%   74.44%   -0.74%     
===========================================
  Files           55       51       -4     
  Lines         1116     1088      -28     
===========================================
- Hits           839      810      -29     
- Misses         277      278       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lodewiges
lodewiges added this pull request to the merge queue Oct 27, 2025
Merged via the queue into staging with commit 4fa7afc Oct 27, 2025
5 of 6 checks passed
@lodewiges
lodewiges deleted the fix/mutable_product_name branch October 27, 2025 00:14
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.

Allow changing product name

2 participants