Skip to content

Feat/apd 22 header selection updates.#534

Merged
carlbrugger merged 13 commits intomainfrom
feat/apd-22-header-selection
Jun 6, 2024
Merged

Feat/apd 22 header selection updates.#534
carlbrugger merged 13 commits intomainfrom
feat/apd-22-header-selection

Conversation

@damonbanks
Copy link
Contributor

@damonbanks damonbanks commented May 24, 2024

Please explain how to summarize this PR for the Changelog:

This formats excel and delimiter plugins to not truncate the incoming data to the detected header row but instead preserves the original format of the file, opting to update the sheet.metadata column with the header information.

Adds sheets.metadata support for future releases of Flatfile Platform. This formats the metadata.headers to support Flatfile platform expectations.

Tell code reviewer how and what to test:

The PR Essentially updates how the file extraction operates:

  1. The uploaded file will now not cut off rows above the detected header row
  2. File Sheets row headers will be A, B, C, ... AA, AB, AC...

What this will enable us to do is to allow the user or AI (eventually) to update the header row.

Testing

On the platform project:
Setup:

  1. New Entitlement: run pnpm run migrate:records from the apps/platform folder
  2. then run pnpm run cli entitlement add --key headerSelection --resource dev_acc_yourLocalAccountId
  3. From there you can test with it on and off pnpm run cli entitlement rm --key headerSelection --resource dev_acc_yourLocalAccountId

Testing Areas:
File upload
- Different Files. See not above on CSVs only getting the new functionality atm
- You should be able to upload a csv with the header row on line > 1 and still see the previous rows
- With the new entitlement turned off you should see things work as they do today

File Mapping

  • Mapping should look and act exactly like it does today with and without the entitlement on.

@damonbanks damonbanks requested a review from carlbrugger June 5, 2024 21:18
@carlbrugger carlbrugger force-pushed the feat/apd-22-header-selection branch from 2e4458c to 16943cb Compare June 6, 2024 02:35
@damonbanks damonbanks marked this pull request as ready for review June 6, 2024 16:14
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 6, 2024

Walkthrough

The recent updates introduce significant changes across various modules to enhance functionality and ensure immutability. The primary focus is on replacing the exportWorkbookPlugin with ExcelExtractor and DelimiterExtractor, adding header index-to-letter conversion capabilities, and making properties in DelimiterOptions immutable. Additionally, new features related to header selection and metadata handling have been incorporated, impacting multiple extractors and parsers.

Changes

File(s) Change Summary
flatfilers/sandbox/src/index.ts Replaced exportWorkbookPlugin with ExcelExtractor and DelimiterExtractor with specific configurations.
plugins/delimiter-extractor/src/header.detection.ts, plugins/xlsx-extractor/src/header.detection.ts Added letters property to GetHeadersResult and introduced functions for header index-to-letter conversion. Updated various classes to include letters.
plugins/delimiter-extractor/src/index.ts Made all properties of DelimiterOptions interface readonly.
plugins/xlsx-extractor/src/parser.spec.ts Added new data object, adjusted length expectation for Departments array, and set metadata property to undefined.
plugins/xlsx-extractor/src/parser.ts Modified ParseBufferOptions to include headerSelectionEnabled, updated parseBuffer and convertSheet functions to handle this new option.
plugins/json-extractor/src/parser.spec.ts, plugins/xml-extractor/src/parser.spec.ts Added metadata: undefined property in test cases.
utils/extractor/src/index.ts Updated Extractor function to include spaceId parameter, fetch entitlements, set headerSelectionEnabled, and update sheet metadata. Added updateSheetMetadata function.
.changeset/config.json Updated configuration to ignore internal dependency @private/sandbox.
.changeset/happy-mangos-hug.md Introduced support for new Platform feature related to header selection.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant Listener
    participant ExcelExtractor
    participant DelimiterExtractor

    User->>Listener: Initiates extraction
    Listener->>ExcelExtractor: Uses ExcelExtractor
    ExcelExtractor-->>Listener: Data extracted
    Listener->>DelimiterExtractor: Uses DelimiterExtractor with .txt config
    DelimiterExtractor-->>Listener: Data extracted
    Listener-->>User: Extraction complete
Loading
sequenceDiagram
    participant System
    participant Extractor
    participant EntitlementsService
    participant Workbook

    System->>Extractor: Call Extractor with spaceId
    Extractor->>EntitlementsService: Fetch entitlements for spaceId
    EntitlementsService-->>Extractor: Return entitlements
    Extractor->>Workbook: Update sheet metadata if headerSelectionEnabled
    Workbook-->>Extractor: Metadata updated
    Extractor-->>System: Extraction complete
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 16943cb and d58bc47.

Files selected for processing (2)
  • .changeset/config.json (1 hunks)
  • .changeset/happy-mangos-hug.md (1 hunks)
Files skipped from review due to trivial changes (1)
  • .changeset/config.json
Additional comments not posted (2)
.changeset/happy-mangos-hug.md (2)

2-4: Versioning correctly reflects major updates, indicating significant changes.


7-7: Clear and concise description of the new feature support.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@damonbanks damonbanks changed the title Feat/apd 22 header selection updates. (DONT MERGE UNTIL Platform is ready) Feat/apd 22 header selection updates. Jun 6, 2024
@damonbanks damonbanks requested a review from carlbrugger June 6, 2024 16:14
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: 3

Outside diff range and nitpick comments (10)
plugins/xml-extractor/src/parser.spec.ts (1)

Line range hint 68-156: Convert function expressions to arrow functions for simplicity.

- describe('parser', function () {
+ describe('parser', () => {
-   describe('xmlToJson', function () {
+   describe('xmlToJson', () => {
-     test('with multiple items', function () {
+     test('with multiple items', () => {
-     test('with one item', function () {
+     test('with one item', () => {
-   test('headersFromObjectList', function () {
+   test('headersFromObjectList', () => {
-   describe('findRoot', function () {
+   describe('findRoot', () => {
-     test('skips _declaration', function () {
+     test('skips _declaration', () => {
-     test('works with no declaration', function () {
+     test('works with no declaration', () => {
-   describe('parser', function () {
+   describe('parser', () => {
-     test('test duplicate header', function () {
+     test('test duplicate header', () => {
plugins/xlsx-extractor/src/parser.spec.ts (1)

38-38: The metadata property is set to undefined. If this is intentional to represent no metadata, consider adding a comment to clarify this, as it might be mistaken for an oversight.

plugins/json-extractor/src/parser.spec.ts (2)

Line range hint 5-147: Convert the function expression to an arrow function for consistency and to align with modern JavaScript practices.

- describe('parser', function () {
+ describe('parser', () => {

118-118: The metadata property is set to undefined. If this is intentional, consider adding a comment to clarify this choice.

plugins/xlsx-extractor/src/header.detection.ts (3)

41-42: Add documentation for the new letters property in GetHeadersResult.

It would be beneficial to include comments explaining the purpose and usage of the letters property to aid future developers.


Line range hint 111-134: Refactor duplicated logic in OriginalDetector.getHeaders.

The logic to resolve the promise with { header, skip, letters } is duplicated in the 'finish' and 'close' event handlers. Consider extracting this into a separate method to reduce duplication and improve maintainability.

+ private resolveHeaders(resolve, header, skip, letters) {
+   resolve({ header, skip, letters });
+ }
  ...
  detector.on('finish', () => {
-   resolve({ header, skip, letters });
+   this.resolveHeaders(resolve, header, skip, letters);
  });
  dataStream.on('close', () => {
-   resolve({ header, skip, letters });
+   this.resolveHeaders(resolve, header, skip, letters);
  });

Also applies to: 137-137


Line range hint 62-62: Remove unnecessary constructor in Headerizer.

The constructor in Headerizer is flagged as unnecessary by static analysis. Consider removing it to simplify the class definition.

- constructor() {}
plugins/delimiter-extractor/src/header.detection.ts (3)

41-42: Add documentation for the new letters property in GetHeadersResult.

It would be beneficial to include comments explaining the purpose and usage of the letters property to aid future developers.


Line range hint 111-134: Refactor duplicated logic in OriginalDetector.getHeaders.

The logic to resolve the promise with { header, skip, letters } is duplicated in the 'finish' and 'close' event handlers. Consider extracting this into a separate method to reduce duplication and improve maintainability.

+ private resolveHeaders(resolve, header, skip, letters) {
+   resolve({ header, skip, letters });
+ }
  ...
  detector.on('finish', () => {
-   resolve({ header, skip, letters });
+   this.resolveHeaders(resolve, header, skip, letters);
  });
  dataStream.on('close', () => {
-   resolve({ header, skip, letters });
+   this.resolveHeaders(resolve, header, skip, letters);
  });

Also applies to: 137-137


Line range hint 62-62: Remove unnecessary constructor in Headerizer.

The constructor in Headerizer is flagged as unnecessary by static analysis. Consider removing it to simplify the class definition.

- constructor() {}

@carlbrugger carlbrugger merged commit a78b608 into main Jun 6, 2024
@carlbrugger carlbrugger deleted the feat/apd-22-header-selection branch June 6, 2024 17:58
@coderabbitai coderabbitai bot mentioned this pull request Jan 8, 2025
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