|
1 | 1 | // components/ImportExportStepper/ExportPanel.tsx |
2 | 2 |
|
| 3 | +import { ComponentProps, Fragment } from "react"; |
| 4 | + |
3 | 5 | import { useStepper } from "./StepperContext"; |
4 | 6 | import styles from "./ExportPanel.module.css"; |
5 | 7 | import { ExportLoadingBars } from "./ExportLoadingBars"; |
@@ -181,14 +183,128 @@ export const ExportPanel = () => { |
181 | 183 | </StepDescription> |
182 | 184 | {exportError && <p className={styles.error}>{exportError}</p>} |
183 | 185 | {stepperState === "import_complete" && ( |
184 | | - <button |
185 | | - className={styles.startExportButton} |
186 | | - onClick={handleStartExport} |
187 | | - > |
188 | | - Start Export of Tables and Queries from Splitgraph to Seafowl |
189 | | - </button> |
| 186 | + <ExportPreview |
| 187 | + handleStartExport={handleStartExport} |
| 188 | + tablesToExport={tablesToExport} |
| 189 | + queriesToExport={queriesToExport} |
| 190 | + splitgraphRepository={splitgraphRepository} |
| 191 | + splitgraphNamespace={splitgraphNamespace} |
| 192 | + /> |
190 | 193 | )} |
191 | 194 | {stepperState === "awaiting_export" && <ExportLoadingBars />} |
192 | 195 | </div> |
193 | 196 | ); |
194 | 197 | }; |
| 198 | + |
| 199 | +const ExportPreview = ({ |
| 200 | + handleStartExport, |
| 201 | + tablesToExport, |
| 202 | + queriesToExport, |
| 203 | + splitgraphRepository, |
| 204 | + splitgraphNamespace, |
| 205 | +}: { |
| 206 | + handleStartExport: () => Promise<() => void>; |
| 207 | + tablesToExport: ExportTableInput[]; |
| 208 | + queriesToExport: ExportQueryInput[]; |
| 209 | + splitgraphRepository: string; |
| 210 | + splitgraphNamespace: string; |
| 211 | +}) => { |
| 212 | + return ( |
| 213 | + <> |
| 214 | + <button className={styles.startExportButton} onClick={handleStartExport}> |
| 215 | + Start Export of Tables and Queries from Splitgraph to Seafowl |
| 216 | + </button> |
| 217 | + {/* |
| 218 | + <h3>Debugging</h3> |
| 219 | +
|
| 220 | + <SplitgraphEmbeddedQuery |
| 221 | + importedRepository={{ |
| 222 | + splitgraphNamespace, |
| 223 | + splitgraphRepository, |
| 224 | + }} |
| 225 | + tableName={"Debugging"} |
| 226 | + makeQuery={() => "select 1;"} |
| 227 | + /> */} |
| 228 | + |
| 229 | + <h3>Tables to Export</h3> |
| 230 | + {tablesToExport |
| 231 | + .filter((_) => true) |
| 232 | + .map((exportTable) => ( |
| 233 | + <ExportTablePreview |
| 234 | + key={`export-table-preview-${exportTable.table}`} |
| 235 | + splitgraphNamespace={splitgraphNamespace} |
| 236 | + splitgraphRepository={splitgraphRepository} |
| 237 | + {...exportTable} |
| 238 | + /> |
| 239 | + ))} |
| 240 | + |
| 241 | + <h3>Queries to Export</h3> |
| 242 | + {queriesToExport |
| 243 | + .filter((_) => true) |
| 244 | + .map((exportQuery) => ( |
| 245 | + <ExportQueryPreview |
| 246 | + key={`export-query-preview-${exportQuery.destinationTable}-${exportQuery.destinationSchema}`} |
| 247 | + splitgraphNamespace={splitgraphNamespace} |
| 248 | + splitgraphRepository={splitgraphRepository} |
| 249 | + {...exportQuery} |
| 250 | + /> |
| 251 | + ))} |
| 252 | + </> |
| 253 | + ); |
| 254 | +}; |
| 255 | + |
| 256 | +const ExportQueryPreview = ({ |
| 257 | + splitgraphNamespace, |
| 258 | + splitgraphRepository, |
| 259 | + destinationSchema, |
| 260 | + destinationTable, |
| 261 | + sourceQuery, |
| 262 | +}: ExportQueryInput & { |
| 263 | + splitgraphNamespace: string; |
| 264 | + splitgraphRepository: string; |
| 265 | +}) => { |
| 266 | + return ( |
| 267 | + <> |
| 268 | + <h4> |
| 269 | + <code> |
| 270 | + {destinationSchema}.{destinationTable} |
| 271 | + </code> |
| 272 | + </h4> |
| 273 | + <SplitgraphEmbeddedQuery |
| 274 | + importedRepository={{ |
| 275 | + splitgraphNamespace, |
| 276 | + splitgraphRepository, |
| 277 | + }} |
| 278 | + tableName={destinationTable} |
| 279 | + makeQuery={() => sourceQuery} |
| 280 | + /> |
| 281 | + </> |
| 282 | + ); |
| 283 | +}; |
| 284 | + |
| 285 | +const ExportTablePreview = ({ |
| 286 | + splitgraphNamespace, |
| 287 | + splitgraphRepository, |
| 288 | + table, |
| 289 | +}: { |
| 290 | + splitgraphNamespace: string; |
| 291 | + splitgraphRepository: string; |
| 292 | +} & ExportTableInput) => { |
| 293 | + return ( |
| 294 | + <> |
| 295 | + <h4> |
| 296 | + <code>{table}</code> |
| 297 | + </h4> |
| 298 | + <SplitgraphEmbeddedQuery |
| 299 | + importedRepository={{ |
| 300 | + splitgraphNamespace, |
| 301 | + splitgraphRepository, |
| 302 | + }} |
| 303 | + tableName={table} |
| 304 | + makeQuery={({ splitgraphNamespace, splitgraphRepository }) => |
| 305 | + `SELECT * FROM "${splitgraphNamespace}/${splitgraphRepository}"."${table}";` |
| 306 | + } |
| 307 | + /> |
| 308 | + </> |
| 309 | + ); |
| 310 | +}; |
0 commit comments