Skip to content

Re-factoring API services #14

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

Merged
merged 7 commits into from
Mar 18, 2025
Merged

Re-factoring API services #14

merged 7 commits into from
Mar 18, 2025

Conversation

shahariaazam
Copy link
Member

@shahariaazam shahariaazam commented Mar 18, 2025

This pull request includes significant refactoring and improvements to the codebase, focusing on updating API endpoints, improving error handling, and enhancing test coverage. The most important changes include the removal of deprecated API calls, the introduction of a new error handling mechanism, and the refactoring of service classes to use updated endpoints.

API Refactoring:

  • Removed deprecated API calls in src/api/index.ts and updated the corresponding service classes to use new endpoints. ([[1]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-764761d79ed791ea154187526b088322dba3bebe94f9d38ab22120554aba77c7L1-L28), [[2]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-9dd13b51c673219aa9d6fb02c8bc1100134172df11c9c69008b0b299c0b3d53fR28-R39), [[3]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-9dd13b51c673219aa9d6fb02c8bc1100134172df11c9c69008b0b299c0b3d53fL47-R58), [[4]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-cd77df0f49406951d1fac5878b9dbaedda26efdcfdf299051c8efa5b820c22fcL10-R10), [[5]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-ebf1d939d609a4816004caf5632789818db419201d7af8b12e6123dcfd0b995dL6-R10))

Error Handling:

  • Introduced a new error handling mechanism using useCallback in ChatContainer.tsx to centralize error notifications. ([[1]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-c0bfccaf03a29a5059f6a47c6dd2cdd194fcb1e06fe8e0e188d700a86204f073R27-R36), [[2]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-c0bfccaf03a29a5059f6a47c6dd2cdd194fcb1e06fe8e0e188d700a86204f073L53-R63), [[3]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-c0bfccaf03a29a5059f6a47c6dd2cdd194fcb1e06fe8e0e188d700a86204f073L71-R73))

Test Coverage:

  • Refactored tests in ChatContainer.test.tsx and ToolsModal.test.tsx to mock the updated service classes and ensure proper test isolation. ([[1]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-5bc04b73d213740634c14cc7f3b8c028d08edba97c1c08197b8ed348a3112d47L29-L35), [[2]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-5bc04b73d213740634c14cc7f3b8c028d08edba97c1c08197b8ed348a3112d47L98-L103), [[3]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-5403659b7ee64a58dcfa7026e4f58e57a731ed7d0cd222e7c4391912bd6d10afL1-R79), [[4]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-5403659b7ee64a58dcfa7026e4f58e57a731ed7d0cd222e7c4391912bd6d10afL74-R93))

Component Updates:

  • Updated ToolsModal.tsx and Sidebar.tsx components to use the refactored service classes for fetching data. ([[1]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-63552adfc136b5745280f1413214afb454e46b6558a54e0ac1a62d3076779256L5-R6), [[2]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-63552adfc136b5745280f1413214afb454e46b6558a54e0ac1a62d3076779256L21-R23), [[3]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-63552adfc136b5745280f1413214afb454e46b6558a54e0ac1a62d3076779256L33), [[4]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-5f3a5cc0c274c553bf7e5a260f594f138c16fd5197e1555cb608f862f0120f1cL4-R9), [[5]](https://github.com/shaharia-lab/mcp-frontend/pull/14/files#diff-5f3a5cc0c274c553bf7e5a260f594f138c16fd5197e1555cb608f862f0120f1cL36-R38))

These changes collectively improve the maintainability, reliability, and testability of the codebase.

Replaced direct API calls with ChatService for consistency and centralized API handling. Updated `getChatHistories` to return a typed response and adjusted `Sidebar` to use the new service implementation. Removed unused `fetchLLMProviders` function from the API module.
The fetchTools function was no longer in use and has been deleted to simplify the codebase. Removing unused code improves maintainability and reduces potential confusion.
Replaced old chat API endpoints with new ones prefixed by /api/v1 for consistency and to align with the updated API structure. This ensures all requests are routed correctly to the new versioned endpoints.
Replaced hardcoded API URL with an environment variable to improve configurability. Removed unused API mocks from ChatContainer tests to simplify and declutter the test setup.
Replaced duplicated error handling logic with a reusable `handleError` function using `useCallback`. This reduces redundancy and improves maintainability by centralizing error notification logic."
@shahariaazam shahariaazam merged commit d25164d into main Mar 18, 2025
3 checks passed
@shahariaazam shahariaazam deleted the improvements branch March 18, 2025 23:19
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