|
| 1 | +import styles from "./EmbeddedPreviews.module.css"; |
| 2 | +import type { |
| 3 | + ExportTable, |
| 4 | + ExportQueryInput, |
| 5 | + ExportTableInput, |
| 6 | +} from "../../types"; |
| 7 | + |
| 8 | +import { EmbedPreviewTableOrQuery } from "../EmbeddedQuery/EmbeddedQuery"; |
| 9 | +import { ComponentProps } from "react"; |
| 10 | + |
| 11 | +export const EmbeddedTablePreviewHeadingAndDescription = ({ |
| 12 | + exportComplete, |
| 13 | +}: { |
| 14 | + exportComplete: boolean; |
| 15 | +}) => { |
| 16 | + return ( |
| 17 | + <> |
| 18 | + {!exportComplete ? ( |
| 19 | + <> |
| 20 | + <h2 className={styles.embeddedPreviewHeading}>Tables to Export</h2> |
| 21 | + <p className={styles.embeddedPreviewDescription}> |
| 22 | + These are the tables that we'll export from Splitgraph to Seafowl. |
| 23 | + You can query them in Splitgraph now, and then when the export is |
| 24 | + complete, you'll be able to query them in Seafowl too. |
| 25 | + </p> |
| 26 | + </> |
| 27 | + ) : ( |
| 28 | + <> |
| 29 | + <h2 className={styles.embeddedPreviewHeading}>Exported Tables</h2> |
| 30 | + <p className={styles.embeddedPreviewDescription}> |
| 31 | + We successfully exported the tables to Seafowl, so now you can query |
| 32 | + them in Seafowl too. |
| 33 | + </p> |
| 34 | + </> |
| 35 | + )} |
| 36 | + </> |
| 37 | + ); |
| 38 | +}; |
| 39 | + |
| 40 | +export const EmbeddedTablePreviews = ({ |
| 41 | + tablesToExport, |
| 42 | + splitgraphRepository, |
| 43 | + splitgraphNamespace, |
| 44 | + useLoadingOrCompleted, |
| 45 | +}: { |
| 46 | + tablesToExport: ExportTableInput[]; |
| 47 | + splitgraphRepository: string; |
| 48 | + splitgraphNamespace: string; |
| 49 | + useLoadingOrCompleted: ComponentProps< |
| 50 | + typeof EmbedPreviewTableOrQuery |
| 51 | + >["useLoadingOrCompleted"]; |
| 52 | +}) => { |
| 53 | + return ( |
| 54 | + <> |
| 55 | + {tablesToExport.map((exportTable) => ( |
| 56 | + <EmbedPreviewTableOrQuery |
| 57 | + key={`export-table-preview-${exportTable.table}`} |
| 58 | + exportInput={exportTable} |
| 59 | + importedRepository={{ splitgraphNamespace, splitgraphRepository }} |
| 60 | + makeQuery={({ splitgraphNamespace, splitgraphRepository, table }) => |
| 61 | + `SELECT * FROM "${splitgraphNamespace}/${splitgraphRepository}"."${table}";` |
| 62 | + } |
| 63 | + useLoadingOrCompleted={useLoadingOrCompleted} |
| 64 | + makeMatchInputToExported={(exportTableInput) => (exportTable) => { |
| 65 | + return ( |
| 66 | + exportTable.destinationSchema === exportTableInput.repository && |
| 67 | + exportTable.destinationTable === exportTableInput.table |
| 68 | + ); |
| 69 | + }} |
| 70 | + /> |
| 71 | + ))} |
| 72 | + </> |
| 73 | + ); |
| 74 | +}; |
| 75 | + |
| 76 | +export const EmbeddedQueryPreviewHeadingAndDescription = ({ |
| 77 | + exportComplete, |
| 78 | +}: { |
| 79 | + exportComplete: boolean; |
| 80 | +}) => { |
| 81 | + return ( |
| 82 | + <> |
| 83 | + {" "} |
| 84 | + {!exportComplete ? ( |
| 85 | + <> |
| 86 | + <h2 className={styles.embeddedPreviewHeading}>Queries to Export</h2> |
| 87 | + <p className={styles.embeddedPreviewDescription}> |
| 88 | + We've prepared a few queries to export from Splitgraph to Seafowl, |
| 89 | + so that we can use them to render the charts that we want. |
| 90 | + Splitgraph will execute the query and insert its result into |
| 91 | + Seafowl. You can query them in Splitgraph now, and then when the |
| 92 | + export is complete, you'll be able to query them in Seafowl too. |
| 93 | + </p> |
| 94 | + </> |
| 95 | + ) : ( |
| 96 | + <> |
| 97 | + <h2 className={styles.embeddedPreviewHeading}>Exported Queries</h2> |
| 98 | + <p className={styles.embeddedPreviewDescription}> |
| 99 | + We successfully exported these queries from Splitgraph to Seafowl, |
| 100 | + so now you can query them in Seafowl too.{" "} |
| 101 | + <em className={styles.note}> |
| 102 | + Note: If some queries failed to export, it's probably because they |
| 103 | + had empty result sets (e.g. the table of issue reactions) |
| 104 | + </em> |
| 105 | + </p> |
| 106 | + </> |
| 107 | + )} |
| 108 | + </> |
| 109 | + ); |
| 110 | +}; |
| 111 | + |
| 112 | +export const EmbeddedQueryPreviews = ({ |
| 113 | + queriesToExport, |
| 114 | + splitgraphRepository, |
| 115 | + splitgraphNamespace, |
| 116 | + useLoadingOrCompleted, |
| 117 | +}: { |
| 118 | + queriesToExport: ExportQueryInput[]; |
| 119 | + splitgraphRepository: string; |
| 120 | + splitgraphNamespace: string; |
| 121 | + useLoadingOrCompleted: ComponentProps< |
| 122 | + typeof EmbedPreviewTableOrQuery |
| 123 | + >["useLoadingOrCompleted"]; |
| 124 | +}) => { |
| 125 | + return ( |
| 126 | + <> |
| 127 | + {queriesToExport.map((exportQuery) => ( |
| 128 | + <EmbedPreviewTableOrQuery |
| 129 | + key={`export-query-preview-${exportQuery.destinationTable}-${exportQuery.destinationSchema}`} |
| 130 | + exportInput={exportQuery} |
| 131 | + importedRepository={{ splitgraphNamespace, splitgraphRepository }} |
| 132 | + // This is the query we run on Splitgraph that we exported to Seafowl |
| 133 | + makeQuery={({ sourceQuery }) => sourceQuery} |
| 134 | + // But once it's exported, we can just select from its table in Seafowl (and |
| 135 | + // besides, the sourceQuery might not be compatible with Seafowl anyway) |
| 136 | + makeSeafowlQuery={({ destinationSchema, destinationTable }) => |
| 137 | + `SELECT * FROM "${destinationSchema}"."${destinationTable}";` |
| 138 | + } |
| 139 | + useLoadingOrCompleted={useLoadingOrCompleted} |
| 140 | + makeMatchInputToExported={(exportQueryInput) => |
| 141 | + (exportTable: ExportTable) => { |
| 142 | + return ( |
| 143 | + exportTable.destinationSchema === |
| 144 | + exportQueryInput.destinationSchema && |
| 145 | + exportTable.destinationTable === |
| 146 | + exportQueryInput.destinationTable |
| 147 | + ); |
| 148 | + }} |
| 149 | + /> |
| 150 | + ))} |
| 151 | + </> |
| 152 | + ); |
| 153 | +}; |
0 commit comments