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: UI for the new "Conencted" badge #1144

Merged

Conversation

JustARatherRidiculouslyLongUsername
Copy link
Contributor

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername commented Jan 9, 2025

Clickup

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

Summary by CodeRabbit

  • New Features

    • Added a new SUCCESS theme option to the existing theme enum.
    • Introduced a new .theme-success CSS class for badges with success styling.
    • Added a new IntegrationsService for managing integration data retrieval.
    • Enhanced the LandingV2Component to display connection status for various applications.
  • Bug Fixes

    • Updated the routing path for the LandingV2Component to use underscores instead of hyphens.
  • Tests

    • Introduced a new test suite for the IntegrationsService.

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

The pull request introduces a new SUCCESS value to the ThemeOption enum and adds a corresponding .theme-success CSS class in the badge component's stylesheet. Additionally, a new IntegrationsService is created, which includes methods for retrieving integration data. The LandingV2Component is updated to utilize this service and manage connected applications more effectively. The routing configuration for the LandingV2Component is also modified.

Changes

File Change Summary
src/app/core/models/enum/enum.model.ts Added SUCCESS = 'success' to ThemeOption enum
src/app/shared/components/core/badge/badge.component.scss Introduced .theme-success CSS class with Tailwind utility classes for success theme styling
src/app/core/services/common/integrations.service.ts Added IntegrationsService class with getIntegrations method
src/app/core/services/common/integrations.service.spec.ts Introduced test suite for IntegrationsService
src/app/integrations/integrations-routing.module.ts Modified path for LandingV2Component from landing-v2 to landing_v2
src/app/integrations/landing-v2/landing-v2.component.html Updated HTML structure for connection buttons and application logos
src/app/integrations/landing-v2/landing-v2.component.ts Added methods and properties for managing connected applications and integration keys

Possibly related PRs

Suggested labels

deploy

Suggested reviewers

  • ashwin1111

Poem

🐰 A rabbit's tale of theme delight,
Success now shines so crisp and bright!
An enum expanded, styles so keen,
With badges that make victory gleam 🏆
Hop-hop hooray for color's might! 🌈

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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

* feat: fetch data from integrations API and show connected apps

