Skip to content

Comments

(fix): Make download work when no datasource is present#175

Open
dobri1408 wants to merge 5 commits intodevelopfrom
fix-download-when-no-datasource-present
Open

(fix): Make download work when no datasource is present#175
dobri1408 wants to merge 5 commits intodevelopfrom
fix-download-when-no-datasource-present

Conversation

@dobri1408
Copy link
Contributor

No description provided.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

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:

  1. Enhanced data extraction logic: The processTraceData function in csvString.js now includes a fallback path that can extract data directly from trace properties when dataSources is empty or invalid
  2. Improved CSV generation: The generateOriginalCSV function in utils.js was updated to detect when datasources are missing and process chart traces directly using the enhanced processTraceData function
  3. Parameter propagation: The Download.jsx component now passes the necessary chartData and reactChartEditorLib parameters 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.js for 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
Loading

3 files reviewed, 4 comments

Edit Code Review Bot Settings | Greptile

dobri1408 and others added 4 commits September 16, 2025 08:30
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@dobri1408
Copy link
Contributor Author

@avoinea ready for review!

@avoinea
Copy link
Member

avoinea commented Nov 4, 2025

@dobri1408 Can you please fix the conflicts.

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.

3 participants