MCPcopy
hub / github.com/chartdb/chartdb / ExportSQLDialog

Function ExportSQLDialog

src/dialogs/export-sql-dialog/export-sql-dialog.tsx:41–342  ·  view source on GitHub ↗
({
    dialog,
    targetDatabaseType,
})

Source from the content-addressed store, hash-verified

39}
40
41export const ExportSQLDialog: React.FC<ExportSQLDialogProps> = ({
42 dialog,
43 targetDatabaseType,
44}) => {
45 const { closeExportSQLDialog } = useDialog();
46 const { currentDiagram } = useChartDB();
47 const { filter } = useDiagramFilter();
48 const { t } = useTranslation();
49 const [script, setScript] = React.useState<string>();
50 const [error, setError] = React.useState<boolean>(false);
51 const [isScriptLoading, setIsScriptLoading] =
52 React.useState<boolean>(false);
53 const [useAIExport, setUseAIExport] = React.useState<boolean>(false);
54 const abortControllerRef = useRef<AbortController | null>(null);
55
56 // Check if a deterministic export path is available
57 const hasDeterministicPath = useMemo(() => {
58 return (
59 targetDatabaseType === DatabaseType.GENERIC ||
60 currentDiagram.databaseType === targetDatabaseType ||
61 hasCrossDialectSupport(
62 currentDiagram.databaseType,
63 targetDatabaseType
64 )
65 );
66 }, [targetDatabaseType, currentDiagram.databaseType]);
67
68 // Show toggle only for cross-dialect exports where both options are available
69 const showExportModeToggle = useMemo(() => {
70 return (
71 hasDeterministicPath &&
72 currentDiagram.databaseType !== targetDatabaseType &&
73 targetDatabaseType !== DatabaseType.GENERIC
74 );
75 }, [hasDeterministicPath, currentDiagram.databaseType, targetDatabaseType]);
76
77 const exportSQLScript = useCallback(async () => {
78 const filteredDiagram: Diagram = {
79 ...currentDiagram,
80 tables: currentDiagram.tables?.filter((table) =>
81 filterTable({
82 table: {
83 id: table.id,
84 schema: table.schema,
85 },
86 filter,
87 options: {
88 defaultSchema: defaultSchemas[targetDatabaseType],
89 },
90 })
91 ),
92 relationships: currentDiagram.relationships?.filter((rel) => {
93 const sourceTable = currentDiagram.tables?.find(
94 (t) => t.id === rel.sourceTableId
95 );
96 const targetTable = currentDiagram.tables?.find(
97 (t) => t.id === rel.targetTableId
98 );

Callers

nothing calls this directly

Calls 9

useDialogFunction · 0.90
useChartDBFunction · 0.90
useDiagramFilterFunction · 0.90
hasCrossDialectSupportFunction · 0.90
filterTableFunction · 0.90
filterRelationshipFunction · 0.90
exportBaseSQLFunction · 0.90
exportSQLFunction · 0.90
fetchScriptFunction · 0.85

Tested by

no test coverage detected