Skip to content

Commit 50b915e

Browse files
committed
fix: dummy data not being saved
1 parent e64d56e commit 50b915e

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

classes/Visualizer/ChartBuilder/src/AIBuilder/DataSource.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,18 @@ export default function DataSource( { chartId, uploadNonce, onDataReady, dataLoa
110110
const [ error, setError ] = useState( null );
111111

112112
// Manual — pre-load sample data for new charts (no initialCsvText means no existing data).
113-
const [ csvText, setCsvText ] = useState( initialCsvText ? '' : SAMPLE_CSV );
114-
const [ sheetRows, setSheetRows ] = useState( initialCsvText ? [] : csvToGrid( SAMPLE_CSV ) );
113+
const [ csvText, setCsvText ] = useState( initialCsvText || SAMPLE_CSV );
114+
const [ sheetRows, setSheetRows ] = useState(
115+
initialCsvText ? csvToGrid( initialCsvText ) : csvToGrid( SAMPLE_CSV )
116+
);
115117
const sheetEditRef = useRef( false );
116118
const sheetHotRef = useRef( null );
117119

118120
// File
119121
const [ file, setFile ] = useState( null );
120122
const fileInputRef = useRef( null );
121-
// Skip the initial auto-upload when pre-loading sample data for a new chart.
122-
const skipUploadRef = useRef( ! initialCsvText );
123+
// Skip the initial auto-upload only when editing existing data.
124+
const skipUploadRef = useRef( !! initialCsvText );
123125

124126
// URL
125127
const [ fileUrl, setFileUrl ] = useState( '' );
@@ -214,7 +216,7 @@ export default function DataSource( { chartId, uploadNonce, onDataReady, dataLoa
214216
// Manual CSV: debounce 700 ms — uploads whenever the full CSV text changes.
215217
useEffect( () => {
216218
if ( disabled ) return;
217-
if ( ( source !== 'manual' && source !== 'sheet' ) || ! csvText.trim() || ! chartId ) return;
219+
if ( ( source !== 'manual' && source !== 'sheet' ) || ! csvText.trim() || ! chartId || ! uploadNonce ) return;
218220
if ( skipUploadRef.current ) { skipUploadRef.current = false; return; }
219221
const trimmed = csvText.trim();
220222
if ( lastCsvRef.current === trimmed ) return;
@@ -233,7 +235,7 @@ export default function DataSource( { chartId, uploadNonce, onDataReady, dataLoa
233235
finally { setLoading( false ); }
234236
}, 700 );
235237
return () => clearTimeout( t );
236-
}, [ source, csvText ] ); // eslint-disable-line react-hooks/exhaustive-deps
238+
}, [ source, csvText, uploadNonce ] ); // eslint-disable-line react-hooks/exhaustive-deps
237239

238240
// File and URL import are manual (button-triggered).
239241
async function handleImportFile() {

0 commit comments

Comments
 (0)