Skip to content

fix: view mapped plugin#758

Merged
carlbrugger merged 4 commits intomainfrom
fix/view-mapped-plugin
Feb 21, 2025
Merged

fix: view mapped plugin#758
carlbrugger merged 4 commits intomainfrom
fix/view-mapped-plugin

Conversation

@carlbrugger
Copy link
Contributor

Please explain how to summarize this PR for the Changelog:

This PR fixes an issue computing records by running the view-mapped job at the sheet level

Tell code reviewer how and what to test:

@carlbrugger carlbrugger marked this pull request as ready for review February 21, 2025 00:02
@promptless
Copy link

promptless bot commented Feb 21, 2025

✅ No documentation updates required.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

Walkthrough

This patch for the @flatfile/plugin-view-mapped plugin updates the internal logic of the viewMappedPlugin function. The changes adjust job completion handling by extracting the job ID directly from the event context and switching the job type from workbook-level to sheet-level. Additionally, the listener for mapped fields now uses the updated job type and applies optional chaining when accessing the trackChanges setting, improving error robustness. No alterations were made to the public API.

Changes

File Summary of Changes
.changeset/violet-flies-warn.md Release note updating the plugin description to reflect the shift to sheet-level job handling for improved record computation.
plugins/view-mapped/src/view-mapped.ts Updated viewMappedPlugin function: extracted jobId from event context; changed custom job type from 'workbook' to 'sheet' and listener job type from 'workbook:viewMappedFieldsOnly' to 'sheet:viewMappedFieldsOnly'; implemented optional chaining for safer access to trackChanges.

Possibly related PRs

Suggested reviewers

  • bangarang

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 52bfd17 and 498124b.

📒 Files selected for processing (1)
  • plugins/view-mapped/src/view-mapped.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/view-mapped/src/view-mapped.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Setup

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

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

🧹 Nitpick comments (3)
plugins/view-mapped/src/view-mapped.ts (2)

23-23: Add error handling for getExecutionPlan.
If the job ID is invalid or the job plan data is unavailable, api.jobs.getExecutionPlan(jobId) could fail. Consider wrapping this call in a try/catch block or performing a sanity check to gracefully handle potential errors.

 try {
   const jobPlan = await api.jobs.getExecutionPlan(jobId)
+} catch (err) {
+  logError('viewMappedPlugin', `Failed to retrieve execution plan: ${err}`)
+  throw new Error('Unable to retrieve execution plan.')
 }

25-27: Validate job config before type casting.
Using as Flatfile.MappingProgramJobConfig presumes the existence of config. Consider optional chaining or a prior guard to prevent errors if jobPlan.data.job.config is missing or null.

 const destinationSheetId = (
-  jobPlan.data.job.config as Flatfile.MappingProgramJobConfig
+  jobPlan.data?.job?.config as Flatfile.MappingProgramJobConfig
).destinationSheetId
.changeset/violet-flies-warn.md (1)

5-5: Add missing preposition for clarity.
Consider rephrasing “fixes an issue computing records” to “fixes an issue in computing records” or “with computing records” for improved readability.

-This release fixes an issue computing records by running the view-mapped job at the sheet level
+This release fixes an issue in computing records by running the view-mapped job at the sheet level
🧰 Tools
🪛 LanguageTool

[uncategorized] ~5-~5: Possible missing preposition found.
Context: ... patch --- This release fixes an issue computing records by running the view-mapped job ...

(AI_EN_LECTOR_MISSING_PREPOSITION)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eff986e and 52bfd17.

📒 Files selected for processing (2)
  • .changeset/violet-flies-warn.md (1 hunks)
  • plugins/view-mapped/src/view-mapped.ts (3 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/violet-flies-warn.md

[uncategorized] ~5-~5: Possible missing preposition found.
Context: ... patch --- This release fixes an issue computing records by running the view-mapped job ...

(AI_EN_LECTOR_MISSING_PREPOSITION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Setup
🔇 Additional comments (5)
plugins/view-mapped/src/view-mapped.ts (5)

19-21: Consider guarding against missing jobId in the event context.
Although extracting jobId directly from event.context is a reasonable approach, you might want to validate its presence to avoid runtime errors if jobId is undefined.


31-32: Sheet-level job creation looks correct.
Changing the job type to 'sheet' aligns with the goal of recomputing record counts at the sheet level. This meets the PR objective of fixing the sheet-level computations.


34-34: Consistent source usage for sheet-level job.
Referencing destinationSheetId as the job source is sensible. This maintains consistency with the newly adopted sheet-level operation.


47-47: Using 'sheet:viewMappedFieldsOnly' is consistent with the sheet-level scope.
Transitioning the listener to handle the 'sheet:viewMappedFieldsOnly' operation reflects the new approach, ensuring that logic for mapped fields only applies at the sheet level.


87-87: Good use of optional chaining to avoid runtime errors.
Utilizing workbook.settings?.trackChanges safely checks for settings before accessing trackChanges, preventing potential exceptions if settings is null or undefined.

@carlbrugger carlbrugger merged commit 2411e56 into main Feb 21, 2025
37 checks passed
@carlbrugger carlbrugger deleted the fix/view-mapped-plugin branch February 21, 2025 00:17
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