Skip to content

added-used-in-projects-dropdown-in-add-new-model#2231

Merged
MuhammadKhalilzadeh merged 2 commits intodevelopfrom
sw-016-sep-25-add-mapping-from-model-inventory-to-projects-and-framework
Sep 27, 2025
Merged

added-used-in-projects-dropdown-in-add-new-model#2231
MuhammadKhalilzadeh merged 2 commits intodevelopfrom
sw-016-sep-25-add-mapping-from-model-inventory-to-projects-and-framework

Conversation

@swaleha456
Copy link
Copy Markdown
Contributor

Add mapping from model inventory to projects or organizational frameworks

Fixes #2158

Please ensure all items are checked off before requesting a review:

  • I deployed the code locally.
  • I have performed a self-review of my code.
  • I have included the issue # in the PR.
  • I have labelled the PR correctly.
  • The issue I am working on is assigned to me.
  • I have avoided using hardcoded values to ensure scalability and maintain consistency across the application.
  • I have ensured that font sizes, color choices, and other UI elements are referenced from the theme.
  • My pull request is focused and addresses a single, specific feature.
  • If there are UI changes, I have attached a screenshot or video to this PR.
Screenshot 2025-09-26 at 1 05 06 PM Screenshot 2025-09-26 at 1 04 47 PM Screenshot 2025-09-26 at 12 40 36 PM

@swaleha456 swaleha456 added this to the 1.5 milestone Sep 26, 2025
@swaleha456 swaleha456 self-assigned this Sep 26, 2025
@swaleha456 swaleha456 added frontend Frontend related tasks/issues backend Backend related tasks/issues labels Sep 26, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 26, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
Client domain types
Clients/src/domain/interfaces/i.modelInventory.ts, Clients/src/domain/types/Project.ts
Add used_in_projects: string[] to client IModelInventory. Add name: string to framework in Project type.
Client UI: New Model Inventory flow
Clients/src/presentation/components/Modals/NewModelInventory/index.tsx, Clients/src/presentation/pages/ModelInventory/index.tsx
Add project loading, combined project+framework list, new form state/validation used_in_projects: string[], multi-select Autocomplete in modal, and include used_in_projects in modal initialData and submit flow.
Server API controller
Servers/controllers/modelInventory.ctrl.ts
Destructure and propagate used_in_projects in create and update controller handlers to the model layer.
Server domain interface & model
Servers/domain.layer/interfaces/i.modelInventory.ts, Servers/domain.layer/models/modelInventory/modelInventory.model.ts
Server interface adds used_in_projects (string). Model stores used_in_projects internally as comma-separated TEXT, validates non-empty, accepts array or string on create/update, and serializes JSON outputs as arrays.
Persistence & schema
Servers/utils/modelInventory.utils.ts, Servers/database/migrations/20250926170942-add-one-column-in-model-inventory-table.js, Servers/scripts/createNewTenant.ts
SQL utils include used_in_projects in INSERT/UPDATE replacements. Migration adds per-tenant used_in_projects TEXT NOT NULL DEFAULT ''. Tenant creation script adds the column to model_inventories.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

I hop through fields of specs and lights,
Mapping projects in jumpy bites—
Multi-select nibs and comma trails,
Saved in rows, returned as vales.
A rabbit's tag on inventory nights. 🐇

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly indicates the addition of a used-in-projects dropdown in the add-new-model form, which reflects the primary UI change introduced by this pull request.
Linked Issues Check ✅ Passed The implementation adds a multi-select dropdown for mapping model inventory entries to projects and organizational frameworks, loads all projects with the relevant ISO frameworks, persists the new used_in_projects field end-to-end through client, server, and database layers, thereby fulfilling the coding objectives of issue #2158.
Out of Scope Changes Check ✅ Passed All modifications directly support the mapping feature by extending interfaces, adding the used_in_projects field, and updating UI, server, and database logic to persist and validate this new field; there are no unrelated or out-of-scope changes.
Description Check ✅ Passed The description includes a concise summary of changes, correctly uses “Fixes #2158” to reference the linked issue, and the checklist is fully completed with UI screenshots attached, so it aligns with the repository’s PR template.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sw-016-sep-25-add-mapping-from-model-inventory-to-projects-and-framework

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a44f9df and a88613b.

📒 Files selected for processing (1)
  • Servers/utils/modelInventory.utils.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Servers/utils/modelInventory.utils.ts

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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_projects as 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 TEXT column 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 us TEXT[] or JSONB which map naturally to the string[] 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_projects as plain TEXT invites delimiter headaches. Before this lands in prod, let's make the column TEXT[] (or JSONB) 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3807876 and a44f9df.

📒 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 for used_in_projects looks 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_projects into 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_projects as 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_projects flows 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;
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.

⚠️ Potential issue | 🔴 Critical

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[].

Comment thread Servers/utils/modelInventory.utils.ts Outdated
biases?: string;
limitations?: string;
hosting_provider?: string;
used_in_projects: string;
Copy link
Copy Markdown
Collaborator

@HarshP4585 HarshP4585 Sep 26, 2025

Choose a reason for hiding this comment

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

What is this field for? It is named like it should be a boolean field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It’s new field for add new model in model Inventory to select the projects and frameworks are using in

Copy link
Copy Markdown
Collaborator

@MuhammadKhalilzadeh MuhammadKhalilzadeh left a comment

Choose a reason for hiding this comment

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

Thank you for the implementation @swaleha456

Only there are a few small warnings and errors that we need to fix.:

Image

It's not letting me to create models

@swaleha456
Copy link
Copy Markdown
Contributor Author

swaleha456 commented Sep 26, 2025

Thank you for the implementation @swaleha456

Only there are a few small warnings and errors that we need to fix.:

Image It's not letting me to create models

no worries @MuhammadKhalilzadeh I will check and fix then I will update here.

@swaleha456
Copy link
Copy Markdown
Contributor Author

Thank you for the implementation @swaleha456
Only there are a few small warnings and errors that we need to fix.:
Image
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

@MuhammadKhalilzadeh MuhammadKhalilzadeh merged commit 713fc6f into develop Sep 27, 2025
3 checks passed
@MuhammadKhalilzadeh MuhammadKhalilzadeh deleted the sw-016-sep-25-add-mapping-from-model-inventory-to-projects-and-framework branch September 27, 2025 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend related tasks/issues frontend Frontend related tasks/issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add mapping from model inventory to projects or organizational frameworks

3 participants