Skip to content

feat(orm): add overridable NameSearch#188

Merged
buke merged 6 commits into
mainfrom
feat/orm-model-namesearch
Jul 25, 2026
Merged

feat(orm): add overridable NameSearch#188
buke merged 6 commits into
mainfrom
feat/orm-model-namesearch

Conversation

@buke

@buke buke commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add BaseModel.NameSearch(name, condition?, options?) → T[] with a default DisplayName like keyword path that reuses Search (record rules / soft-delete unchanged).
  • Wire relation typeahead remotes to NameSearch: OManyToOneField, OManyToOneRefField, OManyToManyTagsField, OManyToManyRefTagsField (M2M tags align to DisplayName like; multi-field matching via static override).
  • Expose NameSearch on WebModelStore and webapistore base services so conventional RPC/store binding stays consistent.

Implements PR-P0-M3 from the module platform gap assessment (NameSearch hook; NameCreate still P2).

Test plan

  • ./choysum test unit core --be --pattern 'NameSearch|buildNameSearch|mergeNameSearch'
  • npx vitest run modules/web/web/components/field/OManyToOneField.mapping.test.ts modules/web/web/components/field/OManyToOneRefField.mapping.test.ts modules/web/web/components/field/OManyToManyTagsField.mapping.test.ts modules/web/web/components/field/OManyToManyRefTagsField.mapping.test.ts
  • ./choysum test typecheck core and ./choysum test typecheck web
  • Manual: M2O dropdown keyword suggestions still work; list keyword / Search more / M2M tree unchanged
  • Optional: static override NameSearch on a demo model changes typeahead matching

By submitting this pull request, you agree to the Contributor License Agreement (CLA) of this project. If you have not yet signed it, please follow the instructions provided by @cla-bot below.

Summary by CodeRabbit

  • New Features
    • Added model-based NameSearch for typeahead-style lookups (defaults to Id and DisplayName).
    • Exposed NameSearch and Copy on the model store for use by the UI.
    • Updated relationship field components to use NameSearch for remote typeahead.
  • Bug Fixes
    • Standardized keyword trimming and search condition handling across remote typeahead.
  • Tests
    • Added and updated unit/contract tests to verify NameSearch wiring, default options/limits, and that the legacy Search path is not used.

- Add BaseModel.NameSearch that defaults to DisplayName like via Search.

- Wire M2O, M2O-Ref, and M2M Tags typeahead remotes to NameSearch.

- Expose NameSearch on WebModelStore and webapistore base services.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds reusable BaseModel.NameSearch behavior with default display-name matching, exposes it through model stores, and updates relation typeahead fields to use the new service.

Changes

NameSearch typeahead integration

Layer / File(s) Summary
Model NameSearch contract and implementation
modules/core/service/orm/model/model_namesearch.ts, modules/core/service/orm/model/model.ts, modules/core/service/orm/model/model_namesearch.test.ts
Adds name-search condition and option helpers, BaseModel.NameSearch, custom override support, and unit tests for delegation and defaults.
Store service exposure
internal/module/artifact/generate/webapistore.go, modules/web/web/stores/modelStore.ts
Registers NameSearch and Copy as base services in generated stores and the WebModelStore interface.
Many-relation typeahead migration
modules/web/web/components/field/OManyToMany*Field.vue, modules/web/web/components/field/OManyToMany*Field.mapping.test.ts, modules/web/web/components/field/relationTypeahead.NameSearch.test.ts
Replaces local keyword-condition construction with NameSearch calls while preserving effective conditions and result handling.
One-relation typeahead migration
modules/web/web/components/field/OManyToOne*Field.vue, modules/web/web/components/field/OManyToOne*Field.mapping.test.ts, modules/web/web/components/field/relationTypeahead.NameSearch.test.ts
Routes remote searches through NameSearch with Id and DisplayName fields and removes the previous keyword-condition path.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RelationField
  participant RelationStore
  participant BaseModel
  participant Search
  RelationField->>RelationStore: NameSearch(keyword, effectiveConditions)
  RelationStore->>BaseModel: invoke NameSearch
  BaseModel->>Search: build condition and call Search
  Search-->>RelationField: return matching rows
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.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 is concise and accurately highlights the new overridable NameSearch ORM capability.
Description check ✅ Passed The description includes the required CLA note and a clear summary and test plan for the change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/orm-model-namesearch

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

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

buke and others added 2 commits July 25, 2026 21:46
- Exercise name ?? '' when buildNameSearchCondition receives nullish name.

- Call NameSearch with only the name argument to hit condition = [].

Co-authored-by: Cursor <cursoragent@cursor.com>
- Mount M2O/M2O-Ref and M2M Tags fields with stubbed el-select-v2.

- Assert remote-method calls NameSearch with trimmed keyword and options.

Co-authored-by: Cursor <cursoragent@cursor.com>

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modules/web/web/components/field/relationTypeahead.NameSearch.test.ts`:
- Around line 171-197: Update the OManyToManyRefTagsField remote-search test to
assert that the mocked Search service is never called, while preserving the
existing NameSearch call and hydration-field assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 525d0911-c746-438b-a0d9-2db54e655647

📥 Commits

Reviewing files that changed from the base of the PR and between 4ff2c81 and a36ab56.

📒 Files selected for processing (1)
  • modules/web/web/components/field/relationTypeahead.NameSearch.test.ts

buke and others added 2 commits July 25, 2026 22:05
- Align OManyToManyRefTagsField NameSearch coverage with the Tags case.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Exercise query ?? '' / keyword || '' via null and empty remote queries.

- Hit relationStore?. short-circuit when the relation store is unresolved.

Co-authored-by: Cursor <cursoragent@cursor.com>
@buke

buke commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

/improve

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modules/web/web/components/field/relationTypeahead.NameSearch.test.ts`:
- Around line 295-313: Add an equivalent Search not-called assertion after the
.trigger-remote-null click in the OManyToManyRefTagsField test, alongside the
existing NameSearch expectation, so both falsy-query branches verify the legacy
Search service is not invoked.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d264218-0672-48ec-8b4a-8cf5fb67e8ff

📥 Commits

Reviewing files that changed from the base of the PR and between 819561f and ee5730c.

📒 Files selected for processing (1)
  • modules/web/web/components/field/relationTypeahead.NameSearch.test.ts

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

- Mirror the empty-keyword case after trigger-remote-null.

Co-authored-by: Cursor <cursoragent@cursor.com>
@buke
buke merged commit 9b8a4b8 into main Jul 25, 2026
43 checks passed
@buke
buke deleted the feat/orm-model-namesearch branch July 25, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant