Step Handler
Concept
The Step Handler provides powerful hooks that execute after each step of the import process, giving you complete control over the data flow and user experience. Unlike its predecessor (Data Handler) which runs before the header and the review steps, the Step Handler runs after each step is completed, allowing you to validate, modify, or block progression based on your requirements.
| Description | The Step Handler is an advanced feature that provides hooks after each step of the import process. It enables you to access the raw uploaded and parsed files, validate data, add cell-specific errors/warnings/infos, and control the import flow with built-in or custom modals. With the Step Handler, you can implement complex validation logic, throw pre-submission errors, access column and option mappings, and provide custom user feedback at any stage of the import process. Step Handler replaces the Data Handler and provides more granular control with hooks for upload, header selection, mapping, and review steps. |
| Available hooks |
|
| Control functions |
|
Basic syntax
Here is an example of the Step Handler's syntax:
stepHandler={{
uploadStep: async ({parsedData, rawData, updateData, alert, block}) => {
// Hook runs after file upload and parsing
},
headerStep: async ({data, updateData, alert, block, proceed, stay}) => {
// Hook runs after header selection confirmation
},
preProcessingStep: async ({data, updateData, alert, block, proceed, stay}) => {
// Hook runs after the Pre-Processing step
},
mappingStep: async ({data, tdm, updateData, alert, block, proceed, stay, logs}) => {
// Hook runs after mapping confirmation
},
reviewStep: async ({data, updateData, block, proceed, stay, logs}) => {
// Hook runs when user clicks "Complete import" in the review step
}
}}
uploadStep()
| Description | This hook runs after the user has uploaded one or multiple files and the files have been parsed. It provides access to both the raw uploaded files and their parsed data, allowing validation and transformation before proceeding to the next step. |
| Parameters |
|
| Run event | The uploadStep function is executed immediately after file upload and parsing is complete |
Parameters
parsedData
Array of sheet objects containing the parsed data and metadata for each uploaded file/sheet.
Sheet object properties:
- data: A 2D array representing the content of the sheet
- fileName: The name of the uploaded file
- fileSize: The size of the file in megabytes (MB)
- fileType: The file extension (e.g., "xlsx", "csv", "xls")
- sheetName: The name of the sheet (for Excel files) or defaults to the
fileNamefor single-sheet files
Example:
[
{
"data": [
[
"company",
"order_id",
"customer_email",
"order_instructions",
], ...
],
"fileName": "test-file.xlsx",
"fileSize": 0.0067,
"fileType": "xlsx",
"sheetName": "test-sheet-1"
}, ...
]
rawData
Array of raw file objects containing the unprocessed files exactly as they were uploaded. This gives you access to the original files before any parsing or processing.
updateData
Function to modify the data structure before proceeding to the next step.
Return format:
updateData([
{
fileName: "Customers",
sheetName: "Internal", // optional
data: [
// supports 2D array and array of row objects
["id", "name"],
["12345", "Jason"],
],
},
{
fileName: "Products",
data: [
// supports 2D array and array of row objects
{ id: "12", quantity: 24 },
{ id: "13", quantity: 88 },
],
},
]);
alert
Function to show a warning modal with proceed/cancel options.
Parameters:
- title: Title of the warning modal
- description: Description text explaining the warning
- cancelButton: Text for the cancel button
- proceedButton: Text for the proceed button
block
Function to show an error modal that blocks progression.
Parameters:
- title: Text for the modal title
- description: Text explaining the error
- closeButton: Text for the close button
Implementation example
stepHandler={{
uploadStep: async ({parsedData, rawData, updateData, alert, block}) => {
// Access raw uploaded files
console.log('Raw files:', rawData);
// Process parsed data
const processedData = parsedData.map(file => ({
fileName: file.fileName,
sheetName: file.sheetName,
data: file.data.filter(row => row.length > 0) // Remove empty rows
}));
// Check for issues and potentially block
if (processedData.some(file => file.data.length === 0)) {
block({
title: "Empty File Detected",
description: "One or more files contain no data. Please upload valid files.",
closeButton: "Close"
});
return;
}
// Update data for next step
updateData(processedData);
}
}}
Interaction with other features
- allowManualInput: When the user clicks the "Manual Entry" button,
uploadStep()is not triggered, and the user is forwarded to the review step. - automaticHeaderDetection: When
automaticHeaderDetection === true, it does not affectuploadStep().uploadStep()is triggered after parsing. If it finishes withoutalert()orblock()being called, the user is forwarded to the next step (sheet or header selection). - Contextual Engine:
uploadStep()runs after file upload, before the Contextual Engine is applied or the modal to use the Contextual Engine is displayed.