Conversation
WalkthroughThe changes introduce foundational documentation and configuration for the Changes
Recent review detailsConfiguration used: CodeRabbit UI Files ignored due to path filters (2)
Files selected for processing (5)
Files skipped from review due to trivial changes (4)
Additional comments not posted (2)
TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
Outside diff range, codebase verification and nitpick comments (1)
plugins/view-mapped/src/view-mapped.ts (1)
112-119: Improve error message clarity.The error message in the
catchblock could be more descriptive to help users understand the issue and possible next steps. Consider including more context or potential resolutions.- 'An error occured while updating the workbook. See Event Logs.' + 'An error occurred while updating the workbook. Please check the Event Logs for more details and ensure all configurations are correct.'
| listener | ||
| .filter({ job: 'workbook:viewMappedFieldsOnly' }) | ||
| .on('job:ready', async ({ context: { jobId, workbookId } }) => { | ||
| try { | ||
| // First, we acknowledge the job | ||
| await api.jobs.ack(jobId, { | ||
| info: 'Updating the table to only view mapped fields', | ||
| progress: 10, | ||
| }) | ||
|
|
||
| // Retrieving the info on the custom job we created in the listener above, and storing that info in its own "customJobInfo" variable | ||
| const customJobInfo = await api.jobs.get(jobId) | ||
|
|
||
| // From "customJobInfo" variable, retrieving the jobId specifically of the mapping job that completed, and storing it in its own "mappingJobId" variable | ||
| const mappingJobId = customJobInfo.data.input.mappingJobId | ||
|
|
||
| // Obtaining the mapping job's execution plan to later extract "fieldMapping" out of it, which tells us which fields were mapped in the Matching step | ||
| const jobPlan = await api.jobs.getExecutionPlan(mappingJobId) | ||
|
|
||
| // Initializing an empty array to store the keys of the mapped fields | ||
| const mappedFields = [] | ||
|
|
||
| // Iterating through all destination fields that are mapped and extracting their field keys. Then, pushing keys of mapped fields to the "mappedFields" variable | ||
| for (let i = 0; i < jobPlan.data.plan.fieldMapping.length; i++) { | ||
| const destinationFieldKey = | ||
| jobPlan.data.plan.fieldMapping[i].destinationField.key | ||
|
|
||
| mappedFields.push(destinationFieldKey) | ||
| } | ||
| // Making an API call to only get the "data" property out of the response, and saving it as its own "fetchedWorkbook" variable | ||
| // We need to make this API call and cannot just use what's inside of "workbookOne" because we need data in a specific format | ||
| const { data: workbook } = await api.workbooks.get(workbookId) | ||
|
|
||
| // Looping through all sheets of the Workbook One. For all fields that are mapped, updating those fields' metadata to "{mapped: true}" | ||
| workbook.sheets.forEach((sheet) => { | ||
| sheet.config.fields.forEach((field) => { | ||
| if (mappedFields.includes(field.key)) { | ||
| field.metadata = { mapped: true } | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
| // Looping over each sheet in "workbook" and filtering for fields with metadata "mapped: true". Saving mapped fields per each sheet inside of "filteredWorkbookFields" varibable | ||
| const filteredWorkbookFields = workbook.sheets.map((sheet) => { | ||
| const fields = sheet.config.fields.filter( | ||
| (field) => field.metadata && field.metadata.mapped === true | ||
| ) | ||
| return fields.length > 0 ? fields : null | ||
| }) | ||
|
|
||
| // Updating each sheet in a workbook to only contain fields that a user mapped. This ensures that when the table with data loads, only mapped fields will be displayed | ||
| await api.workbooks.update(workbookId, { | ||
| // Keeping other non-sheet elements of the workbook untouched (Workbook name, its Submit action, etc) | ||
| ...workbook, | ||
|
|
||
| // Mapping over each sheet to update each to only contain fields that are inside of "filteredWorkbookFields" variable (that have metadata "{mapped: true})" | ||
| sheets: workbook.sheets.map((sheet, index) => { | ||
| const mappedWorkbookFields = filteredWorkbookFields[index] | ||
|
|
||
| // If there are no mapped fields, returning the original sheet structure | ||
| if (!mappedWorkbookFields) { | ||
| return sheet | ||
| } | ||
|
|
||
| // If there are mapped fields, returning all properties of the original sheet but updating the "fields" property to the mapped fields | ||
| return { | ||
| ...sheet, | ||
| config: { | ||
| ...sheet.config, | ||
| fields: mappedWorkbookFields, | ||
| }, | ||
| } | ||
| }), | ||
| }) | ||
|
|
||
| // Completing the job with an appropriate message to the user | ||
| await api.jobs.complete(jobId, { | ||
| outcome: { | ||
| message: 'Table update complete. Please audit the data', | ||
| acknowledge: true, | ||
| }, | ||
| }) | ||
| } catch (error) { | ||
| // If something goes wrong while executing the custom job, we fail the job with a message on what next steps to take | ||
| await api.jobs.fail(jobId, { | ||
| outcome: { | ||
| message: | ||
| 'An error occured while updating the workbook. See Event Logs.', | ||
| }, | ||
| }) | ||
| } | ||
| }) |
There was a problem hiding this comment.
Optimize field mapping extraction.
The current implementation uses a loop to extract mapped fields. Consider using array methods like map and reduce for a more functional approach, which can improve readability and performance.
- for (let i = 0; i < jobPlan.data.plan.fieldMapping.length; i++) {
- const destinationFieldKey =
- jobPlan.data.plan.fieldMapping[i].destinationField.key
- mappedFields.push(destinationFieldKey)
- }
+ const mappedFields = jobPlan.data.plan.fieldMapping.map(
+ (mapping) => mapping.destinationField.key
+ )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.
| listener | |
| .filter({ job: 'workbook:viewMappedFieldsOnly' }) | |
| .on('job:ready', async ({ context: { jobId, workbookId } }) => { | |
| try { | |
| // First, we acknowledge the job | |
| await api.jobs.ack(jobId, { | |
| info: 'Updating the table to only view mapped fields', | |
| progress: 10, | |
| }) | |
| // Retrieving the info on the custom job we created in the listener above, and storing that info in its own "customJobInfo" variable | |
| const customJobInfo = await api.jobs.get(jobId) | |
| // From "customJobInfo" variable, retrieving the jobId specifically of the mapping job that completed, and storing it in its own "mappingJobId" variable | |
| const mappingJobId = customJobInfo.data.input.mappingJobId | |
| // Obtaining the mapping job's execution plan to later extract "fieldMapping" out of it, which tells us which fields were mapped in the Matching step | |
| const jobPlan = await api.jobs.getExecutionPlan(mappingJobId) | |
| // Initializing an empty array to store the keys of the mapped fields | |
| const mappedFields = [] | |
| // Iterating through all destination fields that are mapped and extracting their field keys. Then, pushing keys of mapped fields to the "mappedFields" variable | |
| for (let i = 0; i < jobPlan.data.plan.fieldMapping.length; i++) { | |
| const destinationFieldKey = | |
| jobPlan.data.plan.fieldMapping[i].destinationField.key | |
| mappedFields.push(destinationFieldKey) | |
| } | |
| // Making an API call to only get the "data" property out of the response, and saving it as its own "fetchedWorkbook" variable | |
| // We need to make this API call and cannot just use what's inside of "workbookOne" because we need data in a specific format | |
| const { data: workbook } = await api.workbooks.get(workbookId) | |
| // Looping through all sheets of the Workbook One. For all fields that are mapped, updating those fields' metadata to "{mapped: true}" | |
| workbook.sheets.forEach((sheet) => { | |
| sheet.config.fields.forEach((field) => { | |
| if (mappedFields.includes(field.key)) { | |
| field.metadata = { mapped: true } | |
| } | |
| }) | |
| }) | |
| // Looping over each sheet in "workbook" and filtering for fields with metadata "mapped: true". Saving mapped fields per each sheet inside of "filteredWorkbookFields" varibable | |
| const filteredWorkbookFields = workbook.sheets.map((sheet) => { | |
| const fields = sheet.config.fields.filter( | |
| (field) => field.metadata && field.metadata.mapped === true | |
| ) | |
| return fields.length > 0 ? fields : null | |
| }) | |
| // Updating each sheet in a workbook to only contain fields that a user mapped. This ensures that when the table with data loads, only mapped fields will be displayed | |
| await api.workbooks.update(workbookId, { | |
| // Keeping other non-sheet elements of the workbook untouched (Workbook name, its Submit action, etc) | |
| ...workbook, | |
| // Mapping over each sheet to update each to only contain fields that are inside of "filteredWorkbookFields" variable (that have metadata "{mapped: true})" | |
| sheets: workbook.sheets.map((sheet, index) => { | |
| const mappedWorkbookFields = filteredWorkbookFields[index] | |
| // If there are no mapped fields, returning the original sheet structure | |
| if (!mappedWorkbookFields) { | |
| return sheet | |
| } | |
| // If there are mapped fields, returning all properties of the original sheet but updating the "fields" property to the mapped fields | |
| return { | |
| ...sheet, | |
| config: { | |
| ...sheet.config, | |
| fields: mappedWorkbookFields, | |
| }, | |
| } | |
| }), | |
| }) | |
| // Completing the job with an appropriate message to the user | |
| await api.jobs.complete(jobId, { | |
| outcome: { | |
| message: 'Table update complete. Please audit the data', | |
| acknowledge: true, | |
| }, | |
| }) | |
| } catch (error) { | |
| // If something goes wrong while executing the custom job, we fail the job with a message on what next steps to take | |
| await api.jobs.fail(jobId, { | |
| outcome: { | |
| message: | |
| 'An error occured while updating the workbook. See Event Logs.', | |
| }, | |
| }) | |
| } | |
| }) | |
| listener | |
| .filter({ job: 'workbook:viewMappedFieldsOnly' }) | |
| .on('job:ready', async ({ context: { jobId, workbookId } }) => { | |
| try { | |
| // First, we acknowledge the job | |
| await api.jobs.ack(jobId, { | |
| info: 'Updating the table to only view mapped fields', | |
| progress: 10, | |
| }) | |
| // Retrieving the info on the custom job we created in the listener above, and storing that info in its own "customJobInfo" variable | |
| const customJobInfo = await api.jobs.get(jobId) | |
| // From "customJobInfo" variable, retrieving the jobId specifically of the mapping job that completed, and storing it in its own "mappingJobId" variable | |
| const mappingJobId = customJobInfo.data.input.mappingJobId | |
| // Obtaining the mapping job's execution plan to later extract "fieldMapping" out of it, which tells us which fields were mapped in the Matching step | |
| const jobPlan = await api.jobs.getExecutionPlan(mappingJobId) | |
| // Using map to extract the keys of the mapped fields | |
| const mappedFields = jobPlan.data.plan.fieldMapping.map( | |
| (mapping) => mapping.destinationField.key | |
| ) | |
| // Making an API call to only get the "data" property out of the response, and saving it as its own "fetchedWorkbook" variable | |
| // We need to make this API call and cannot just use what's inside of "workbookOne" because we need data in a specific format | |
| const { data: workbook } = await api.workbooks.get(workbookId) | |
| // Looping through all sheets of the Workbook One. For all fields that are mapped, updating those fields' metadata to "{mapped: true}" | |
| workbook.sheets.forEach((sheet) => { | |
| sheet.config.fields.forEach((field) => { | |
| if (mappedFields.includes(field.key)) { | |
| field.metadata = { mapped: true } | |
| } | |
| }) | |
| }) | |
| // Looping over each sheet in "workbook" and filtering for fields with metadata "mapped: true". Saving mapped fields per each sheet inside of "filteredWorkbookFields" varibable | |
| const filteredWorkbookFields = workbook.sheets.map((sheet) => { | |
| const fields = sheet.config.fields.filter( | |
| (field) => field.metadata && field.metadata.mapped === true | |
| ) | |
| return fields.length > 0 ? fields : null | |
| }) | |
| // Updating each sheet in a workbook to only contain fields that a user mapped. This ensures that when the table with data loads, only mapped fields will be displayed | |
| await api.workbooks.update(workbookId, { | |
| // Keeping other non-sheet elements of the workbook untouched (Workbook name, its Submit action, etc) | |
| ...workbook, | |
| // Mapping over each sheet to update each to only contain fields that are inside of "filteredWorkbookFields" variable (that have metadata "{mapped: true})" | |
| sheets: workbook.sheets.map((sheet, index) => { | |
| const mappedWorkbookFields = filteredWorkbookFields[index] | |
| // If there are no mapped fields, returning the original sheet structure | |
| if (!mappedWorkbookFields) { | |
| return sheet | |
| } | |
| // If there are mapped fields, returning all properties of the original sheet but updating the "fields" property to the mapped fields | |
| return { | |
| ...sheet, | |
| config: { | |
| ...sheet.config, | |
| fields: mappedWorkbookFields, | |
| }, | |
| } | |
| }), | |
| }) | |
| // Completing the job with an appropriate message to the user | |
| await api.jobs.complete(jobId, { | |
| outcome: { | |
| message: 'Table update complete. Please audit the data', | |
| acknowledge: true, | |
| }, | |
| }) | |
| } catch (error) { | |
| // If something goes wrong while executing the custom job, we fail the job with a message on what next steps to take | |
| await api.jobs.fail(jobId, { | |
| outcome: { | |
| message: | |
| 'An error occured while updating the workbook. See Event Logs.', | |
| }, | |
| }) | |
| } | |
| }) |
No description provided.