(fix): Make download work when no datasource is present#175
(fix): Make download work when no datasource is present#175
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR fixes a critical bug in the CSV download functionality for Plotly charts when no traditional datasource is present. The changes enable the system to extract data directly from chart traces as a fallback mechanism.
The core issue was that the existing download system assumed all charts would have populated dataSources objects, but some Plotly charts embed their data directly within trace properties instead. When users attempted to download CSV data from these charts, the process would fail because the utility functions couldn't access the required data.
The solution involves three coordinated changes:
- Enhanced data extraction logic: The
processTraceDatafunction incsvString.jsnow includes a fallback path that can extract data directly from trace properties whendataSourcesis empty or invalid - Improved CSV generation: The
generateOriginalCSVfunction inutils.jswas updated to detect when datasources are missing and process chart traces directly using the enhancedprocessTraceDatafunction - Parameter propagation: The
Download.jsxcomponent now passes the necessarychartDataandreactChartEditorLibparameters to the utility functions, enabling the fallback logic to work properly
This enhancement maintains full backward compatibility with existing charts that use traditional datasources while extending support to charts with embedded trace data. The implementation leverages existing helper functions and follows established patterns in the codebase, ensuring consistency with other data processing workflows.
Important Files Changed
Changed Files
| Filename | Score | Overview |
|---|---|---|
| src/Utils/Download.jsx | 5/5 | Added missing chartData and reactChartEditorLib parameters to CSV generation function calls |
| src/helpers/csvString.js | 4/5 | Enhanced processTraceData function with fallback logic to extract data from trace properties when no datasources exist |
| src/Utils/utils.js | 4/5 | Modified generateOriginalCSV to handle missing dataSources by processing chart traces directly with debugging logs |
Confidence score: 4/5
- This PR is safe to merge with low risk of production issues
- Score reflects solid bug fix implementation with proper fallback logic, though debugging console logs should be cleaned up
- Pay close attention to
src/Utils/utils.jsfor the debugging console.log statements that should be removed before production
Sequence Diagram
sequenceDiagram
participant User
participant Download
participant Utils
participant CSVHelper
participant JSZip
participant Browser
User->>Download: "Click Download Data button"
Download->>Download: "Check if dataset info exists in chartData"
alt No dataset information
Download->>Download: "Call handleDownloadSingleCSV()"
Download->>Utils: "generateOriginalCSV(dataSources, metadata, chartData)"
Utils->>Utils: "Check if dataSources has data"
alt No dataSources available
Utils->>CSVHelper: "processTraceData() for each trace in chartData"
CSVHelper->>CSVHelper: "Extract data directly from trace properties"
CSVHelper-->>Utils: "Return processed trace data"
Utils->>Utils: "Combine all trace data into array"
else dataSources available
Utils->>Utils: "Use existing dataSources"
end
Utils->>CSVHelper: "convertToCSV(array, readme)"
CSVHelper-->>Utils: "Return CSV string"
Utils-->>Download: "Return complete CSV data"
Download->>CSVHelper: "exportCSVFile(csvData, title)"
CSVHelper->>Browser: "Trigger download of single CSV file"
else Dataset information exists
Download->>Download: "Call handleDownloadData()"
Download->>JSZip: "Create new JSZip instance"
loop For each dataset
Download->>Utils: "generateCSVForDataset()"
Utils->>CSVHelper: "processTraceData() for dataset traces"
CSVHelper-->>Utils: "Return processed data"
Utils-->>Download: "Return dataset CSV"
Download->>JSZip: "Add CSV file to zip"
end
Download->>Utils: "generateOriginalCSV() for complete data"
Utils-->>Download: "Return complete CSV"
Download->>JSZip: "Add complete CSV to zip"
Download->>JSZip: "Generate zip blob"
Download->>CSVHelper: "exportZipFile(zipData, title)"
CSVHelper->>Browser: "Trigger download of zip file"
end
3 files reviewed, 4 comments
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
@avoinea ready for review! |
|
@dobri1408 Can you please fix the conflicts. |
No description provided.