refactor: extract sub-components and custom hooks from UpdateDSLModal and Metadata components#32045
refactor: extract sub-components and custom hooks from UpdateDSLModal and Metadata components#32045CodingOnStar wants to merge 3 commits intomainfrom
Conversation
- Added VersionMismatchModal component to handle version mismatch scenarios during DSL updates. - Refactored UpdateDSLModal to utilize a custom hook (useUpdateDSLModal) for improved state management and logic separation. - Updated tests for both UpdateDSLModal and the new VersionMismatchModal to ensure proper functionality and user interactions. - Removed unused code and dependencies from UpdateDSLModal to streamline the component.
- Refactored the Metadata component to improve readability and maintainability by splitting it into smaller sub-components: FieldInfo, DocTypeSelector, and MetadataFieldList. - Introduced a new hook, useMetadataState, to manage metadata-related state and logic. - Updated tests to cover new component structure and ensure functionality. - Removed unused imports and code to streamline the component.
Summary of ChangesHello @CodingOnStar, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on a significant refactoring effort across two key frontend components: Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This is an excellent refactoring effort. You've successfully extracted complex logic from the UpdateDSLModal and Metadata components into custom hooks and smaller, more manageable sub-components. This greatly reduces complexity, improves readability, and enhances testability, as demonstrated by the comprehensive new test files. The code is much cleaner and more maintainable. I have a few suggestions to further improve the code.
web/app/components/datasets/documents/detail/metadata/hooks/use-metadata-state.ts
Outdated
Show resolved
Hide resolved
web/app/components/datasets/documents/detail/metadata/components/doc-type-selector.tsx
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This pull request refactors two large components (UpdateDSLModal and Metadata) by extracting custom hooks and sub-components to improve maintainability and reduce complexity.
Changes:
- UpdateDSLModal refactoring: Extracted business logic into
useUpdateDSLModalcustom hook and split the version mismatch dialog into a standaloneVersionMismatchModalcomponent, reducing main component from 284 lines (complexity 53) to 112 lines (complexity 0) - Metadata refactoring: Split UI components (
FieldInfo,DocTypeSelector,MetadataFieldList) into a components subdirectory and extracted state management intouse-metadata-state.tshook, streamlining main component from 425 lines to 127 lines - Test coverage: Added comprehensive unit tests for all newly extracted hooks and components (+838 lines of test code), achieving high coverage (98% statements / 97.95% lines / 100% functions for use-metadata-state)
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| web/eslint-suppressions.json | Removed ESLint suppressions for the refactored files, indicating code quality improvements |
| web/app/components/rag-pipeline/hooks/use-update-dsl-modal.ts | New custom hook extracting UpdateDSLModal business logic |
| web/app/components/rag-pipeline/hooks/use-update-dsl-modal.spec.ts | Comprehensive test suite for the hook (551 lines) |
| web/app/components/rag-pipeline/components/version-mismatch-modal.tsx | Extracted version mismatch modal component |
| web/app/components/rag-pipeline/components/version-mismatch-modal.spec.tsx | Test suite for the modal component |
| web/app/components/rag-pipeline/components/update-dsl-modal.tsx | Refactored main component using extracted hook and component |
| web/app/components/rag-pipeline/components/update-dsl-modal.spec.tsx | Updated tests with cleanup simplification |
| web/app/components/datasets/documents/detail/metadata/index.tsx | Refactored main Metadata component |
| web/app/components/datasets/documents/detail/metadata/index.spec.tsx | Enhanced tests with additional hook coverage tests |
| web/app/components/datasets/documents/detail/metadata/hooks/use-metadata-state.ts | New custom hook for metadata state management |
| web/app/components/datasets/documents/detail/metadata/components/field-info.tsx | Extracted FieldInfo component |
| web/app/components/datasets/documents/detail/metadata/components/doc-type-selector.tsx | Extracted DocTypeSelector and DocumentTypeDisplay components |
| web/app/components/datasets/documents/detail/metadata/components/metadata-field-list.tsx | Extracted MetadataFieldList component |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Updated the function in to safely handle potential undefined values in . - Modified the hook to correctly type the event emitter, enhancing type safety and clarity. - Adjusted the to support a new type for better event handling.
Summary
Checklist
make lintandmake type-check(backend) andcd web && npx lint-staged(frontend) to appease the lint gods