added-used-in-projects-dropdown-in-add-new-model#2231
Conversation
WalkthroughAdds a new used_in_projects field across client types and UI, server interfaces, domain model, SQL utilities, tenant creation script, and a per-tenant DB migration; UI provides a multi-select for project/framework mapping and the server persists the field as TEXT while exposing arrays in JSON. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant UI as NewModelInventory (Client)
participant API as modelInventory.ctrl (Server)
participant M as ModelInventoryModel
participant DB as DB (model_inventories)
U->>UI: Open modal
UI->>API: GET /projects
API-->>UI: 200 OK (projects)
UI->>UI: Build selectable list (projects + enabled ISO frameworks)
U->>UI: Select multiple used_in_projects
U->>UI: Submit form (includes used_in_projects[])
UI->>API: POST /model-inventories { ..., used_in_projects: [] }
API->>M: createNewModelInventory({... used_in_projects ...})
M->>DB: INSERT (... used_in_projects TEXT ...)
DB-->>M: Row created
M-->>API: JSON (used_in_projects as array)
API-->>UI: 201 Created
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Clients/src/presentation/components/Modals/NewModelInventory/index.tsx (1)
291-315: Add client-side validation for “Used in projects”.The server enforces
used_in_projectsas non-empty (ValidationException + NOT NULL), but the form currently allows submitting an empty array, which will bounce with a 400. We should block submit locally just like the other required fields to avoid a broken flow for users.if (!values.status_date) { newErrors.status_date = "Status date is required."; } + + if (!values.used_in_projects || values.used_in_projects.length === 0) { + newErrors.used_in_projects = "Used in projects is required."; + }
🧹 Nitpick comments (2)
Servers/scripts/createNewTenant.ts (1)
670-671: Prefer array/JSON storage for multi-select column.Line 670 introduces a
TEXTcolumn for a multi-select field. Persisting user-chosen projects/frameworks as a delimited string will make it brittle (commas inside names will corrupt the split) and hard to query. Postgres gives usTEXT[]orJSONBwhich map naturally to thestring[]you expose in the API. Please switch the schema (here and in the migration) to one of those types so we don't ship a format we'll need to undo later.Servers/database/migrations/20250926170942-add-one-column-in-model-inventory-table.js (1)
20-22: Schema type should reflect multi-select semantics.For the same reason mentioned in createNewTenant (Line 670 there), adding
used_in_projectsas plainTEXTinvites delimiter headaches. Before this lands in prod, let's make the columnTEXT[](orJSONB) so the persisted shape matches the array you expose via the API. That way the migration and tenant-creation script stay consistent, and we avoid having to write another migration later to fix the type.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
Clients/src/domain/interfaces/i.modelInventory.ts(1 hunks)Clients/src/domain/types/Project.ts(1 hunks)Clients/src/presentation/components/Modals/NewModelInventory/index.tsx(7 hunks)Clients/src/presentation/pages/ModelInventory/index.tsx(1 hunks)Servers/controllers/modelInventory.ctrl.ts(4 hunks)Servers/database/migrations/20250926170942-add-one-column-in-model-inventory-table.js(1 hunks)Servers/domain.layer/interfaces/i.modelInventory.ts(1 hunks)Servers/domain.layer/models/modelInventory/modelInventory.model.ts(6 hunks)Servers/scripts/createNewTenant.ts(1 hunks)Servers/utils/modelInventory.utils.ts(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
Servers/domain.layer/models/modelInventory/modelInventory.model.ts (1)
Servers/domain.layer/exceptions/custom.exception.ts (1)
ValidationException(94-116)
Clients/src/presentation/components/Modals/NewModelInventory/index.tsx (1)
Clients/src/domain/types/Project.ts (1)
Project(3-35)
Servers/database/migrations/20250926170942-add-one-column-in-model-inventory-table.js (1)
Servers/tools/getTenantHash.ts (1)
getTenantHash(3-6)
🔇 Additional comments (5)
Servers/domain.layer/models/modelInventory/modelInventory.model.ts (1)
101-214: Backend wiring forused_in_projectslooks consistent.Column definition and validation follow the existing required-field pattern cleanly; no issues spotted here.
Clients/src/presentation/pages/ModelInventory/index.tsx (1)
800-801: Thanks for wiring the edit flow.Line 800 now passes
used_in_projectsinto the modal, so edits preserve the association correctly. Looks good.Clients/src/domain/types/Project.ts (1)
23-24: Nice type enrichment.Line 23 adds the framework
name, which keeps the client types aligned with the new dropdown labels. 👍Clients/src/domain/interfaces/i.modelInventory.ts (1)
16-16: Interface update reads well.Line 16 marks
used_in_projectsas part of the contract, matching the new UI/API. LGTM.Servers/controllers/modelInventory.ctrl.ts (1)
125-156: Good propagation to the model layer.Lines 125 and 155 ensure
used_in_projectsflows through both create and update paths, keeping the controller aligned with the domain model. Looks solid.
| biases?: string; | ||
| limitations?: string; | ||
| hosting_provider?: string; | ||
| used_in_projects: string; |
There was a problem hiding this comment.
Align server type with array payload
All controller paths (see Servers/controllers/modelInventory.ctrl.ts, Lines 111-157 and 200-268) now pass used_in_projects straight from req.body, which the UI submits as a string[]. However, this interface defines the field as a string. Because the interface drives both the domain model constructor and the serialized response, we end up with a type mismatch: the server model expects a string while the request supplies an array. In practice this will surface as a validation or persistence failure when the backend attempts to coerce the array to a string. Update the interface (and downstream handling) to accept string[] consistently so it matches the client contract.
🤖 Prompt for AI Agents
In Servers/domain.layer/interfaces/i.modelInventory.ts around line 18, update
the used_in_projects field from string to string[] to match the client payload;
then update the domain model constructor(s) and any code that builds/serializes
model inventory objects (including validation, type guards, and
persistence/mapping logic) to accept and pass through a string[] rather than
coercing to a single string, ensuring requests from controllers
(Servers/controllers/modelInventory.ctrl.ts) and responses consistently use
string[].
| biases?: string; | ||
| limitations?: string; | ||
| hosting_provider?: string; | ||
| used_in_projects: string; |
There was a problem hiding this comment.
What is this field for? It is named like it should be a boolean field.
There was a problem hiding this comment.
It’s new field for add new model in model Inventory to select the projects and frameworks are using in
MuhammadKhalilzadeh
left a comment
There was a problem hiding this comment.
Thank you for the implementation @swaleha456
Only there are a few small warnings and errors that we need to fix.:
It's not letting me to create models
no worries @MuhammadKhalilzadeh I will check and fix then I will update here. |
It is fixed @MuhammadKhalilzadeh |

Add mapping from model inventory to projects or organizational frameworks
Fixes #2158
Please ensure all items are checked off before requesting a review: