Skip to content

feat: add model-list page#995

Open
carlosthe19916 wants to merge 1 commit intoguacsec:mainfrom
carlosthe19916:feat/models-all
Open

feat: add model-list page#995
carlosthe19916 wants to merge 1 commit intoguacsec:mainfrom
carlosthe19916:feat/models-all

Conversation

@carlosthe19916
Copy link
Copy Markdown
Collaborator

@carlosthe19916 carlosthe19916 commented Apr 15, 2026

Fixes: https://redhat.atlassian.net/browse/TC-4111

Counter part of guacsec/trustify#2325 (review)

Summary by Sourcery

Add a new Models listing view backed by a models API endpoint and integrate it into the application navigation and routing.

New Features:

  • Expose a new /api/v2/sbom/models endpoint in the OpenAPI spec to list AI models with filtering, sorting, and pagination.
  • Introduce a Models page with toolbar and table components to display AI models including name, supplier, and licenses.
  • Add client-side query hook to fetch models from the backend and wire it into the shared table controls system.
  • Add a Models route and sidebar navigation entry, along with table state persistence configuration for the models table.

Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 15, 2026

Reviewer's Guide

Adds a new AI models listing feature, including backend OpenAPI endpoint wiring, React query hook, table controls, toolbar, routing, and sidebar navigation entry for a paginated, filterable models list view.

Sequence diagram for loading the models list view

sequenceDiagram
  actor User
  participant SidebarApp
  participant Router
  participant ModelList
  participant ModelSearchProvider
  participant ReactQuery
  participant listAllModels
  participant TrustdAPI
  participant ModelToolbar
  participant ModelTable

  User->>SidebarApp: Click Models NavLink
  SidebarApp->>Router: Navigate to path Paths.models
  Router->>ModelList: Render route element
  ModelList->>ModelSearchProvider: Render with children
  ModelSearchProvider->>ReactQuery: useFetchAllModels(params)
  ReactQuery->>listAllModels: listAllModels(client, query)
  listAllModels->>TrustdAPI: GET /api/v2/sbom/models?q,sort,offset,limit
  TrustdAPI-->>listAllModels: 200 PaginatedResults_SbomModel
  listAllModels-->>ReactQuery: AxiosResponse
  ReactQuery-->>ModelSearchProvider: data items and total
  ModelSearchProvider-->>ModelToolbar: Provide ModelSearchContext
  ModelSearchProvider-->>ModelTable: Provide ModelSearchContext
  ModelToolbar->>ModelToolbar: Render filters and top pagination
  ModelTable->>ModelTable: Render table rows from context

  User->>ModelToolbar: Change filter or page
  ModelToolbar->>ModelSearchProvider: Update table control state
  ModelSearchProvider->>ReactQuery: Refetch useFetchAllModels
  ReactQuery->>listAllModels: listAllModels(client, updatedQuery)
  listAllModels->>TrustdAPI: GET /api/v2/sbom/models with new params
  TrustdAPI-->>listAllModels: 200 PaginatedResults_SbomModel
  listAllModels-->>ReactQuery: AxiosResponse
  ReactQuery-->>ModelSearchProvider: Updated data
  ModelSearchProvider-->>ModelTable: Update tableControls and totalItemCount
  ModelTable->>ModelTable: Re-render rows
Loading

Class diagram for new models list components and query hook

classDiagram
  class ModelList {
    +ReactNode children
    +render()
  }

  class ModelSearchProvider {
    +ReactNode children
    +tableControlState
    +ModelSearchContext Provider
    +render()
  }

  class ModelSearchContext {
    <<context>>
    +tableControls ITableControls
    +totalItemCount number
    +isFetching boolean
    +fetchError AxiosError
  }

  class ModelTable {
    +render()
  }

  class ModelToolbar {
    +boolean showFilters
    +render()
  }

  class useFetchAllModels {
    <<hook>>
    +useFetchAllModels(params HubRequestParams, disableQuery boolean)
  }

  class ITableControls {
    <<interface>>
    +numRenderedColumns number
    +currentPageItems SbomModel[]
    +propHelpers
  }

  class SbomModel {
    +string id
    +string name
    +object properties
  }

  class getModelProperties {
    +getModelProperties(properties object) SbomModelProperties
  }

  class SbomModelProperties {
    +string suppliedBy
    +string licenses
  }

  class TablePersistenceKeyPrefixes {
    +string models
  }

  class Paths {
    +string models
  }

  class listAllModels {
    +listAllModels(client object, query object)
  }

  class ReactQueryUseQuery {
    <<hook>>
    +useQuery(options object)
  }

  class SimplePagination {
    +string idPrefix
    +boolean isTop
    +object paginationProps
  }

  class FilterToolbar {
    +render()
  }

  class TableControlsHelpers {
    +getHubRequestParams(state object) HubRequestParams
    +useTableControlState(options object)
    +useTableControlProps(options object)
    +requestParamsQuery(params HubRequestParams) object
  }

  ModelList --> ModelSearchProvider : uses
  ModelList --> ModelToolbar : uses
  ModelList --> ModelTable : uses

  ModelSearchProvider --> ModelSearchContext : provides
  ModelToolbar --> ModelSearchContext : consumes
  ModelTable --> ModelSearchContext : consumes

  ModelSearchProvider --> useFetchAllModels : calls
  useFetchAllModels --> ReactQueryUseQuery : uses
  useFetchAllModels --> listAllModels : calls

  ModelTable --> SbomModel : renders
  ModelTable --> getModelProperties : calls
  getModelProperties --> SbomModelProperties : returns

  ModelToolbar --> FilterToolbar : uses
  ModelToolbar --> SimplePagination : uses
  ModelTable --> SimplePagination : uses

  ModelSearchProvider --> TableControlsHelpers : uses

  TablePersistenceKeyPrefixes <.. ModelSearchProvider : models key
  Paths <.. SidebarApp : models route entry
