Skip to content

Use formatted_id in user-facing WP identifier rendering#23200

Merged
akabiru merged 4 commits into
devfrom
feature/use-formatted-id-in-wp-identifier-rendering
May 14, 2026
Merged

Use formatted_id in user-facing WP identifier rendering#23200
akabiru merged 4 commits into
devfrom
feature/use-formatted-id-in-wp-identifier-rendering

Conversation

@akabiru
Copy link
Copy Markdown
Member

@akabiru akabiru commented May 13, 2026

Ticket

https://community.openproject.org/wp/74945

Split out of #22976; ships independently.

What are you trying to accomplish?

Three WP render paths spoke numeric ids — WorkPackage#to_s (autocomplete dropdown rows and the delete-confirmation dialog), link_to_work_package (the visible link label in activity-feed entries), and JournalFormatter::Cause (the automatic entry emitted when a parent / child / predecessor date cascade fires).

All three switch to formatted_id, which produces PROJ-7 in semantic mode and #42 in classic. The href uses to_param and is mode-correct without changes; this updates only the visible label.

Screenshots

pr22976-activity-cause-formatter-semantic pr22976-autocomplete-dropdown-semantic-annotated

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

akabiru added 3 commits May 13, 2026 17:41
…antic ids

The autocomplete dropdown in CKEditor renders each result with
`item.name = wp.to_s`, and `to_s` hardcoded `##{id}` — so a semantic-mode
search for `#KSTP-2` resolved correctly but the dropdown row showed
`Task #10244: Subject` instead of `Task KSTP-2: Subject`.

Switch to `formatted_id`, which already produces the user-facing form in
both modes (`PROJ-7` semantic, `#42` classic). The other caller — the
delete-dialog component — benefits from the same mode awareness.
The activity feed renders an automatic entry whenever a parent / child /
predecessor / related work package change cascades dates onto the
current WP. Both render paths spoke numeric ids:

- The plain-text branch (used for the API JSON) hardcoded `##{id}`.
- The HTML branch went through `link_to_work_package`, which built the
  visible link label as `Type ##{id}: subject`.

Both now use `formatted_id`, which produces `PROJ-7` in semantic mode
and `#42` in classic — same shape, mode-aware. The link href was
already mode-correct via `to_param`; only the visible label needed the
swap.
- Pin literal "MACROPROJ-42" in helper spec so a regression where
  the helper accidentally returns `#N` shape still trips the
  assertion. Previously the expected string was built from the
  same accessor under test.
- Drop framework-mechanics narration from the cause spec comment.
  The assertion already conveys intent.
@akabiru akabiru self-assigned this May 13, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

Deploying openproject with PullPreview

Field Value
Latest commit c9c9ea7
Job deploy
Status ✅ Deploy successful
Preview URL https://pr-23200-use-formatted-id-i-ip-178-105-9-66.my.opf.run:443

View logs

@akabiru akabiru marked this pull request as ready for review May 13, 2026 18:01
@akabiru akabiru requested review from Copilot and thykel May 13, 2026 18:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates user-facing work package identifier rendering to consistently use WorkPackage#formatted_id, ensuring semantic identifiers (e.g., PROJ-7) are shown in semantic mode while preserving classic #42 formatting in classic mode.

Changes:

  • Update WorkPackage#to_s to use formatted_id instead of the raw numeric id.
  • Update link_to_work_package and JournalFormatter::Cause to render formatted_id in visible labels / raw text variants.
  • Add/extend specs to cover classic vs semantic mode output for the affected render paths.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
app/models/work_package.rb Switch to_s to use formatted_id for mode-correct user-visible IDs.
app/helpers/work_packages_helper.rb Render formatted_id in work package link labels.
lib/open_project/journal_formatter/cause.rb Use formatted_id for raw text cause rendering when a related WP is present.
spec/models/work_package_spec.rb Add coverage for to_s output in classic vs semantic modes.
spec/helpers/work_packages_helper_spec.rb Add coverage for link_to_work_package label in semantic mode.
spec/lib/open_project/journal_formatter/cause_spec.rb Add coverage ensuring cause formatter uses formatted_id in semantic mode (HTML + raw).

Comment thread app/helpers/work_packages_helper.rb
The hardcoded `#6` in the examples was misleading once the rendered
label became mode-dependent. Use `<id>` placeholder so the docstring
stays accurate across both modes without re-describing the modes.
@akabiru
Copy link
Copy Markdown
Member Author

akabiru commented May 13, 2026

https://pr-23200-use-formatted-id-i-ip-178-105-9-66.my.opf.run/projects/DP/work_packages/12/activity

Note

WorkPackage links are not yet converted to semantic IDs- this PR only addresses the search menu and journal formatter. The former will be addressed in #23203

Screenshot 2026-05-13 at 9 29 09 PM Screenshot 2026-05-13 at 9 28 57 PM

Copy link
Copy Markdown
Contributor

@thykel thykel left a comment

Choose a reason for hiding this comment

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

🚀 🥳

@akabiru akabiru merged commit ab375e5 into dev May 14, 2026
16 of 17 checks passed
@akabiru akabiru deleted the feature/use-formatted-id-in-wp-identifier-rendering branch May 14, 2026 13:54
@github-actions github-actions Bot locked and limited conversation to collaborators May 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants