Skip to content

feat: remove remeda & add disableFileNameUpdate option#672

Merged
carlbrugger merged 1 commit intomainfrom
feat/automap-update
Oct 22, 2024
Merged

feat: remove remeda & add disableFileNameUpdate option#672
carlbrugger merged 1 commit intomainfrom
feat/automap-update

Conversation

@carlbrugger
Copy link
Contributor

Please explain how to summarize this PR for the Changelog:

This PR removes the remeda dependency & adds the disableFileNameUpdate option

Tell code reviewer how and what to test:

Using the provided listener, upload the provided file. Ensure that the file name does not change and the file's data is mapped to the getting-started workbook.

getting-started.csv

import type { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
import { automap } from '@flatfile/plugin-automap'
import { configureSpace } from '@flatfile/plugin-space-configure'

export default function (listener: FlatfileListener) {
  const matchFilename = /(?:^|.*\s)getting-started\.csv(?:\s.*|$)/

  listener.use(
    automap({
      accuracy: 'confident',
      defaultTargetSheet: 'getting-started',
      matchFilename,
      disableFileNameUpdate: true,
      onFailure: (event: FlatfileEvent) => {
        console.error(
          `Failed to automap! Please visit https://platform.flatfile.com/s/space/${event.context.spaceId}/files?mode=import to manually import file.`
        )
      },
    })
  )

  listener.use(
    configureSpace({
      workbooks: [
        {
          name: 'Sandbox',
          sheets: [
            {
              name: 'Getting Started',
              slug: 'getting-started',
              fields: [
                {
                  key: 'firstName',
                  type: 'string',
                  label: 'First Name',
                },
                {
                  key: 'lastName',
                  type: 'string',
                  label: 'Last Name',
                },
                {
                  key: 'email',
                  type: 'string',
                  label: 'Email',
                },
                {
                  key: 'dob',
                  type: 'date',
                  label: 'Date of Birth',
                },
                {
                  key: 'hireDate',
                  type: 'date',
                  label: 'Hire Date',
                },
              ],
            },
          ],
        },
      ],
    })
  )
}

@carlbrugger carlbrugger marked this pull request as ready for review October 15, 2024 21:42
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

This pull request introduces a minor update to the @flatfile/plugin-automap package. It removes the remeda dependency and adds a new option, disableFileNameUpdate, allowing users to control file name updates during plugin operation. Modifications to the AutomapService class enhance logging and adjust file name matching logic based on the new option. Import statements are updated to utilize utilities from modern-async and @flatfile/util-common, reflecting a shift towards modern JavaScript practices.

Changes

File Path Change Summary
plugins/automap/src/automap.plugin.ts Added disableFileNameUpdate option and readonly disableFileNameUpdate?: boolean property.
plugins/automap/src/automap.service.ts Updated logging methods, modified logic for file name matching, and adjusted import statements.
Method signatures in AutomapService updated, but no changes in their signatures.

Possibly related PRs

  • chore: update versions #600: This PR updates the @flatfile/plugin-automap, which is directly related to the main PR that also modifies the AutomapService class in the same plugin.
  • feat: export-workbook refactor #512: Although this PR focuses on the @flatfile/plugin-export-workbook, it shares a similar context of plugin functionality updates, which may relate to the overall plugin architecture being modified in the main PR.

Suggested reviewers

  • bangarang

🪧 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: 0

🧹 Outside diff range and nitpick comments (2)
plugins/automap/src/automap.plugin.ts (1)

36-36: Approved: New option added successfully. Consider adding JSDoc comment.

The addition of the disableFileNameUpdate property to the AutomapOptions interface is correct and aligns with the PR objectives. The property is properly typed as an optional boolean and marked as readonly, which is good for immutability.

For consistency with other properties in the interface, consider adding a JSDoc comment explaining the purpose of this new option. Here's a suggested addition:

+  /** Prevents updating of the file name during the automapping process when set to true. */
   readonly disableFileNameUpdate?: boolean
plugins/automap/src/automap.service.ts (1)

87-89: Consider optional chaining for safer property access

In the destinationSheet finder, you access s.config.slug without ensuring that s.config is defined. To prevent potential runtime errors if s.config is undefined, consider using optional chaining.

Apply this diff to safely access s.config.slug:

-destinationSheet = destinationWorkbook.sheets.find(
-  (s) =>
-    s.name === target || s.id === target || s.config.slug === target
+destinationSheet = destinationWorkbook.sheets.find(
+  (s) =>
+    s.name === target || s.id === target || s.config?.slug === target
)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ad3d45f and 1bc7c2a.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • plugins/automap/package.json is excluded by !**/*.json
📒 Files selected for processing (3)
  • .changeset/poor-starfishes-nail.md (1 hunks)
  • plugins/automap/src/automap.plugin.ts (1 hunks)
  • plugins/automap/src/automap.service.ts (14 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/poor-starfishes-nail.md
🧰 Additional context used
🔇 Additional comments (8)
plugins/automap/src/automap.plugin.ts (1)

Line range hint 1-36: Verify implementation of new option in AutomapService

The addition of the disableFileNameUpdate option to the AutomapOptions interface is a good enhancement. However, the implementation of this option is not visible in this file.

To ensure the new option is properly implemented, please run the following script to check the AutomapService class:

This will help verify that the new option is being used correctly in the AutomapService class.

✅ Verification successful

Verified: The disableFileNameUpdate option is properly implemented in the AutomapService class, as it is actively used in conditional statements within plugins/automap/src/automap.service.ts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the implementation of the disableFileNameUpdate option in AutomapService

# Test: Search for usage of disableFileNameUpdate in AutomapService
ast-grep --lang typescript --pattern 'class AutomapService {
  $$$
  $_($$$) {
    $$$
    this.options.disableFileNameUpdate
    $$$
  }
  $$$
}'

# If no results, search for any mention of disableFileNameUpdate
rg --type typescript 'disableFileNameUpdate' plugins/automap/src/automap.service.ts

Length of output: 267


Script:

#!/bin/bash
# Description: Verify the implementation of the disableFileNameUpdate option in AutomapService

# Search for the usage of disableFileNameUpdate in the AutomapService class
ast-grep --lang typescript --pattern 'class AutomapService {
  $$$
  $_($$$) {
    $$$
    this.options.disableFileNameUpdate
    $$$
  }
  $$$
}'

# If no results, search for any mention of disableFileNameUpdate in .ts files
rg 'disableFileNameUpdate' plugins/automap/src/automap.service.ts

Length of output: 348

plugins/automap/src/automap.service.ts (7)

3-4: Updated imports to remove remeda dependency

The imports have been updated to use logError, logInfo, logWarn from @flatfile/util-common and asyncMap from modern-async, effectively removing the dependency on remeda. This aligns with the PR objective of removing remeda and modernizes the codebase.


46-47: Conditional check for disableFileNameUpdate option

The condition else if (!this.options.disableFileNameUpdate) correctly checks whether the disableFileNameUpdate option is not enabled before updating the file name. This ensures that file name updates are only performed when not disabled by the user.


50-54: Use of custom isNil method for null checks

Replacing the R.isNil function with the custom isNil method serves the purpose of checking for null or undefined values after removing the remeda dependency. The implementation is straightforward and maintains the original functionality.


Line range hint 298-306: Resetting regex lastIndex for global patterns

In the isFileNameMatch method, resetting regex.lastIndex = 0 when regex.global is true is necessary to avoid unexpected behavior due to the lastIndex property in global regex patterns. This ensures consistent and accurate file name matching.


343-346: Verification of absolute matching strategy

The verifyAbsoluteMatchingStrategy method correctly checks that all field mappings have a certainty of Flatfile.Certainty.Absolute. This ensures that the 'exact' accuracy option functions as intended, only proceeding when matches are absolutely certain.


353-358: Verification of confident matching strategy

The verifyConfidentMatchingStrategy method effectively verifies that all field mappings have a certainty of either Flatfile.Certainty.Strong or Flatfile.Certainty.Absolute. This aligns with the 'confident' accuracy option, allowing the process to continue when mappings are sufficiently reliable.


369-370: Implementation of isNil method

The isNil method is correctly implemented to check for null or undefined values, effectively replacing the R.isNil function from remeda. This maintains the previous functionality while removing the external dependency.

Copy link
Collaborator

@bangarang bangarang left a comment

Choose a reason for hiding this comment

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

Nice cleanup in here while you're at it! 🚀

@carlbrugger carlbrugger merged commit 484fac9 into main Oct 22, 2024
@carlbrugger carlbrugger deleted the feat/automap-update branch October 22, 2024 14:50
This was referenced Oct 22, 2024
This was referenced Oct 29, 2024
@coderabbitai coderabbitai bot mentioned this pull request Nov 19, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 17, 2024
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