Spaces:
Running
Running
File size: 6,095 Bytes
56bf851 826a975 56bf851 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
import React, { useState, useEffect } from "react";
import Papa from "papaparse";
import { config as envConfig, debugLog } from "../utils/config";
const Step3 = ({
uploadedFile,
fileMetadata,
config,
setConfig,
stepNumber,
stepTitle,
stepIcon,
enabled = true,
// Add validation props
apiKey,
isApiKeyValid,
s3Link,
}) => {
const [columns, setColumns] = useState([]);
useEffect(() => {
if (uploadedFile) {
debugLog("Parsing uploaded file for columns", {
fileName: uploadedFile.name,
});
// Parse the uploaded file to get column names
Papa.parse(uploadedFile, {
complete: (results) => {
if (results.data.length > 0) {
const headers = Object.keys(results.data[0]);
setColumns(headers);
debugLog("Columns extracted from file", { columns: headers });
// Set first column as default target if not already set
if (!config.targetColumn && headers.length > 0) {
setConfig((prev) => ({
...prev,
targetColumn: headers[0],
fileSizeBytes: fileMetadata?.fileSizeBytes || 0,
sourceFileRows: fileMetadata?.sourceFileRows || 0,
}));
}
// Set default number of rows from environment config if not already set
if (!config.numRows || config.numRows === 100) {
setConfig((prev) => ({
...prev,
numRows: envConfig.defaultNumRecords,
fileSizeBytes: fileMetadata?.fileSizeBytes || 0,
sourceFileRows: fileMetadata?.sourceFileRows || 0,
}));
debugLog("Set default number of rows", {
numRows: envConfig.defaultNumRecords,
});
}
}
},
header: true,
skipEmptyLines: true,
});
}
}, [
uploadedFile,
config.targetColumn,
config.numRows,
setConfig,
fileMetadata?.fileSizeBytes,
fileMetadata?.sourceFileRows,
]);
const handleNumRowsChange = (e) => {
// Prevent action if step is disabled
if (!enabled) return;
const numRows = parseInt(e.target.value, 10);
debugLog("Number of rows changed", { numRows });
setConfig((prev) => ({
...prev,
numRows: numRows,
fileSizeBytes: fileMetadata?.fileSizeBytes || 0,
sourceFileRows: fileMetadata?.sourceFileRows || 0,
}));
};
const handleTargetColumnChange = (e) => {
// Prevent action if step is disabled
if (!enabled) return;
const targetColumn = e.target.value;
debugLog("Target column changed", { targetColumn });
setConfig((prev) => ({
...prev,
targetColumn: targetColumn,
fileSizeBytes: fileMetadata?.fileSizeBytes || 0,
sourceFileRows: fileMetadata?.sourceFileRows || 0,
}));
};
return (
<div className="step-container fade-in">
<div className="step-header">
<h2>
<span className="step-number">{stepNumber}</span>
{stepIcon} {stepTitle}
</h2>
<p>
Configure the parameters for your synthetic data generation process
</p>
</div>
<div className="step-body">
<div className="config-section">
<h3>
<span className="config-icon">π</span>
Data Generation Settings
</h3>
<div className="form-group">
<label htmlFor="numRows">Number of Rows to Generate</label>
<div className="slider-container">
<input
id="numRows"
type="range"
min="10"
max="1000"
step="10"
value={config.numRows}
onChange={handleNumRowsChange}
className="slider"
disabled={false}
/>
<div className="slider-value">{config.numRows} rows</div>
</div>
</div>
<div className="form-group">
<label htmlFor="targetColumn">Target Column</label>
<select
id="targetColumn"
className="form-input"
value={config.targetColumn}
onChange={handleTargetColumnChange}
disabled={columns.length === 0}
>
<option value="">Select a target column...</option>
{columns.map((column, index) => (
<option key={index} value={column}>
{column}
</option>
))}
</select>
</div>
</div>
{columns.length > 0 && (
<div className="config-section">
<h3>
<span className="config-icon">π</span>
Available Columns ({columns.length})
</h3>
<div
style={{
display: "flex",
flexWrap: "wrap",
gap: "0.5rem",
marginTop: "1rem",
}}
>
{columns.map((column, index) => (
<span
key={index}
style={{
background:
config.targetColumn === column
? "var(--primary-color)"
: "var(--bg-tertiary)",
color:
config.targetColumn === column
? "white"
: "var(--text-secondary)",
padding: "0.5rem 0.75rem",
borderRadius: "6px",
fontSize: "0.8rem",
fontWeight: "500",
border:
config.targetColumn === column
? "none"
: "1px solid var(--border-color)",
}}
>
{column}
</span>
))}
</div>
</div>
)}
</div>
</div>
);
};
export default Step3;
|