* fix: update route name and keep `exposeC1Apps` (#1145)

* fix: update route name and keep `exposeC1Apps`

* fix: use new logos in landing-v2 only

Use original images everywhere else.

* fix: incorrect URL for `/integrations` call and rendering errors (#1149)
@github-actions github-actions bot added size/M Medium PR and removed size/XS Extra Small PR labels Jan 17, 2025
Copy link

Unit Test Coverage % values
Statements 33.02% ( 4122 / 12483 )
Branches 26.43% ( 1179 / 4460 )
Functions 25.6% ( 893 / 3487 )
Lines 33.2% ( 4056 / 12216 )

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: 4

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

12-16: Remove empty constructor block.

The empty constructor block can be removed since TypeScript automatically creates these parameters as class properties when using the access modifier in the constructor parameters.

 export class IntegrationsService {
-  constructor(
-    private apiService: ApiService,
-    private helper: HelperService
-  ) {
-  }
+  constructor(
+    private apiService: ApiService,
+    private helper: HelperService
+  ) {}
src/app/core/models/integrations/integrations.model.ts (1)

3-12: Add JSDoc documentation for Integration type.

The Integration type properties need documentation for better clarity and maintainability.

+/**
+ * Represents an integration between the application and a third-party service
+ */
 export type Integration = {
+  /** Unique identifier for the integration */
   id: number;
+  /** Organization identifier */
   org_id: string;
+  /** Organization display name */
   org_name: string;
+  /** Third-party application identifier */
   tpa_id: string;
+  /** Third-party application display name */
   tpa_name: string;
+  /** Type of integration (e.g., 'accounting', 'hrms') */
   type: string;
+  /** Whether the integration is currently active */
   is_active: boolean;
+  /** Whether the integration is in beta testing phase */
   is_beta: boolean;
 }
src/app/integrations/integrations-routing.module.ts (1)

17-19: Maintain consistent route naming convention.

The route paths use inconsistent naming conventions:

  • Some routes use hyphens: bamboo-hr, business-central, qbd-direct
  • Others use underscores: landing_v2

Consider standardizing to either hyphens or underscores across all routes.

-        path: 'landing_v2',
+        path: 'landing-v2',
         component: LandingV2Component
src/app/integrations/landing-v2/landing-v2.component.ts (1)

168-170: Remove unnecessary optional chaining.

If we initialize the connectedApps array as suggested earlier, the optional chaining operator isn't needed.

-    return this.connectedApps?.includes(appKey);
+    return this.connectedApps.includes(appKey);
src/app/integrations/landing-v2/landing-v2.component.html (1)

46-50: Consider extracting the connection status display into a reusable component.

The connection status display pattern is repeated across all integration cards. This could be extracted into a reusable component to improve maintainability and reduce duplication.

Create a new component IntegrationConnectionStatus:

@Component({
  selector: 'app-integration-connection-status',
  template: `
    <app-badge *ngIf="isConnected" text="Connected" [theme]="ThemeOption.SUCCESS"></app-badge>
    <button *ngIf="!isConnected" class="btn-connect">Connect</button>
  `
})
export class IntegrationConnectionStatus {
  @Input() isConnected: boolean;
  ThemeOption = ThemeOption;
}

Then simplify the usage in the template:

-@if (isAppConnected('NETSUITE')) {
-    <app-badge text="Connected" [theme]="ThemeOption.SUCCESS"></app-badge>
-} @else {
-    <button class="btn-connect">Connect</button>
-}
+<app-integration-connection-status [isConnected]="isAppConnected('NETSUITE')">
+</app-integration-connection-status>

Also applies to: 66-70, 85-89, 104-108, 123-127, 143-147, 161-165, 180-184, 200-204, 221-225

📜 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 be16dd3.

⛔ Files ignored due to path filters (6)
  • src/assets/logos/intacct-logo-new.png is excluded by !**/*.png
  • src/assets/logos/intacct-logo.png is excluded by !**/*.png
  • src/assets/logos/netsuite-logo-new.png is excluded by !**/*.png
  • src/assets/logos/netsuite-logo.png is excluded by !**/*.png
  • src/assets/logos/xero-logo-new.png is excluded by !**/*.png
  • src/assets/logos/xero-logo.png is excluded by !**/*.png
📒 Files selected for processing (6)
  • 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/integrations-routing.module.ts (1 hunks)
  • src/app/integrations/landing-v2/landing-v2.component.html (11 hunks)
  • src/app/integrations/landing-v2/landing-v2.component.ts (6 hunks)
🔇 Additional comments (4)
src/app/integrations/landing-v2/landing-v2.component.ts (2)

80-91: LGTM! Well-structured integration mapping.

The mapping is comprehensive, type-safe, and immutable. Good use of TypeScript's Record type and readonly modifier.


250-253: LGTM! Proper initialization sequence.

The component correctly initializes both the login watcher and connected apps state.

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

Line range hint 15-35: LGTM! Clean implementation of conditional tab rendering.

The tabs are properly controlled by the exposeC1Apps flag and maintain consistent styling.


Line range hint 37-39: LGTM! Well-structured responsive grid layout.

The grid layout is properly responsive with appropriate breakpoints for different screen sizes.

Comment on lines +5 to +16
xdescribe('IntegrationsService', () => {
let service: IntegrationsService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(IntegrationsService);
});

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

Enable tests and add coverage for getIntegrations method.

The test suite has the following issues:

  1. Tests are disabled with xdescribe
  2. Missing test coverage for getIntegrations method
  3. No error handling tests
  4. No API response mocking

Here's how to improve the test coverage:

-xdescribe('IntegrationsService', () => {
+describe('IntegrationsService', () => {
   let service: IntegrationsService;
+  let apiService: jasmine.SpyObj<ApiService>;
+  let helperService: jasmine.SpyObj<HelperService>;
 
   beforeEach(() => {
+    const apiSpy = jasmine.createSpyObj('ApiService', ['get']);
+    const helperSpy = jasmine.createSpyObj('HelperService', ['setBaseApiURL']);
     TestBed.configureTestingModule({
-      {}
+      providers: [
+        IntegrationsService,
+        { provide: ApiService, useValue: apiSpy },
+        { provide: HelperService, useValue: helperSpy }
+      ]
     });
     service = TestBed.inject(IntegrationsService);
+    apiService = TestBed.inject(ApiService) as jasmine.SpyObj<ApiService>;
+    helperService = TestBed.inject(HelperService) as jasmine.SpyObj<HelperService>;
   });
 
   it('should be created', () => {
     expect(service).toBeTruthy();
   });
+
+  describe('getIntegrations', () => {
+    it('should set base URL and return integrations', (done) => {
+      const mockIntegrations: Integration[] = [
+        {
+          id: 1,
+          org_id: 'org1',
+          org_name: 'Org 1',
+          tpa_id: 'tpa1',
+          tpa_name: 'TPA 1',
+          type: 'type1',
+          is_active: true,
+          is_beta: false
+        }
+      ];
+
+      helperService.setBaseApiURL.and.returnValue(undefined);
+      apiService.get.and.returnValue(of(mockIntegrations));
+
+      service.getIntegrations().subscribe({
+        next: (integrations) => {
+          expect(helperService.setBaseApiURL).toHaveBeenCalledWith(AppUrl.INTEGRATION);
+          expect(apiService.get).toHaveBeenCalledWith('/integrations/', {});
+          expect(integrations).toEqual(mockIntegrations);
+          done();
+        },
+        error: done.fail
+      });
+    });
+
+    it('should handle API errors', (done) => {
+      const errorResponse = new HttpErrorResponse({
+        error: 'test 404 error',
+        status: 404,
+        statusText: 'Not Found'
+      });
+
+      helperService.setBaseApiURL.and.returnValue(undefined);
+      apiService.get.and.returnValue(throwError(() => errorResponse));
+
+      service.getIntegrations().subscribe({
+        next: () => done.fail('should have failed'),
+        error: (error) => {
+          expect(error.status).toBe(404);
+          done();
+        }
+      });
+    });
+  });
 });

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

Comment on lines +18 to +21
getIntegrations(): Observable<Integration[]> {
this.helper.setBaseApiURL(AppUrl.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 and retry logic.

The getIntegrations method should:

  1. Handle API errors gracefully
  2. Implement retry logic for transient failures
  3. Consider caching the results to improve performance
 getIntegrations(): Observable<Integration[]> {
   this.helper.setBaseApiURL(AppUrl.INTEGRATION);
-  return this.apiService.get(`/integrations/`, {});
+  return this.apiService.get<Integration[]>('/integrations/', {}).pipe(
+    retry({
+      count: 3,
+      delay: (error, retryCount) => {
+        if (error.status === 404) {
+          return EMPTY;
+        }
+        return timer(1000 * retryCount);
+      }
+    }),
+    catchError((error: HttpErrorResponse) => {
+      console.error('Error fetching integrations:', error);
+      return throwError(() => error);
+    })
+  );
 }
📝 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
getIntegrations(): Observable<Integration[]> {
this.helper.setBaseApiURL(AppUrl.INTEGRATION);
return this.apiService.get(`/integrations/`, {});
}
getIntegrations(): Observable<Integration[]> {
this.helper.setBaseApiURL(AppUrl.INTEGRATION);
return this.apiService.get<Integration[]>('/integrations/', {}).pipe(
retry({
count: 3,
delay: (error, retryCount) => {
if (error.status === 404) {
return EMPTY;
}
return timer(1000 * retryCount);
}
}),
catchError((error: HttpErrorResponse) => {
console.error('Error fetching integrations:', error);
return throwError(() => error);
})
);
}

Comment on lines +241 to +248
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.

⚠️ Potential issue

Add error handling and cleanup subscription.

The subscription to getIntegrations() should handle errors and be cleaned up to prevent memory leaks.

+  private destroy$ = new Subject<void>();

   private storeConnectedApps() {
-    this.integrationService.getIntegrations().subscribe(integrations => {
+    this.integrationService.getIntegrations().pipe(
+      takeUntil(this.destroy$),
+      catchError(error => {
+        console.error('Failed to fetch integrations:', error);
+        return of([]);
+      })
+    ).subscribe(integrations => {
       const tpaNames = integrations.map(integration => integration.tpa_name);
       const connectedApps = tpaNames.map(tpaName => this.tpaNameToIntegrationKeyMap[tpaName]);
 
       this.connectedApps = connectedApps;
     });
   }

Don't forget to implement ngOnDestroy:

ngOnDestroy(): void {
  this.destroy$.next();
  this.destroy$.complete();
}

@@ -31,6 +32,10 @@

org: Org = this.orgService.getCachedOrg();

private connectedApps: IntegrationAppKey[];
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

Initialize the connectedApps array to prevent undefined access.

The connectedApps array should be initialized to prevent potential undefined access in the isAppConnected method.

-  private connectedApps: IntegrationAppKey[];
+  private connectedApps: IntegrationAppKey[] = [];
📝 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 connectedApps: IntegrationAppKey[];
private connectedApps: IntegrationAppKey[] = [];

@JustARatherRidiculouslyLongUsername JustARatherRidiculouslyLongUsername merged commit 84ceb24 into logos-and-hover Jan 17, 2025
5 checks passed
JustARatherRidiculouslyLongUsername added a commit that referenced this pull request Jan 17, 2025
* fix: update images

* feat: add CTA and shadow animation on tile hover

* feat: UI for the new "Conencted" badge (#1144)

* feat: UI for the new "Conencted" badge

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

* feat: fetch data from integrations API and show connected apps

* fix: update route name and keep `exposeC1Apps` (#1145)

* fix: update route name and keep `exposeC1Apps`

* fix: use new logos in landing-v2 only

Use original images everywhere else.

* fix: incorrect URL for `/integrations` call and rendering errors (#1149)
JustARatherRidiculouslyLongUsername added a commit that referenced this pull request Jan 17, 2025
* feat: responsive grid layout + new tile layout

* feat: add CTA and shadow animation on tile hover (#1142)

* fix: update images

* feat: add CTA and shadow animation on tile hover

* feat: UI for the new "Conencted" badge (#1144)

* feat: UI for the new "Conencted" badge

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

* feat: fetch data from integrations API and show connected apps

* fix: update route name and keep `exposeC1Apps` (#1145)

* fix: update route name and keep `exposeC1Apps`

* fix: use new logos in landing-v2 only

Use original images everywhere else.

* fix: incorrect URL for `/integrations` call and rendering errors (#1149)
JustARatherRidiculouslyLongUsername added a commit that referenced this pull request Jan 17, 2025
* feat: new app tile structure + remove extra content

* feat: responsive grid layout + new tile layout (#1141)

* feat: responsive grid layout + new tile layout

* feat: add CTA and shadow animation on tile hover (#1142)

* fix: update images

* feat: add CTA and shadow animation on tile hover

* feat: UI for the new "Conencted" badge (#1144)

* feat: UI for the new "Conencted" badge

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

* feat: fetch data from integrations API and show connected apps

* fix: update route name and keep `exposeC1Apps` (#1145)

* fix: update route name and keep `exposeC1Apps`

* fix: use new logos in landing-v2 only

Use original images everywhere else.

* fix: incorrect URL for `/integrations` call and rendering errors (#1149)
JustARatherRidiculouslyLongUsername added a commit that referenced this pull request Jan 17, 2025
* feat: create new landing page and add header and tab switcher

* feat: new app tile structure + remove extra content (#1140)

* feat: new app tile structure + remove extra content

* feat: responsive grid layout + new tile layout (#1141)

* feat: responsive grid layout + new tile layout

* feat: add CTA and shadow animation on tile hover (#1142)

* fix: update images

* feat: add CTA and shadow animation on tile hover

* feat: UI for the new "Conencted" badge (#1144)

* feat: UI for the new "Conencted" badge

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

* feat: fetch data from integrations API and show connected apps

* fix: update route name and keep `exposeC1Apps` (#1145)

* fix: update route name and keep `exposeC1Apps`

* fix: use new logos in landing-v2 only

Use original images everywhere else.

* fix: incorrect URL for `/integrations` call and rendering errors (#1149)
JustARatherRidiculouslyLongUsername added a commit that referenced this pull request Jan 17, 2025
* feat: create new landing page and add header and tab switcher

* feat: new app tile structure + remove extra content (#1140)

* feat: new app tile structure + remove extra content

* feat: responsive grid layout + new tile layout (#1141)

* feat: responsive grid layout + new tile layout

* feat: add CTA and shadow animation on tile hover (#1142)

* fix: update images

* feat: add CTA and shadow animation on tile hover

* feat: UI for the new "Conencted" badge (#1144)

* feat: UI for the new "Conencted" badge

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

* feat: fetch data from integrations API and show connected apps

* fix: update route name and keep `exposeC1Apps` (#1145)

* fix: update route name and keep `exposeC1Apps`

* fix: use new logos in landing-v2 only

Use original images everywhere else.

* fix: incorrect URL for `/integrations` call and rendering errors (#1149)
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