Skip to content

Refactor RegisterCatlogModel and Remove useEffect #4420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Taj010
Copy link
Contributor

@Taj010 Taj010 commented Jun 26, 2025

For: https://issues.redhat.com/browse/RHOAIENG-21678

Description

The original RegisterCatalogModel.tsx component was split into two separate components: RegisterCatalogModelPage.tsx (handling data fetching, loading states, and routing) and RegisterCatalogModelForm.tsx (rendering the form UI and handling form logic). The previous useEffect workaround for prefilling form data was replaced with using a custom hook (useRegisterCatalogModelDataWithDefaults). This is a followup tech debt work for #3921

How Has This Been Tested?

  • Go to Model Catalog, click on a model
  • Click "Register model"
  • Ensure that the initial functionality/view remained the same
  • Edit one of the fields in the form
  • Wait at least 30 seconds
  • See that your edits are not reset to the initial prefilled data

Test Impact

Cypress test was added to verify that user input in form fields remains stable and doesn't reset to prefilled values over time.

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change.

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

Summary by CodeRabbit

  • New Features
    • Introduced a new page and form for registering catalog models, featuring improved state management, validation, and error handling.
    • Enhanced navigation with updated breadcrumbs during the registration process.
  • Bug Fixes
    • Added a test to ensure user input in the registration form remains unchanged over time.
  • Refactor
    • Reorganized registration components for better modularity and maintainability.
  • Chores
    • Updated internal exports to improve code accessibility.

@openshift-ci openshift-ci bot requested a review from FedeAlonso June 26, 2025 17:53
Copy link
Contributor

coderabbitai bot commented Jun 26, 2025

Walkthrough

The changes refactor the catalog model registration feature by replacing the monolithic RegisterCatalogModel component with a new modular structure. The registration logic and UI are now split into RegisterCatalogModelPage and RegisterCatalogModelForm. Related routing and test updates accompany the refactor, and a utility constant is made public for broader reuse.

Changes

File(s) Change Summary
frontend/src/pages/modelCatalog/screens/RegisterCatalogModel.tsx Deleted the original RegisterCatalogModel component and its logic.
frontend/src/pages/modelCatalog/screens/RegisterCatalogModelForm.tsx Added new RegisterCatalogModelForm component and supporting hook for form state management.
frontend/src/pages/modelCatalog/screens/RegisterCatalogModelPage.tsx Added new RegisterCatalogModelPage component to manage data loading and render the form page.
frontend/src/pages/modelCatalog/ModelCatalogRoutes.tsx Updated import and usage from RegisterCatalogModel to RegisterCatalogModelPage in routing.
frontend/src/pages/modelRegistry/screens/RegisterModel/useRegisterModelData.ts Made registerModelFormDataDefaultsForModelCatalog constant exported for external use.
frontend/src/tests/cypress/cypress/tests/mocked/modelCatalog/registerCatalogModel.cy.ts Added Cypress test to verify form field stability after user input on the registration page.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant RegisterCatalogModelPage
    participant RegisterCatalogModelForm
    participant ModelRegistryService
    participant Router

    User->>RegisterCatalogModelPage: Navigates to registration page
    RegisterCatalogModelPage->>RegisterCatalogModelForm: Passes model, registry, and data
    User->>RegisterCatalogModelForm: Fills out form fields
    RegisterCatalogModelForm->>ModelRegistryService: Submits registration
    ModelRegistryService-->>RegisterCatalogModelForm: Returns success or error
    RegisterCatalogModelForm->>Router: Navigates to model detail or shows error
Loading

Suggested labels

lgtm, approved

Poem

A hop, a skip, a brand new form,
The catalog’s flow is now transformed!
With pages split and fields that stay,
The rabbits code in bright array.
No bouncing back to defaults here,
Just onward—register, and cheer! 🐇✨


📜 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 8417817 and 77ea719.

📒 Files selected for processing (1)
  • frontend/src/__tests__/cypress/cypress/tests/mocked/modelCatalog/registerCatalogModel.cy.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/tests/cypress/cypress/tests/mocked/modelCatalog/registerCatalogModel.cy.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Lint
  • GitHub Check: Cypress-Setup
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci openshift-ci bot requested a review from mturley June 26, 2025 17:53
Copy link
Contributor

openshift-ci bot commented Jun 26, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign antowaddle for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
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: 0

🧹 Nitpick comments (2)
frontend/src/pages/modelCatalog/screens/RegisterCatalogModelPage.tsx (1)

41-46: Consider enhancing the loading state UI.

While the loading logic is correct, the generic "Loading..." text could be more informative.

-        <div>Loading...</div>
+        <div>Loading model registration form...</div>

Also applies to: 84-85

frontend/src/pages/modelCatalog/screens/RegisterCatalogModelForm.tsx (1)

119-123: Use optional chaining for cleaner code.

The current approach with && can be simplified using optional chaining.

         // eslint-disable-next-line camelcase
         string_value:
-          model.artifacts?.map((artifact) => artifact.tags && artifact.tags[0])[0] ?? '',
+          model.artifacts?.map((artifact) => artifact.tags?.[0])[0] ?? '',
         metadataType: ModelRegistryMetadataType.STRING,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81b60a6 and 8417817.

📒 Files selected for processing (6)
  • frontend/src/__tests__/cypress/cypress/tests/mocked/modelCatalog/registerCatalogModel.cy.ts (1 hunks)
  • frontend/src/pages/modelCatalog/ModelCatalogRoutes.tsx (2 hunks)
  • frontend/src/pages/modelCatalog/screens/RegisterCatalogModel.tsx (0 hunks)
  • frontend/src/pages/modelCatalog/screens/RegisterCatalogModelForm.tsx (1 hunks)
  • frontend/src/pages/modelCatalog/screens/RegisterCatalogModelPage.tsx (1 hunks)
  • frontend/src/pages/modelRegistry/screens/RegisterModel/useRegisterModelData.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • frontend/src/pages/modelCatalog/screens/RegisterCatalogModel.tsx
🧰 Additional context used
🧠 Learnings (1)
frontend/src/__tests__/cypress/cypress/tests/mocked/modelCatalog/registerCatalogModel.cy.ts (1)
Learnt from: christianvogt
PR: opendatahub-io/odh-dashboard#4381
File: frontend/src/__tests__/cypress/tsconfig.json:9-9
Timestamp: 2025-06-19T20:38:32.485Z
Learning: In the ODH Dashboard project, the `frontend/src/__tests__/cypress/tsconfig.json` file intentionally has an empty `files` array to disable type checking for Cypress test files. This is part of the monorepo structure where Cypress was separated into its own package but type checking is deliberately disabled for it.
🧬 Code Graph Analysis (2)
frontend/src/__tests__/cypress/cypress/tests/mocked/modelCatalog/registerCatalogModel.cy.ts (2)
frontend/src/__tests__/cypress/cypress/pages/modelCatalog/registerCatalogModel.ts (1)
  • registerCatalogModelPage (23-23)
frontend/src/__tests__/cypress/cypress/pages/modelRegistry/registerModelPage.ts (1)
  • registerModelPage (89-89)
frontend/src/pages/modelCatalog/screens/RegisterCatalogModelPage.tsx (6)
frontend/src/pages/modelCatalog/types.ts (1)
  • CatalogModelDetailsParams (1-6)
frontend/src/pages/modelCatalog/utils.ts (2)
  • decodeParams (42-47)
  • findModelFromModelCatalogSources (11-32)
frontend/src/concepts/modelRegistry/context/ModelRegistriesContext.tsx (1)
  • ModelRegistriesContext (20-27)
frontend/src/concepts/modelCatalog/context/ModelCatalogContext.tsx (1)
  • ModelCatalogContext (16-18)
frontend/src/concepts/modelCatalog/types.ts (1)
  • CatalogModel (18-37)
frontend/src/routes/modelCatalog/catalogModelDetails.ts (1)
  • getCatalogModelDetailsRoute (7-13)
🪛 Biome (1.9.4)
frontend/src/pages/modelCatalog/screens/RegisterCatalogModelForm.tsx

[error] 121-121: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (6)
frontend/src/pages/modelCatalog/ModelCatalogRoutes.tsx (1)

8-8: LGTM! Clean refactoring of the registration component.

The import and usage have been correctly updated to use the new RegisterCatalogModelPage component, aligning with the architectural improvement of separating page logic from form UI.

Also applies to: 24-24

frontend/src/__tests__/cypress/cypress/tests/mocked/modelCatalog/registerCatalogModel.cy.ts (1)

342-377: Excellent test coverage for the form input stability fix!

This test directly verifies that the user input issue mentioned in the PR objectives has been resolved. The 30-second timeout assertions ensure that form values remain stable and don't revert to prefilled defaults.

frontend/src/pages/modelRegistry/screens/RegisterModel/useRegisterModelData.ts (1)

66-69: Good modularization - exporting defaults for reuse.

Making registerModelFormDataDefaultsForModelCatalog exportable enables its use in the new RegisterCatalogModelForm component, promoting code reuse and consistency.

frontend/src/pages/modelCatalog/screens/RegisterCatalogModelPage.tsx (1)

15-90: Clean separation of page logic from form UI - well structured!

The component properly handles data fetching, loading states, and breadcrumb navigation. The conditional rendering based on isDataReady ensures the form only renders when all required data is available.

frontend/src/pages/modelCatalog/screens/RegisterCatalogModelForm.tsx (2)

44-69: Excellent solution to prevent form value resets!

The useRegisterCatalogModelDataWithDefaults hook with the isInitialized ref is a clean solution to the core issue. This ensures form values are initialized only once, preventing the problematic resets that users were experiencing.


71-238: Well-structured form component with comprehensive error handling.

The form properly handles:

  • Model registry selection
  • Form validation including duplicate name checking
  • Submission with proper error handling and state management
  • Analytics tracking for user interactions
  • Navigation on success/cancel

The separation from the page component improves maintainability and testability.

Copy link

codecov bot commented Jun 26, 2025

Codecov Report

Attention: Patch coverage is 88.04348% with 11 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@f8b9974). Learn more about missing BASE report.
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
.../modelCatalog/screens/RegisterCatalogModelForm.tsx 85.50% 10 Missing ⚠️
.../modelCatalog/screens/RegisterCatalogModelPage.tsx 95.45% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4420   +/-   ##
=======================================
  Coverage        ?   82.62%           
=======================================
  Files           ?     1752           
  Lines           ?    36570           
  Branches        ?    10804           
=======================================
  Hits            ?    30216           
  Misses          ?     6354           
  Partials        ?        0           
Files with missing lines Coverage Δ
...tend/src/pages/modelCatalog/ModelCatalogRoutes.tsx 100.00% <ø> (ø)
...stry/screens/RegisterModel/useRegisterModelData.ts 100.00% <100.00%> (ø)
.../modelCatalog/screens/RegisterCatalogModelPage.tsx 95.45% <95.45%> (ø)
.../modelCatalog/screens/RegisterCatalogModelForm.tsx 85.50% <85.50%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f8b9974...77ea719. Read the comment docs.

🚀 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
None yet
Development

Successfully merging this pull request may close these issues.

1 participant