Skip to content

Conversation

@dodo920306
Copy link
Contributor

Let's face it: the current state of this project’s code is not so good.

Contributions over time have lacked consistency, leading to duplicated implementations and a fragmented structure that makes maintenance and development difficult.

The combination of Python, Django, and object-oriented design has introduced unnecessary complexity, and without long-term technical stewardship, the project has become hard to extend.

Another pressing issue is the number of long-standing bugs. For a project that has been in existence for over six years, there remain issues that ideally should have been addressed very early on. Many of these are not superficial problems that tools or automated testing could easily detect, but deeper logical flaws that only become evident when the affected code paths are used.

Additionally, it seems that the project has not fully embraced the design principles of Django REST Framework (DRF). For example, serializers are often used only for traffic handling, while much of the core business logic resides in views.py, which goes against DRF’s intended design practices.

To summary, a refactor is inevitable, and to make sure I’m not just another person who criticizes without acting, I’ll do it myself.

@dodo920306 dodo920306 closed this Aug 29, 2025
@dodo920306 dodo920306 deleted the task/the-refactoring branch August 29, 2025 11:22
@dodo920306 dodo920306 restored the task/the-refactoring branch August 29, 2025 11:22
@dodo920306 dodo920306 reopened this Aug 29, 2025
@dodo920306 dodo920306 force-pushed the task/the-refactoring branch from b2553e7 to 4a3123e Compare October 6, 2025 07:52
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]>
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]>
@yeasy
Copy link
Contributor

yeasy commented Nov 20, 2025

@YoungHypo suggest we create a new branch for this refactor work.

@dodo920306 dodo920306 changed the base branch from main to lab/kirin-refactor November 21, 2025 07:05
@dodo920306
Copy link
Contributor Author

dodo920306 commented Nov 21, 2025

@YoungHypo suggest we create a new branch for this refactor work.

I just realized that I myself can also create a new branch in this repo. Therefore, I created a new branch called lab/kirin-refactor as a new target for this PR.

Feel free to suggest another branch name.

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

2 participants