Skip to content

refactor: restructure DatasetCard component for improved readability and maintainability#30617

Merged
CodingOnStar merged 3 commits intomainfrom
refactor/dataset-card
Jan 6, 2026
Merged

refactor: restructure DatasetCard component for improved readability and maintainability#30617
CodingOnStar merged 3 commits intomainfrom
refactor/dataset-card

Conversation

@CodingOnStar
Copy link
Contributor

Summary

refactor: restructure DatasetCard component for improved readability and maintainability

  • Split DatasetCard into multiple subcomponents: CornerLabels, DatasetCardHeader, DatasetCardFooter, DatasetCardModals, Description, TagArea, and OperationsPopover.
  • Introduced a custom hook, useDatasetCardState, to manage state and modal logic.
  • Enhanced tag management and modal handling for renaming and deletion.
  • Improved code organization and reduced complexity in the main DatasetCard component.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods
…and maintainability - Split DatasetCard into multiple subcomponents: CornerLabels, DatasetCardHeader, DatasetCardFooter, DatasetCardModals, Description, TagArea, and OperationsPopover. - Introduced a custom hook, useDatasetCardState, to manage state and modal logic. - Enhanced tag management and modal handling for renaming and deletion. - Improved code organization and reduced complexity in the main DatasetCard component.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 of the DatasetCard component. The primary goal is to improve the component's structure, readability, and maintainability by breaking it down into smaller, more focused subcomponents and centralizing its state management logic using a custom React hook. This change streamlines the component's responsibilities and enhances its modularity.

Highlights

  • Component Decomposition: The DatasetCard component has been broken down into several smaller, specialized subcomponents: CornerLabels, DatasetCardHeader, DatasetCardFooter, DatasetCardModals, Description, TagArea, and OperationsPopover.
  • Centralized State Management: A new custom React hook, useDatasetCardState, has been introduced to centralize and manage the state and modal logic previously scattered within the main DatasetCard component.
  • Improved Modals and Tag Handling: The handling of tags and various modals (like rename and delete confirmation) has been enhanced and encapsulated within the new subcomponents and custom hook, leading to a cleaner implementation.
  • Code Organization and Maintainability: The refactoring significantly improves the overall code organization and reduces the complexity of the main DatasetCard component, making it more readable and easier to maintain.

🧠 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.

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is an excellent refactoring of the DatasetCard component. By splitting it into smaller, focused subcomponents and extracting state management into the useDatasetCardState custom hook, you've significantly improved the code's readability, maintainability, and organization. The new structure is much cleaner and follows React best practices. I've left a few suggestions to further enhance code clarity and robustness. Great work on this cleanup!

…DatasetCardFooter - Updated error handling in useDatasetCardState to differentiate between Response and Error types for better clarity. - Removed redundant document count checks in DatasetCardFooter for cleaner code and improved readability.
@CodingOnStar CodingOnStar marked this pull request as ready for review January 6, 2026 08:31
Copilot AI review requested due to automatic review settings January 6, 2026 08:31
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jan 6, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the DatasetCard component to improve code organization and maintainability by breaking it down into smaller, focused subcomponents and extracting state management logic into a custom hook.

  • Split the monolithic component into 7 focused subcomponents for better separation of concerns
  • Introduced useDatasetCardState hook to centralize state and modal management
  • Created new service hooks (useCheckDatasetUsage, useDeleteDataset) using React Query for better data fetching patterns

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
web/service/use-dataset-card.ts New service file with React Query mutations for dataset operations
web/app/components/datasets/list/dataset-card/index.tsx Refactored main component to compose subcomponents and use the new hook
web/app/components/datasets/list/dataset-card/hooks/use-dataset-card-state.ts New custom hook managing state, modals, and dataset operations
web/app/components/datasets/list/dataset-card/components/tag-area.tsx Extracted tag selector area into standalone component
web/app/components/datasets/list/dataset-card/components/operations-popover.tsx Extracted operations menu popover into standalone component
web/app/components/datasets/list/dataset-card/components/description.tsx Extracted description display into standalone component
web/app/components/datasets/list/dataset-card/components/dataset-card-modals.tsx Extracted modal rendering logic into standalone component
web/app/components/datasets/list/dataset-card/components/dataset-card-header.tsx Extracted header section with icon and metadata into standalone component
web/app/components/datasets/list/dataset-card/components/dataset-card-footer.tsx Extracted footer with document counts and timestamps into standalone component
web/app/components/datasets/list/dataset-card/components/corner-labels.tsx Extracted corner labels (unavailable/pipeline) into standalone component

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ved tag management - Modified handleExportPipeline to accept an optional boolean parameter. - Removed the custom useSyncTags hook and implemented useEffect for syncing tags directly in useDatasetCardState, enhancing clarity and reducing complexity.
Copy link
Member

@WTW0313 WTW0313 left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 6, 2026
@CodingOnStar CodingOnStar merged commit 9b12804 into main Jan 6, 2026
14 checks passed
@CodingOnStar CodingOnStar deleted the refactor/dataset-card branch January 6, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.

3 participants