Loading

File-Level Changes

Change Details Files
Expose a new paginated AI models listing endpoint in the OpenAPI client definition.
  • Add /api/v2/sbom/models GET path with query parameters for q, sort, offset, and limit
  • Define response schema to use PaginatedResults_SbomModel for returned data
client/openapi/trustd.yaml
Add navigation and routing for the new Models page in the client app.
  • Add Models route path constant and lazy-loaded ModelList page
  • Wire Models page into the main router via LazyRouteElement
  • Add a Models NavLink entry in the sidebar navigation
  • Introduce a table state persistence key prefix for models
client/src/app/Routes.tsx
client/src/app/layout/sidebar.tsx
client/src/app/Constants.ts
Implement the Models list page with shared table controls, toolbar, and pagination.
  • Create ModelSearchContext and provider wiring table-controls state, filters, and sorting to the models API
  • Create useFetchAllModels React Query hook using listAllModels client API and Hub-style request params
  • Implement ModelToolbar with filter toolbar and top pagination wired to table-controls helpers
  • Implement ModelTable to render model rows with name, suppliedBy, and licenses columns using shared ConditionalTableBody and pagination
  • Compose ModelList page with metadata, header, toolbar, and table wrapped in ModelSearchProvider
client/src/app/pages/model-list/model-context.tsx
client/src/app/queries/models.ts
client/src/app/pages/model-list/model-toolbar.tsx
client/src/app/pages/model-list/model-table.tsx
client/src/app/pages/model-list/model-list.tsx
client/src/app/pages/model-list/index.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The model list page depends on getModelProperties from the sbom details drawer, which creates a cross-page coupling; consider moving this helper into a shared utility module so the model list is not tied to the sbom details implementation.
  • In ModelSearchProvider, the tableName is singular ("model") while the persistence key prefix is plural (TablePersistenceKeyPrefixes.models); if other tables follow a naming convention it may be worth aligning this to keep persisted state keys predictable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The model list page depends on `getModelProperties` from the sbom details drawer, which creates a cross-page coupling; consider moving this helper into a shared utility module so the model list is not tied to the sbom details implementation.
- In `ModelSearchProvider`, the `tableName` is singular (`"model"`) while the persistence key prefix is plural (`TablePersistenceKeyPrefixes.models`); if other tables follow a naming convention it may be worth aligning this to keep persisted state keys predictable.

## Individual Comments

### Comment 1
<location path="client/src/app/pages/model-list/model-context.tsx" line_range="32" />
<code_context>
+  fetchError: AxiosError | null;
+}
+
+const contextDefaultValue = {} as IModelSearchContext;
+
+export const ModelSearchContext =
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Avoid casting an empty object as the full context type

Casting `{}` as `IModelSearchContext` bypasses type safety and could cause runtime errors if the context is used outside a provider. Prefer either:
- Initializing with a concrete default value (no-op functions, empty arrays, etc.), or
- Leaving it possibly `undefined` and throwing in a custom hook when used without a provider.

This preserves type checking and causes incorrect usage to fail fast.

Suggested implementation:

```typescript
const contextDefaultValue: IModelSearchContext | undefined = undefined;

export const ModelSearchContext =
  React.createContext<IModelSearchContext | undefined>(contextDefaultValue);

export const useModelSearchContext = (): IModelSearchContext => {
  const context = React.useContext(ModelSearchContext);

  if (!context) {
    throw new Error(
      "useModelSearchContext must be used within a ModelSearchProvider"
    );
  }

  return context;
};

interface IModelProvider {

```

1. Find all usages of `React.useContext(ModelSearchContext)` (or `useContext(ModelSearchContext)`) and replace them with `useModelSearchContext()`.
2. Ensure `React` is imported in this file with a namespace import (`import * as React from "react";`) or otherwise has `React.useContext` available; if not, add/import `useContext` and adjust the hook accordingly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

fetchError: AxiosError | null;
}

const contextDefaultValue = {} as IModelSearchContext;
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.

suggestion (bug_risk): Avoid casting an empty object as the full context type

Casting {} as IModelSearchContext bypasses type safety and could cause runtime errors if the context is used outside a provider. Prefer either:

  • Initializing with a concrete default value (no-op functions, empty arrays, etc.), or
  • Leaving it possibly undefined and throwing in a custom hook when used without a provider.

This preserves type checking and causes incorrect usage to fail fast.

Suggested implementation:

const contextDefaultValue: IModelSearchContext | undefined = undefined;

export const ModelSearchContext =
  React.createContext<IModelSearchContext | undefined>(contextDefaultValue);

export const useModelSearchContext = (): IModelSearchContext => {
  const context = React.useContext(ModelSearchContext);

  if (!context) {
    throw new Error(
      "useModelSearchContext must be used within a ModelSearchProvider"
    );
  }

  return context;
};

interface IModelProvider {
  1. Find all usages of React.useContext(ModelSearchContext) (or useContext(ModelSearchContext)) and replace them with useModelSearchContext().
  2. Ensure React is imported in this file with a namespace import (import * as React from "react";) or otherwise has React.useContext available; if not, add/import useContext and adjust the hook accordingly.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.90%. Comparing base (7d24134) to head (e1d7e8d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
client/src/app/layout/sidebar.tsx 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #995      +/-   ##
==========================================
- Coverage   66.91%   66.90%   -0.01%     
==========================================
  Files         221      221              
  Lines        3887     3889       +2     
  Branches      903      904       +1     
==========================================
+ Hits         2601     2602       +1     
  Misses        945      945              
- Partials      341      342       +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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant