Skip to content
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

feat: fetch data from integrations API and show connected apps #1143

Open
wants to merge 1 commit into
base: connected-badge-ui
Choose a base branch
from

Conversation

JustARatherRidiculouslyLongUsername
Copy link
Contributor

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername commented Jan 9, 2025

Clickup

https://app.clickup.com/t/86cxhewex

Summary by CodeRabbit

Release Notes

  • New Features

    • Added integration management functionality
    • Introduced dynamic connection status display for integration applications
  • Improvements

    • Enhanced user interface for integration landing page
    • Added ability to track and display connected applications
  • Technical Updates

    • Implemented new service for handling integration data
    • Added type definitions for integration-related entities

The updates provide a more dynamic and informative experience for managing integrations, with real-time connection status tracking.

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

This pull request introduces a new IntegrationsService and related functionality for managing integration applications. The changes include adding a new Integration type model, creating a service to fetch integrations, updating the landing page component to dynamically display connection status, and adding corresponding test infrastructure. The implementation focuses on enhancing the integration management capabilities by providing a structured approach to retrieving and displaying connected applications.

Changes

File Change Summary
src/app/core/models/integrations/integrations.model.ts Added new Integration type with properties like id, org_id, tpa_name, is_active, etc.
src/app/core/services/common/integrations.service.ts Created new IntegrationsService with getIntegrations() method to fetch integration data
src/app/core/services/common/integrations.service.spec.ts Added initial test suite for IntegrationsService
src/app/integrations/landing-v2/landing-v2.component.ts Added methods to manage connected apps, integrated IntegrationsService
src/app/integrations/landing-v2/landing-v2.component.html Updated to conditionally render connection status using isAppConnected method

Sequence Diagram

sequenceDiagram
    participant Component as LandingV2Component
    participant Service as IntegrationsService
    participant API as ApiService

    Component->>Service: getIntegrations()
    Service->>API: GET /integrations/
    API-->>Service: Return Integration[] 
    Service-->>Component: Provide Integration Data
    Component->>Component: Process Connected Apps
    Component->>Component: Update UI with Connection Status
Loading

Suggested labels

size/XS

Suggested reviewers

  • ashwin1111
  • anishfyle
  • DhaaraniCIT

Poem

🐰 Integrations hop and dance,
Connections bloom with every glance,
Services weave their magic spell,
Connected apps now ring their bell!
A rabbit's code, both swift and bright! 🌟

Finishing Touches

  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the size/M Medium PR label Jan 9, 2025
Copy link

github-actions bot commented Jan 9, 2025

Unit Test Coverage % values
Statements 33.04% ( 4125 / 12482 )
Branches 26.45% ( 1180 / 4460 )
Functions 25.63% ( 894 / 3487 )
Lines 33.22% ( 4059 / 12215 )

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Nitpick comments (6)
src/app/core/services/common/integrations.service.ts (1)

12-17: Consider moving base URL configuration to a more appropriate location

Setting the base URL in the constructor couples the service initialization with side effects. Consider moving this configuration to a separate initialization method or to a higher level in the application.

src/app/core/models/integrations/integrations.model.ts (1)

3-12: Add JSDoc documentation and consider more specific types

The Integration type would benefit from documentation explaining each field's purpose. Also, consider using more specific types for certain fields.

+/**
+ * Represents an integration between Fyle and a third-party application
+ */
 export type Integration = {
   id: number;
   org_id: string;
   org_name: string;
   tpa_id: string;
   tpa_name: string;
-  type: string;
+  type: 'ACCOUNTING' | 'HRMS' | 'TRAVEL';
   is_active: boolean;
   is_beta: boolean;
 }
src/app/integrations/landing-v2/landing-v2.component.ts (1)

78-89: Consider moving integration mappings to a configuration file

The tpaNameToIntegrationKeyMap contains hard-coded strings that would be better maintained in a separate configuration file. This would improve maintainability and reduce the risk of typos.

src/app/integrations/landing-v2/landing-v2.component.html (3)

44-50: Enhance accessibility for connection status indicators

While the UI changes effectively show connection status, consider improving accessibility by:

  1. Adding ARIA labels to indicate connection status
  2. Ensuring the Connect buttons have proper focus states
  3. Adding proper role attributes to the status badges

Example implementation for one block:

-<button class="btn-connect">Connect</button>
+<button 
+  class="btn-connect" 
+  aria-label="Connect to NetSuite"
+>Connect</button>

-<app-badge text="Connected" [theme]="ThemeOption.SUCCESS"></app-badge>
+<app-badge 
+  text="Connected" 
+  [theme]="ThemeOption.SUCCESS"
+  role="status" 
+  aria-label="NetSuite is connected"
+></app-badge>

Also applies to: 64-70, 83-89, 102-108, 121-127, 141-147, 159-165, 178-184, 198-204, 219-225


46-48: Consider caching connection status checks

The template calls isAppConnected() multiple times for each integration. Consider caching these results to optimize performance:

  1. Create a map of connection statuses in the component
private connectionStatusMap = new Map<string, boolean>();

ngOnInit() {
  this.storeConnectedApps().subscribe(() => {
    // Cache connection status for each app
    ['NETSUITE', 'INTACCT', 'QBO', /* ... */].forEach(app => {
      this.connectionStatusMap.set(app, this.isAppConnected(app));
    });
  });
}
  1. Use the cached values in template:
-@if (isAppConnected('NETSUITE')) {
+@if (connectionStatusMap.get('NETSUITE')) {

Also applies to: 66-67, 85-86, 104-105, 123-124, 143-144, 161-162, 180-181, 200-201, 221-222


Line range hint 173-175: Simplify beta badge management

The current implementation uses separate arrays (orgsToHideSage300BetaBadge, orgsToHideBusinessCentralBetaBadge) to manage beta badge visibility. Consider a more maintainable approach:

  1. Define a single configuration object:
interface IntegrationConfig {
  id: string;
  name: string;
  type: 'Accounting' | 'HRMS' | 'Travel';
  isBeta?: boolean;
  betaExcludedOrgs?: string[];
}

const INTEGRATIONS_CONFIG: IntegrationConfig[] = [
  {
    id: 'SAGE300',
    name: 'Sage 300 CRE',
    type: 'Accounting',
    isBeta: true,
    betaExcludedOrgs: ['org1', 'org2']
  },
  // ... other integrations
];
  1. Create a helper method:
shouldShowBetaBadge(integrationId: string): boolean {
  const config = INTEGRATIONS_CONFIG.find(i => i.id === integrationId);
  return config?.isBeta && !config?.betaExcludedOrgs?.includes(this.org.fyle_org_id);
}
  1. Update template:
-<app-badge *ngIf="!orgsToHideSage300BetaBadge.includes(org.fyle_org_id)"
+<app-badge *ngIf="shouldShowBetaBadge('SAGE300')"
   [theme]="ThemeOption.DARK"
   text="Beta">
 </app-badge>

Also applies to: 191-194

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b567e9 and 292fb65.

📒 Files selected for processing (5)
  • src/app/core/models/integrations/integrations.model.ts (1 hunks)
  • src/app/core/services/common/integrations.service.spec.ts (1 hunks)
  • src/app/core/services/common/integrations.service.ts (1 hunks)
  • src/app/integrations/landing-v2/landing-v2.component.html (10 hunks)
  • src/app/integrations/landing-v2/landing-v2.component.ts (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: unit-test

Comment on lines +13 to +15
it('should be created', () => {
expect(service).toBeTruthy();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add test coverage for getIntegrations method

The test suite only verifies service creation. Add tests for the getIntegrations method to ensure it correctly fetches and returns integration data.

it('should fetch integrations', (done) => {
  const mockIntegrations = [
    {
      id: 1,
      org_id: 'org1',
      org_name: 'Org 1',
      tpa_id: 'tpa1',
      tpa_name: 'TPA 1',
      type: 'type1',
      is_active: true,
      is_beta: false
    }
  ];
  
  const apiService = TestBed.inject(ApiService) as jasmine.SpyObj<ApiService>;
  apiService.get.and.returnValue(of(mockIntegrations));

  service.getIntegrations().subscribe(integrations => {
    expect(apiService.get).toHaveBeenCalledWith('/integrations/', {});
    expect(integrations).toEqual(mockIntegrations);
    done();
  });
});


import { IntegrationsService } from './integrations.service';

xdescribe('IntegrationsService', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Enable the test suite by removing the 'x' prefix

The test suite is currently disabled with xdescribe. Enable it by changing to describe.

-xdescribe('IntegrationsService', () => {
+describe('IntegrationsService', () => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
xdescribe('IntegrationsService', () => {
describe('IntegrationsService', () => {

Comment on lines +8 to +11
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(IntegrationsService);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing ApiService provider in TestBed configuration

The service depends on ApiService but it's not provided in the testing module.

 beforeEach(() => {
-  TestBed.configureTestingModule({});
+  TestBed.configureTestingModule({
+    providers: [
+      IntegrationsService,
+      {
+        provide: ApiService,
+        useValue: jasmine.createSpyObj('ApiService', ['get'])
+      }
+    ]
+  });
   service = TestBed.inject(IntegrationsService);
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(IntegrationsService);
});
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
IntegrationsService,
{
provide: ApiService,
useValue: jasmine.createSpyObj('ApiService', ['get'])
}
]
});
service = TestBed.inject(IntegrationsService);
});

Comment on lines +19 to +21
getIntegrations(): Observable<Integration[]> {
return this.apiService.get(`/integrations/`, {});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for API requests

The getIntegrations method should handle potential API errors to prevent them from propagating to components.

 getIntegrations(): Observable<Integration[]> {
-  return this.apiService.get(`/integrations/`, {});
+  return this.apiService.get(`/integrations/`, {}).pipe(
+    catchError(error => {
+      console.error('Error fetching integrations:', error);
+      return throwError(() => new Error('Failed to fetch integrations'));
+    })
+  );
 }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +166 to +168
isAppConnected(appKey: IntegrationAppKey) {
return this.connectedApps.includes(appKey);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null check for connectedApps array

The isAppConnected method might be called before connectedApps is initialized, potentially causing runtime errors.

 isAppConnected(appKey: IntegrationAppKey) {
-  return this.connectedApps.includes(appKey);
+  return this.connectedApps?.includes(appKey) ?? false;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
isAppConnected(appKey: IntegrationAppKey) {
return this.connectedApps.includes(appKey);
}
isAppConnected(appKey: IntegrationAppKey) {
return this.connectedApps?.includes(appKey) ?? false;
}

Comment on lines +239 to +246
private storeConnectedApps() {
this.integrationService.getIntegrations().subscribe(integrations => {
const tpaNames = integrations.map(integration => integration.tpa_name);
const connectedApps = tpaNames.map(tpaName => this.tpaNameToIntegrationKeyMap[tpaName]);

this.connectedApps = connectedApps;
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling and loading state for integration fetching

The storeConnectedApps method lacks error handling and doesn't manage loading state. This could lead to silent failures and poor user experience.

+private isLoading = false;
+private error: string | null = null;

 private storeConnectedApps() {
+  this.isLoading = true;
+  this.error = null;
   this.integrationService.getIntegrations().subscribe({
-    integrations => {
+    next: (integrations) => {
       const tpaNames = integrations.map(integration => integration.tpa_name);
       const connectedApps = tpaNames.map(tpaName => this.tpaNameToIntegrationKeyMap[tpaName]);
       this.connectedApps = connectedApps;
+      this.isLoading = false;
+    },
+    error: (error) => {
+      console.error('Failed to fetch integrations:', error);
+      this.error = 'Failed to load connected apps';
+      this.isLoading = false;
     }
   });
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private storeConnectedApps() {
this.integrationService.getIntegrations().subscribe(integrations => {
const tpaNames = integrations.map(integration => integration.tpa_name);
const connectedApps = tpaNames.map(tpaName => this.tpaNameToIntegrationKeyMap[tpaName]);
this.connectedApps = connectedApps;
});
}
private isLoading = false;
private error: string | null = null;
private storeConnectedApps() {
this.isLoading = true;
this.error = null;
this.integrationService.getIntegrations().subscribe({
next: (integrations) => {
const tpaNames = integrations.map(integration => integration.tpa_name);
const connectedApps = tpaNames.map(tpaName => this.tpaNameToIntegrationKeyMap[tpaName]);
this.connectedApps = connectedApps;
this.isLoading = false;
},
error: (error) => {
console.error('Failed to fetch integrations:', error);
this.error = 'Failed to load connected apps';
this.isLoading = false;
}
});
}

Comment on lines +46 to +50
@if (isAppConnected('NETSUITE')) {
<app-badge text="Connected" [theme]="ThemeOption.SUCCESS"></app-badge>
} @else {
<button class="btn-connect">Connect</button>
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add loading and error states for connection status

The current implementation doesn't handle loading or error states when checking connection status. Consider adding these states for better user experience:

-@if (isAppConnected('NETSUITE')) {
+@if (isLoading) {
+    <app-spinner size="small"></app-spinner>
+} @else if (connectionError) {
+    <app-badge 
+      text="Check Status" 
+      [theme]="ThemeOption.WARNING"
+      (click)="retryConnectionCheck('NETSUITE')"
+    ></app-badge>
+} @else if (isAppConnected('NETSUITE')) {
     <app-badge text="Connected" [theme]="ThemeOption.SUCCESS"></app-badge>
 } @else {
     <button class="btn-connect">Connect</button>
 }

Also applies to: 66-70, 85-89, 104-108, 121-127, 141-147, 159-165, 178-184, 198-204, 219-225

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Medium PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants