Database diagrams editor that allows you to visualize and design your DB with a single query.
TypeScript databasedbdb-migrationeditorerdmariadbmssqlmysqlpostgresqlreactreact-flowschema-migrationssqlsqlitetypescriptvisualizationxyflow
create diagram dialog refactor
Guy Ben-Aharondbe4b335e1f9
diff --git a/package-lock.json b/package-lock.jsonindex cdf07631..8f292459 100644--- a/package-lock.json+++ b/package-lock.json@@ -16,6 +16,7 @@"@radix-ui/react-collapsible": "^1.1.0","@radix-ui/react-dialog": "^1.1.1","@radix-ui/react-dropdown-menu": "^2.1.1",+ "@radix-ui/react-hover-card": "^1.1.1","@radix-ui/react-icons": "^1.3.0","@radix-ui/react-label": "^2.1.0","@radix-ui/react-menubar": "^1.1.1",@@ -1749,6 +1750,37 @@}}},+ "node_modules/@radix-ui/react-hover-card": {+ "version": "1.1.1",+ "resolved": "https://registry.npmjs.org/@radix-ui/react-hover-card/-/react-hover-card-1.1.1.tgz",+ "integrity": "sha512-IwzAOP97hQpDADYVKrEEHUH/b2LA+9MgB0LgdmnbFO2u/3M5hmEofjjr2M6CyzUblaAqJdFm6B7oFtU72DPXrA==",+ "license": "MIT",+ "dependencies": {+ "@radix-ui/primitive": "1.1.0",+ "@radix-ui/react-compose-refs": "1.1.0",+ "@radix-ui/react-context": "1.1.0",+ "@radix-ui/react-dismissable-layer": "1.1.0",+ "@radix-ui/react-popper": "1.2.0",+ "@radix-ui/react-portal": "1.1.1",+ "@radix-ui/react-presence": "1.1.0",+ "@radix-ui/react-primitive": "2.0.0",+ "@radix-ui/react-use-controllable-state": "1.1.0"+ },+ "peerDependencies": {+ "@types/react": "*",+ "@types/react-dom": "*",+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",+ "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"+ },+ "peerDependenciesMeta": {+ "@types/react": {+ "optional": true+ },+ "@types/react-dom": {+ "optional": true+ }+ }+ },"node_modules/@radix-ui/react-icons": {"version": "1.3.0","resolved": "https://registry.npmjs.org/@radix-ui/react-icons/-/react-icons-1.3.0.tgz",diff --git a/package.json b/package.jsonindex 5bcdf69f..9585bc2f 100644--- a/package.json+++ b/package.json@@ -20,6 +20,7 @@"@radix-ui/react-collapsible": "^1.1.0","@radix-ui/react-dialog": "^1.1.1","@radix-ui/react-dropdown-menu": "^2.1.1",+ "@radix-ui/react-hover-card": "^1.1.1","@radix-ui/react-icons": "^1.3.0","@radix-ui/react-label": "^2.1.0","@radix-ui/react-menubar": "^1.1.1",diff --git a/src/components/hover-card/hover-card.tsx b/src/components/hover-card/hover-card.tsxnew file mode 100644index 00000000..88c80727--- /dev/null+++ b/src/components/hover-card/hover-card.tsx@@ -0,0 +1,27 @@+import React from 'react';+import * as HoverCardPrimitive from '@radix-ui/react-hover-card';++import { cn } from '@/lib/utils';++const HoverCard = HoverCardPrimitive.Root;++const HoverCardTrigger = HoverCardPrimitive.Trigger;++const HoverCardContent = React.forwardRef<+ React.ElementRef<typeof HoverCardPrimitive.Content>,+ React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>+>(({ className, align = 'center', sideOffset = 4, ...props }, ref) => (+ <HoverCardPrimitive.Content+ ref={ref}+ align={align}+ sideOffset={sideOffset}+ className={cn(+ 'z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',+ className+ )}+ {...props}+ />+));+HoverCardContent.displayName = HoverCardPrimitive.Content.displayName;++export { HoverCard, HoverCardTrigger, HoverCardContent };diff --git a/src/dialogs/create-diagram-dialog/create-diagram-dialog-import-database.tsx b/src/dialogs/create-diagram-dialog/create-diagram-dialog-import-database.tsxnew file mode 100644index 00000000..381ece4e--- /dev/null+++ b/src/dialogs/create-diagram-dialog/create-diagram-dialog-import-database.tsx@@ -0,0 +1,232 @@+import React, { useCallback } from 'react';+import { Button } from '@/components/button/button';+import {+ DialogClose,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from '@/components/dialog/dialog';+import { ToggleGroup, ToggleGroupItem } from '@/components/toggle/toggle-group';+import { DatabaseType } from '@/lib/domain/database-type';+import { databaseSecondaryLogoMap } from '@/lib/databases';+import { CodeSnippet } from '@/components/code-snippet/code-snippet';+import { Textarea } from '@/components/textarea/textarea';+import { importMetadataScripts } from '@/lib/data/import-metadata/scripts/scripts';+import {+ DatabaseEdition,+ databaseEditionToImageMap,+ databaseEditionToLabelMap,+ databaseTypeToEditionMap,+} from '@/lib/domain/database-edition';+import {+ Avatar,+ AvatarFallback,+ AvatarImage,+} from '@/components/avatar/avatar';+import { CreateDiagramDialogStep } from './create-diagram-dialog-step';++export interface CreateDiagramDialogImportDatabaseProps {+ setStep: React.Dispatch<React.SetStateAction<CreateDiagramDialogStep>>;+ createNewDiagram: () => void;+ scriptResult: string;+ setScriptResult: React.Dispatch<React.SetStateAction<string>>;+ databaseType: DatabaseType;+ databaseEdition?: DatabaseEdition;+ setDatabaseEdition: React.Dispatch<+ React.SetStateAction<DatabaseEdition | undefined>+ >;+ errorMessage: string;+}++export const CreateDiagramDialogImportDatabase: React.FC<+ CreateDiagramDialogImportDatabaseProps+> = ({+ setScriptResult,+ setStep,+ scriptResult,+ createNewDiagram,+ databaseType,+ databaseEdition,+ setDatabaseEdition,+ errorMessage,+}) => {+ const handleInputChange = useCallback(+ (e: React.ChangeEvent<HTMLTextAreaElement>) => {+ const inputValue = e.target.value;+ setScriptResult(inputValue);+ },+ [setScriptResult]+ );++ const renderHeader = useCallback(() => {+ return (+ <DialogHeader>+ <DialogTitle>Import your Database</DialogTitle>+ </DialogHeader>+ );+ }, []);++ const renderContent = useCallback(() => {+ return (+ <div className="flex w-full flex-1 flex-col gap-6">+ {databaseTypeToEditionMap[databaseType].length > 0 ? (+ <div className="flex flex-col gap-1 md:flex-row">+ <p className="text-sm leading-6 text-muted-foreground">+ Database edition:+ </p>+ <ToggleGroup+ type="single"+ className="ml-1 gap-2"+ value={+ !databaseEdition ? 'regular' : databaseEdition+ }+ onValueChange={(value) => {+ setDatabaseEdition(+ value === 'regular'+ ? undefined+ : (value as DatabaseEdition)+ );+ }}+ >+ <ToggleGroupItem+ value="regular"+ variant="outline"+ className="h-6 gap-1 p-0 px-2 shadow-none"+ >+ <Avatar className="size-4">+ <AvatarImage+ src={+ databaseSecondaryLogoMap[+ databaseType+ ]+ }+ alt="Regular"+ />+ <AvatarFallback>Regular</AvatarFallback>+ </Avatar>+ Regular+ </ToggleGroupItem>+ {databaseTypeToEditionMap[databaseType].map(+ (edition) => (+ <ToggleGroupItem+ value={edition}+ key={edition}+ variant="outline"+ className="h-6 gap-1 p-0 px-2 shadow-none"+ >+ <Avatar className="size-4">+ <AvatarImage+ src={+ databaseEditionToImageMap[+ edition+ ]+ }+ alt={+ databaseEditionToLabelMap[+ edition+ ]+ }+ />+ <AvatarFallback>+ {+ databaseEditionToLabelMap[+ edition+ ]+ }+ </AvatarFallback>+ </Avatar>+ {databaseEditionToLabelMap[edition]}+ </ToggleGroupItem>+ )+ )}+ </ToggleGroup>+ </div>+ ) : null}+ <div className="flex flex-col gap-1">+ <p className="text-sm text-muted-foreground">+ 1. Run this script in your database:+ </p>+ <CodeSnippet+ className="max-h-40 w-full"+ code={importMetadataScripts[databaseType]({+ databaseEdition,+ })}+ />+ </div>+ <div className="flex h-48 flex-col gap-1">+ <p className="text-sm text-muted-foreground">+ 2. Paste the script result here:+ </p>+ <Textarea+ className="w-full flex-1 rounded-md bg-muted p-2 text-sm"+ placeholder="Script result here..."+ value={scriptResult}+ onChange={handleInputChange}+ />+ {errorMessage && (+ <p className="mt-2 text-sm text-red-700">+ {errorMessage}+ </p>+ )}+ </div>+ </div>+ );+ }, [+ databaseEdition,+ databaseType,+ errorMessage,+ handleInputChange,+ scriptResult,+ setDatabaseEdition,+ ]);++ const renderFooter = useCallback(() => {+ return (+ <DialogFooter className="mt-4 flex !justify-between gap-2">+ <div className="flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2">+ <Button+ type="button"+ variant="secondary"+ onClick={() =>+ setStep(CreateDiagramDialogStep.SELECT_DATABASE)+ }+ >+ Back+ </Button>+ </div>+ <div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end sm:space-x-2">+ <DialogClose asChild>+ <Button+ type="button"+ variant="outline"+ onClick={createNewDiagram}+ >+ Empty diagram+ </Button>+ </DialogClose>+ <DialogClose asChild>+ <Button+ type="button"+ variant="default"+ disabled={+ scriptResult.trim().length === 0 ||+ errorMessage.length > 0+ }+ onClick={createNewDiagram}+ >+ Import+ </Button>+ </DialogClose>+ </div>+ </DialogFooter>+ );+ }, [createNewDiagram, errorMessage.length, scriptResult, setStep]);++ return (+ <>+ {renderHeader()}+ {renderContent()}+ {renderFooter()}+ </>+ );+};diff --git a/src/dialogs/create-diagram-dialog/create-diagram-dialog-select-database.tsx b/src/dialogs/create-diagram-dialog/create-diagram-dialog-select-database.tsxnew file mode 100644index 00000000..29354a7f--- /dev/null+++ b/src/dialogs/create-diagram-dialog/create-diagram-dialog-select-database.tsx@@ -0,0 +1,155 @@+import React, { useCallback } from 'react';+import { Button } from '@/components/button/button';+import {+ DialogClose,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from '@/components/dialog/dialog';++import { ToggleGroup, ToggleGroupItem } from '@/components/toggle/toggle-group';+import { DatabaseType } from '@/lib/domain/database-type';+import { databaseLogoMap } from '@/lib/databases';+import { Link } from '@/components/link/link';+import { LayoutGrid } from 'lucide-react';+import { CreateDiagramDialogStep } from './create-diagram-dialog-step';++export interface CreateDiagramDialogSelectDatabaseProps {+ setStep: React.Dispatch<React.SetStateAction<CreateDiagramDialogStep>>;+ databaseType: DatabaseType;+ setDatabaseType: React.Dispatch<React.SetStateAction<DatabaseType>>;+ hasExistingDiagram: boolean;+ createNewDiagram: () => void;+}++export const CreateDiagramDialogSelectDatabase: React.FC<+ CreateDiagramDialogSelectDatabaseProps+> = ({+ setStep,+ databaseType,+ setDatabaseType,+ hasExistingDiagram,+ createNewDiagram,+}) => {+ const renderDatabaseOption = useCallback((type: DatabaseType) => {+ const logo = databaseLogoMap[type];+ return (+ <ToggleGroupItem+ value={type}+ aria-label="Toggle bold"+ className="flex size-20 md:size-32"+ >+ <img src={logo} alt="PostgreSQL" />+ </ToggleGroupItem>+ );+ }, []);++ const renderExamplesOption = useCallback(+ () => (+ <Link href="/examples" className="text-primary hover:text-primary">+ <div className="flex size-20 cursor-pointer flex-col items-center rounded-md border py-3 text-center md:size-32">+ <div className="flex flex-1 items-center">+ <LayoutGrid size={34} />+ </div>+ <div className="flex flex-col-reverse">+ <div className="hidden text-sm text-primary md:flex">+ Check Examples+ </div>+ <div className="flex text-xs text-primary md:hidden">+ Examples+ </div>+ </div>+ </div>+ </Link>+ ),+ []+ );++ const renderHeader = useCallback(() => {+ return (+ <DialogHeader>+ <DialogTitle>What is your Database?</DialogTitle>+ <DialogDescription>+ Each database has its own unique features and capabilities.+ </DialogDescription>+ </DialogHeader>+ );+ }, []);++ const renderContent = useCallback(() => {+ return (+ <div className="flex flex-1 items-center justify-center">+ <ToggleGroup+ value={databaseType}+ onValueChange={(value: DatabaseType) => {+ if (!value) {+ setDatabaseType(DatabaseType.GENERIC);+ } else {+ setDatabaseType(value);+ setStep(CreateDiagramDialogStep.IMPORT_DATABASE);+ }+ }}+ type="single"+ className="grid grid-flow-row grid-cols-3 gap-6"+ >+ {renderDatabaseOption(DatabaseType.MYSQL)}+ {renderDatabaseOption(DatabaseType.POSTGRESQL)}+ {renderDatabaseOption(DatabaseType.MARIADB)}+ {renderDatabaseOption(DatabaseType.SQLITE)}+ {renderDatabaseOption(DatabaseType.SQL_SERVER)}+ {renderExamplesOption()}+ </ToggleGroup>+ </div>+ );+ }, [+ databaseType,+ renderDatabaseOption,+ renderExamplesOption,+ setDatabaseType,+ setStep,+ ]);++ const renderFooter = useCallback(() => {+ return (+ <DialogFooter className="mt-4 flex !justify-between gap-2">+ {hasExistingDiagram ? (+ <DialogClose asChild>+ <Button type="button" variant="secondary">+ Cancel+ </Button>+ </DialogClose>+ ) : (+ <div></div>+ )}+ <div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end sm:space-x-2">+ <Button+ type="button"+ variant="outline"+ onClick={createNewDiagram}+ >+ Empty diagram+ </Button>+ <Button+ type="button"+ variant="default"+ disabled={databaseType === DatabaseType.GENERIC}+ onClick={() =>+ setStep(CreateDiagramDialogStep.IMPORT_DATABASE)+ }+ >+ Continue+ </Button>+ </div>+ </DialogFooter>+ );+ }, [createNewDiagram, databaseType, hasExistingDiagram, setStep]);++ return (+ <>+ {renderHeader()}+ {renderContent()}+ {renderFooter()}+ </>+ );+};diff --git a/src/dialogs/create-diagram-dialog/create-diagram-dialog-step.ts b/src/dialogs/create-diagram-dialog/create-diagram-dialog-step.tsnew file mode 100644index 00000000..ce57df1d--- /dev/null+++ b/src/dialogs/create-diagram-dialog/create-diagram-dialog-step.ts@@ -0,0 +1,4 @@+export enum CreateDiagramDialogStep {+ SELECT_DATABASE = 'SELECT_DATABASE',+ IMPORT_DATABASE = 'IMPORT_DATABASE',+}diff --git a/src/dialogs/create-diagram-dialog/create-diagram-dialog.tsx b/src/dialogs/create-diagram-dialog/create-diagram-dialog.tsxindex 1e35cd63..a54ec800 100644--- a/src/dialogs/create-diagram-dialog/create-diagram-dialog.tsx+++ b/src/dialogs/create-diagram-dialog/create-diagram-dialog.tsx@@ -1,20 +1,7 @@import React, { useCallback, useEffect, useState } from 'react';-import { Button } from '@/components/button/button';-import {- Dialog,- DialogClose,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogTitle,-} from '@/components/dialog/dialog';+import { Dialog, DialogContent } from '@/components/dialog/dialog';import { DialogProps } from '@radix-ui/react-dialog';-import { ToggleGroup, ToggleGroupItem } from '@/components/toggle/toggle-group';import { DatabaseType } from '@/lib/domain/database-type';-import { databaseLogoMap, databaseSecondaryLogoMap } from '@/lib/databases';-import { CodeSnippet } from '@/components/code-snippet/code-snippet';-import { Textarea } from '@/components/textarea/textarea';import { useStorage } from '@/hooks/use-storage';import { Diagram, loadFromDatabaseMetadata } from '@/lib/domain/diagram';import { useNavigate } from 'react-router-dom';@@ -27,25 +14,10 @@ import {import { generateId } from '@/lib/utils';import { useChartDB } from '@/hooks/use-chartdb';import { useDialog } from '@/hooks/use-dialog';-import { importMetadataScripts } from '@/lib/data/import-metadata/scripts/scripts';-import { Link } from '@/components/link/link';-import { LayoutGrid } from 'lucide-react';-import {- DatabaseEdition,- databaseEditionToImageMap,- databaseEditionToLabelMap,- databaseTypeToEditionMap,-} from '@/lib/domain/database-edition';-import {- Avatar,- AvatarFallback,- AvatarImage,-} from '@/components/avatar/avatar';--enum CreateDiagramDialogStep {- SELECT_DATABASE = 'SELECT_DATABASE',- IMPORT_DATABASE = 'IMPORT_DATABASE',-}+import { DatabaseEdition } from '@/lib/domain/database-edition';+import { CreateDiagramDialogSelectDatabase } from './create-diagram-dialog-select-database';+import { CreateDiagramDialogStep } from './create-diagram-dialog-step';+import { CreateDiagramDialogImportDatabase } from './create-diagram-dialog-import-database';const errorScriptOutputMessage ='Invalid JSON. Please correct it or contact us at [email protected] for help.';@@ -112,11 +84,6 @@ export const CreateDiagramDialog: React.FC<CreateDiagramDialogProps> = ({const hasExistingDiagram = (diagramId ?? '').trim().length !== 0;- const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {- const inputValue = e.target.value;- setScriptResult(inputValue);- };-const createNewDiagram = useCallback(async () => {let diagram: Diagram = {id: generateId(),@@ -161,319 +128,6 @@ export const CreateDiagramDialog: React.FC<CreateDiagramDialogProps> = ({errorMessage,]);- const renderDatabaseOption = useCallback((type: DatabaseType) => {- const logo = databaseLogoMap[type];- return (- <ToggleGroupItem- value={type}- aria-label="Toggle bold"- className="flex size-20 md:size-32"- >- <img src={logo} alt="PostgreSQL" />- </ToggleGroupItem>- );- }, []);-- const renderExamplesOption = useCallback(- () => (- <div- className="flex size-20 cursor-pointer flex-col items-center rounded-md border py-3 text-center md:size-32"- onClick={() => window.open('/examples')}- >- <div className="flex flex-1 items-center">- <Link href="/examples" className="text-sm text-primary">- <LayoutGrid size={34} />- </Link>- </div>- <div className="flex flex-col-reverse">- <Link- href="/examples"- className="hidden text-sm text-primary md:flex"- >- Check Examples- </Link>- <Link- href="/examples"- className="flex text-xs text-primary md:hidden"- >- Examples- </Link>- </div>- </div>- ),- []- );-- const renderHeader = useCallback(() => {- switch (step) {- case CreateDiagramDialogStep.SELECT_DATABASE:- return (- <DialogHeader>- <DialogTitle>What is your Database?</DialogTitle>- <DialogDescription>- Each database has its own unique features and- capabilities.- </DialogDescription>- </DialogHeader>- );- case CreateDiagramDialogStep.IMPORT_DATABASE:- return (- <DialogHeader>- <DialogTitle>Import your Database</DialogTitle>- </DialogHeader>- );- default:- return null;- }- }, [step]);-- const renderContent = useCallback(() => {- switch (step) {- case CreateDiagramDialogStep.SELECT_DATABASE:- return (- <div className="flex flex-1 items-center justify-center">- <ToggleGroup- value={databaseType}- onValueChange={(value: DatabaseType) => {- if (!value) {- setDatabaseType(DatabaseType.GENERIC);- } else {- setDatabaseType(value);- setStep(- CreateDiagramDialogStep.IMPORT_DATABASE- );- }- }}- type="single"- className="grid grid-flow-row grid-cols-3 gap-6"- >- {renderDatabaseOption(DatabaseType.MYSQL)}- {renderDatabaseOption(DatabaseType.POSTGRESQL)}- {renderDatabaseOption(DatabaseType.MARIADB)}- {renderDatabaseOption(DatabaseType.SQLITE)}- {renderDatabaseOption(DatabaseType.SQL_SERVER)}- {renderExamplesOption()}- </ToggleGroup>- </div>- );- case CreateDiagramDialogStep.IMPORT_DATABASE:- return (- <div className="flex w-full flex-1 flex-col gap-6">- {databaseTypeToEditionMap[databaseType].length > 0 ? (- <div className="flex flex-col gap-1 md:flex-row">- <p className="text-sm leading-6 text-muted-foreground">- Database edition:- </p>- <ToggleGroup- type="single"- className="ml-1 gap-2"- value={- !databaseEdition- ? 'regular'- : databaseEdition- }- onValueChange={(value) => {- setDatabaseEdition(- value === 'regular'- ? undefined- : (value as DatabaseEdition)- );- }}- >- <ToggleGroupItem- value="regular"- variant="outline"- className="h-6 gap-1 p-0 px-2 shadow-none"- >- <Avatar className="size-4">- <AvatarImage- src={- databaseSecondaryLogoMap[- databaseType- ]- }- alt="Regular"- />- <AvatarFallback>- Regular- </AvatarFallback>- </Avatar>- Regular- </ToggleGroupItem>- {databaseTypeToEditionMap[databaseType].map(- (edition) => (- <ToggleGroupItem- value={edition}- key={edition}- variant="outline"- className="h-6 gap-1 p-0 px-2 shadow-none"- >- <Avatar className="size-4">- <AvatarImage- src={- databaseEditionToImageMap[- edition- ]- }- alt={- databaseEditionToLabelMap[- edition- ]- }- />- <AvatarFallback>- {- databaseEditionToLabelMap[- edition- ]- }- </AvatarFallback>- </Avatar>- {- databaseEditionToLabelMap[- edition- ]- }- </ToggleGroupItem>- )- )}- </ToggleGroup>- </div>- ) : null}- <div className="flex flex-col gap-1">- <p className="text-sm text-muted-foreground">- 1. Run this script in your database:- </p>- <CodeSnippet- className="max-h-40 w-full"- code={importMetadataScripts[databaseType]({- databaseEdition,- })}- />- </div>- <div className="flex h-48 flex-col gap-1">- <p className="text-sm text-muted-foreground">- 2. Paste the script result here:- </p>- <Textarea- className="w-full flex-1 rounded-md bg-muted p-2 text-sm"- placeholder="Script result here..."- value={scriptResult}- onChange={handleInputChange}- />- {errorMessage && (- <p className="mt-2 text-sm text-red-700">- {errorMessage}- </p>- )}- </div>- </div>- );- default:- return null;- }- }, [- errorMessage,- databaseEdition,- step,- databaseType,- scriptResult,- renderDatabaseOption,- setDatabaseType,- renderExamplesOption,- ]);-- const renderFooter = useCallback(() => {- switch (step) {- case CreateDiagramDialogStep.SELECT_DATABASE:- return (- <DialogFooter className="mt-4 flex !justify-between gap-2">- {hasExistingDiagram ? (- <DialogClose asChild>- <Button type="button" variant="secondary">- Cancel- </Button>- </DialogClose>- ) : (- <div></div>- )}- <div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end sm:space-x-2">- <Button- type="button"- variant="outline"- onClick={createNewDiagram}- >- Empty diagram- </Button>- <Button- type="button"- variant="default"- disabled={databaseType === DatabaseType.GENERIC}- onClick={() =>- setStep(- CreateDiagramDialogStep.IMPORT_DATABASE- )- }- >- Continue- </Button>- </div>- </DialogFooter>- );- case CreateDiagramDialogStep.IMPORT_DATABASE:- return (- <DialogFooter className="mt-4 flex !justify-between gap-2">- <div className="flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2">- <Button- type="button"- variant="secondary"- onClick={() =>- setStep(- CreateDiagramDialogStep.SELECT_DATABASE- )- }- >- Back- </Button>- </div>- <div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end sm:space-x-2">- <DialogClose asChild>- <Button- type="button"- variant="outline"- onClick={createNewDiagram}- >- Empty diagram- </Button>- </DialogClose>- <DialogClose asChild>- <Button- type="button"- variant="default"- disabled={- scriptResult.trim().length === 0 ||- errorMessage.length > 0- }- onClick={createNewDiagram}- >- Import- </Button>- </DialogClose>- </div>- </DialogFooter>- );- default:- return null;- }- }, [- step,- databaseType,- scriptResult,- createNewDiagram,- hasExistingDiagram,- errorMessage,- ]);-return (<Dialog{...dialog}@@ -491,9 +145,26 @@ export const CreateDiagramDialog: React.FC<CreateDiagramDialogProps> = ({className="flex w-[90vw] flex-col overflow-y-auto xl:min-w-[45vw]"showClose={hasExistingDiagram}>- {renderHeader()}- {renderContent()}- {renderFooter()}+ {step === CreateDiagramDialogStep.SELECT_DATABASE ? (+ <CreateDiagramDialogSelectDatabase+ createNewDiagram={createNewDiagram}+ databaseType={databaseType}+ hasExistingDiagram={hasExistingDiagram}+ setDatabaseType={setDatabaseType}+ setStep={setStep}+ />+ ) : (+ <CreateDiagramDialogImportDatabase+ createNewDiagram={createNewDiagram}+ databaseEdition={databaseEdition}+ databaseType={databaseType}+ errorMessage={errorMessage}+ scriptResult={scriptResult}+ setDatabaseEdition={setDatabaseEdition}+ setStep={setStep}+ setScriptResult={setScriptResult}+ />+ )}</DialogContent></Dialog>);