Skip to content

Conversation

@dodo920306
Copy link
Contributor

Summary

Modernize frontend code architecture by introducing Factory Pattern and converting Class Components to Functional Components.

Changes

New Utilities

  • serviceFactory.js: Provides reusable CRUD operations

    • createCrudService(): Generates standard CRUD methods
    • customRequest(): Wrapper for non-standard API endpoints
    • formDataRequest(): File upload helper
    • blobRequest(): File download helper
  • modelFactory.js: Provides reusable dva model logic

    • createModel(): Generates complete dva model
    • createListEffect(): Handles paginated lists
    • createSimpleEffect(): Generates simple effects
    • commonReducers: Shared reducers
  • hooks/: New reusable React Hooks

    • useTableManagement: Table management
    • useModalForm: Modal form handling
    • useDeleteConfirm: Delete confirmation dialog

Component Refactoring

  • Convert Organization page from Class Component to Functional Component
  • Convert all pages to Functional Components
    • Agent
    • ChainCode
    • Channel
    • Node
    • UserManagement

Remove Network Feature

  • Remove Network-related pages (src/pages/Network/)
  • Remove Network router configuration

Code Reduction

  • Services: Reduced ~87 lines of duplicate code
  • Models: Reduced ~176 lines of duplicate code

Benefits

  • ✅ Consistent API call patterns
  • ✅ Centralized extension point
  • ✅ Better code readability and maintainability
  • ✅ Modern React patterns (Hooks)

Breaking Changes

  • Network feature has been completely removed
  • Page component APIs may have changed

Dependencies


🤖 This PR description was generated with AI assistance (Claude, Anthropic).

Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: KIRIN.CHU 朱祐麟 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
Move inside api engine.

Signed-off-by: dodo920306 <[email protected]>
Signed-off-by: dodo920306 <[email protected]>
All dockerfiles should be directly placed inside with their
codes. By this way, it reduces the effort to pay attention
to connect them with their true codebase and context.

Signed-off-by: dodo920306 <[email protected]>
Since the login page doesn't include the `GlobalHeader`, the icon
of the language selection doesn't include the padding like pages
after login.

Signed-off-by: dodo920306 <[email protected]>
The peers dropdown in the chaincode form should be
labelled as "peers" directly instead of "Please select
peers" which should be the warning message.

Signed-off-by: dodo920306 <[email protected]>
The directory contains organizational MSPs should be ignored
by Git.

Signed-off-by: dodo920306 <[email protected]>
To block duplicate package IDs, chaincodes package IDs
will be set when they're created.

Signed-off-by: dodo920306 <[email protected]>
- Add src/utils/serviceFactory.js with reusable utilities:
  - createCrudService(): generates standard CRUD methods for REST resources
  - customRequest(): wrapper for non-standard API endpoints
  - formDataRequest(): helper for file uploads
  - blobRequest(): helper for file downloads

- Refactor all service files to use the new factory:
  - agent.js: use createCrudService, remove duplicate applyAgent/createAgent
  - network.js: use createCrudService
  - node.js: use createCrudService + custom helpers
  - organization.js: use createCrudService, fix getOrganization URL path
  - channel.js: use createCrudService
  - chaincode.js: use customRequest + formDataRequest
  - user.js: use createCrudService

This reduces ~87 lines of duplicate code and provides:
- Consistent API call patterns across all services
- Centralized extension point for future enhancements
- Better code readability and maintainability

---
Generated-by: AI (Claude, Anthropic)
Note: All changes in this commit were generated by AI assistant.

Signed-off-by: dodo920306 <[email protected]>
- Add src/utils/modelFactory.js with reusable utilities:
  - createModel(): generates complete dva model with auto reducers
  - createListEffect(): handles paginated list with consistent logic
  - createSimpleEffect(): generates simple call-and-callback effects
  - commonReducers: shared save reducer
  - createClearReducer(): generates reset reducer from initial state

- Refactor all model files to use the new factory:
  - agent.js: 127 -> 56 lines
  - network.js: 75 -> 28 lines
  - node.js: 140 -> 54 lines
  - organization.js: 97 -> 38 lines
  - channel.js: 73 -> 37 lines
  - chaincode.js: 90 -> 48 lines

This reduces ~176 lines of duplicate code and provides:
- Consistent pagination handling across all models
- Auto-generated save/clear reducers
- Flexible customization for edge cases

---
Generated-by: AI (Claude, Anthropic)

Signed-off-by: dodo920306 <[email protected]>
- Add src/hooks/ directory with custom React hooks:
  - useTableManagement: handles selected rows, pagination, filters
  - useModalForm: handles modal visibility, create/update modes
  - useDeleteConfirm: handles delete confirmation dialog with i18n

These hooks can reduce ~50 lines of boilerplate code per page
when migrating from Class Components to Function Components.

---
Generated-by: AI (Claude, Anthropic)

Signed-off-by: dodo920306 <[email protected]>
New models generated by the factory now will fail to be
loaded since they're not static. Thus, they will be forced
to be loaded after the DVA app is ready.

Signed-off-by: dodo920306 <[email protected]>
With the introduction of Hooks in React 16.8, function components have
become the preferred way to write React components. They are simpler,
more readable, and provide more powerful patterns for managing state
and side effects compared to class components.

Signed-off-by: dodo920306 <[email protected]>
With the introduction of Hooks in React 16.8, function components have
become the preferred way to write React components. They are simpler,
more readable, and provide more powerful patterns for managing state
and side effects compared to class components.

Signed-off-by: dodo920306 <[email protected]>
Network is deprecated.

Signed-off-by: dodo920306 <[email protected]>
Network is deprecated.

Signed-off-by: dodo920306 <[email protected]>
@dodo920306
Copy link
Contributor Author

This is draft only because #748 hasn't been merged yet.

@dodo920306 dodo920306 mentioned this pull request Dec 14, 2025
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