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/Enable overriding Flatfile default loading component #216

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

mattheri
Copy link

@mattheri mattheri commented Oct 30, 2024

Please explain how to summarize this PR for the Changelog:

Right now, with the @flatfile/angular-sdk, it is not possible to replace the default loading spinner in Flatfile. With this PR, a user can assign a TemplateRef to the ISpace['loading'] property and it will correctly show the new loading.

Tell code reviewer how and what to test:

In your HTML, add a Template like so:

=> app.component.html

<main class="main">
  <ng-template #loading>
    <div>Loading ...</div>
  </ng-template>

  <button (click)="toggleSpace()">openDirectly</button>

  <flatfile-space [spaceProps]="spaceProps" />
</main>

Then in your component, assign the TemplateRef as such:

=> app.component.ts

import { CommonModule } from '@angular/common';
import {
  AfterViewInit,
  Component,
  Inject,
  TemplateRef,
  ViewChild,
} from '@angular/core';
import { ISpace, SpaceModule, SpaceService } from '@flatfile/angular-sdk';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [CommonModule, SpaceModule],
  providers: [SpaceService],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css',
})
// Make sure that the component implements AfterViewInit
export class AppComponent implements AfterViewInit {
// Create a template ref with static option enabled
  @ViewChild('loading', { static: true }) loadingTemplate:
    | TemplateRef<any>
    | undefined;

  showSpace: boolean = false;

  constructor(@Inject(SpaceService) private spaceService: SpaceService) {}

  ngAfterViewInit(): void {
    // In ngAfterViewInit, assign the loading attribute to the template ref
     this.spaceProps.loading = this.loadingTemplate;
  }

  toggleSpace() {
    this.spaceService.OpenEmbed();
    this.showSpace = !this.showSpace;
  }

  closeSpace() {
    this.showSpace = false;
  }

  spaceProps: ISpace = {
    space: {
      id: 'id',
      accessToken: 'access_token',
    },
    closeSpace: {
      operation: 'submitActionFg',
      onClose: this.closeSpace.bind(this),
    },
    displayAsModal: false,
    environmentId: 'envId',
    labels: ['pinned'],
  };
}
custom-loading.mp4

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The changes introduce a new loading property in the Angular configuration, allowing developers to customize the loading component in Angular applications. The space.component.html template is modified to enhance conditional rendering, incorporating the new loading property and improving readability. Additionally, the Space component in space.component.ts is updated to implement the OnChanges lifecycle hook, enabling it to respond to changes in input properties and ensuring proper change detection.

Changes

File Path Change Summary
.changeset/proud-books-rush.md Added a new loading property in Angular configuration for overriding the default loading component.
packages/angular/angular-sdk/src/lib/sdk/space.component.html Updated conditions and bindings for rendering components. Simplified *ngIf checks, introduced ng-container for loading template, adjusted spinner display logic, and modified error handling for improved readability.
packages/angular/angular-sdk/src/lib/sdk/space.component.ts Implemented OnChanges lifecycle hook, added ngOnChanges method for handling input changes, updated constructor to include ChangeDetectorRef, and enhanced initSpace method for change detection after async operations.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant AngularApp
    participant SpaceComponent

    Developer->>AngularApp: Set loading property
    AngularApp->>SpaceComponent: Initialize component with loading state
    SpaceComponent->>SpaceComponent: ngOnChanges() triggered on input change
    SpaceComponent->>ChangeDetectorRef: Trigger change detection
    SpaceComponent->>AngularApp: Render loading or content based on loading state
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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.

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

🧹 Outside diff range and nitpick comments (4)
.changeset/proud-books-rush.md (2)

1-3: Consider using full package name instead of 'angular'.

While the minor version bump is appropriate for this feature addition, consider using the full package name '@flatfile/angular-sdk' instead of just 'angular' for better clarity.

---
-'angular': minor
+'@flatfile/angular-sdk': minor
---

5-5: Enhance the changeset description with implementation details.

The current description could be more informative by including key implementation details.

-Allow overriding the default loading component in Angular through the loading property.
+Allow overriding the default loading component in Angular by assigning a custom TemplateRef to the ISpace['loading'] property. This enables users to replace the default loading spinner with their own loading template.
packages/angular/angular-sdk/src/lib/sdk/space.component.ts (2)

114-114: Consider removing redundant change detection call.

The initial markForCheck() call at the start of initSpace might be redundant since the method is already triggered by either ngOnInit or the service subscription, both of which run within Angular's change detection cycle.

 initSpace = async (spaceProps: ReusedOrOnboarding) => {
-  this.changeDetectorRef.markForCheck()
   this.closeInstance = false
   // ... rest of the method
   } finally {
     this.changeDetectorRef.markForCheck()
   }
 }

Also applies to: 152-153


Line range hint 95-103: Consider making the API URL configurable through environment variables.

The hardcoded API URL 'https://platform.flatfile.com/api' appears in multiple places in the code. This could make it difficult to switch environments or handle different deployment scenarios.

Consider:

  1. Moving this URL to an environment configuration file
  2. Providing it through Angular's dependency injection system
  3. Creating a configuration service to manage such values

Example implementation:

// config.service.ts
@Injectable({providedIn: 'root'})
export class ConfigService {
  readonly apiUrl = environment.flatfileApiUrl;
}

// environment.ts
export const environment = {
  flatfileApiUrl: 'https://platform.flatfile.com/api'
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 94955b0 and 970e9a6.

📒 Files selected for processing (3)
  • .changeset/proud-books-rush.md (1 hunks)
  • packages/angular/angular-sdk/src/lib/sdk/space.component.html (1 hunks)
  • packages/angular/angular-sdk/src/lib/sdk/space.component.ts (6 hunks)
🔇 Additional comments (2)
packages/angular/angular-sdk/src/lib/sdk/space.component.ts (2)

Line range hint 1-29: LGTM! Clean implementation of change detection imports.

The addition of ChangeDetectorRef, OnChanges, and SimpleChanges imports along with the OnChanges interface implementation follows Angular best practices for handling component changes.


40-43: LGTM! Proper dependency injection.

The ChangeDetectorRef injection follows Angular's dependency injection best practices with appropriate access modifiers.

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