From 07dc4eace087d72efce88b80f8311828004f813f Mon Sep 17 00:00:00 2001 From: Jonathan Fishner Date: Mon, 3 Nov 2025 12:03:25 +0200 Subject: [PATCH] fix: Add Transactional/Analytical database categorization tabs (#965) * fix: Add Transactional/Analytical database categorization tabs * fix --------- Co-authored-by: Guy Ben-Aharon --- .../select-database-content.tsx | 146 +++++++++++++----- 1 file changed, 110 insertions(+), 36 deletions(-) diff --git a/src/dialogs/create-diagram-dialog/select-database/select-database-content.tsx b/src/dialogs/create-diagram-dialog/select-database/select-database-content.tsx index ae30d1e6..ce5615e8 100644 --- a/src/dialogs/create-diagram-dialog/select-database/select-database-content.tsx +++ b/src/dialogs/create-diagram-dialog/select-database/select-database-content.tsx @@ -1,20 +1,28 @@ -import React, { useMemo, useState } from 'react'; +import React, { useCallback, useMemo, useState } from 'react'; import { ToggleGroup } from '@/components/toggle/toggle-group'; import { DatabaseType } from '@/lib/domain/database-type'; import { DatabaseOption } from './database-option'; import { ExampleOption } from './example-option'; import { Button } from '@/components/button/button'; import { ChevronDown, ChevronUp } from 'lucide-react'; +import { + Tabs, + TabsContent, + TabsList, + TabsTrigger, +} from '@/components/tabs/tabs'; export interface SelectDatabaseContentProps { databaseType: DatabaseType; setDatabaseType: React.Dispatch>; - onContinue: () => void; + onContinue: (selectedDatabaseType: DatabaseType) => void; } const ROW_SIZE = 3; const ROWS = 2; const TOTAL_SLOTS = ROW_SIZE * ROWS; -const SUPPORTED_DB_TYPES: DatabaseType[] = [ + +// Transactional databases - OLTP systems optimized for frequent read/write operations +const TRANSACTIONAL_DB_TYPES: DatabaseType[] = [ DatabaseType.MYSQL, DatabaseType.POSTGRESQL, DatabaseType.MARIADB, @@ -22,69 +30,87 @@ const SUPPORTED_DB_TYPES: DatabaseType[] = [ DatabaseType.SQL_SERVER, DatabaseType.ORACLE, DatabaseType.COCKROACHDB, - DatabaseType.CLICKHOUSE, ]; +// Analytical databases - OLAP systems optimized for complex queries and analytics +const ANALYTICAL_DB_TYPES: DatabaseType[] = [DatabaseType.CLICKHOUSE]; + export const SelectDatabaseContent: React.FC = ({ databaseType, setDatabaseType, onContinue, }) => { + const [activeTab, setActiveTab] = useState<'transactional' | 'analytical'>( + 'transactional' + ); const [currentRow, setCurrentRow] = useState(0); + + const currentDbTypes = + activeTab === 'transactional' + ? TRANSACTIONAL_DB_TYPES + : ANALYTICAL_DB_TYPES; + const currentDatabasesTypes = useMemo( () => - SUPPORTED_DB_TYPES.slice( + currentDbTypes.slice( currentRow * ROW_SIZE, currentRow * ROW_SIZE + TOTAL_SLOTS ), - [currentRow] + [currentRow, currentDbTypes] ); const hasNextRow = useMemo( - () => (currentRow + 1) * ROW_SIZE < SUPPORTED_DB_TYPES.length, - [currentRow] + () => (currentRow + 1) * ROW_SIZE < currentDbTypes.length, + [currentRow, currentDbTypes] ); const hasPreviousRow = useMemo(() => currentRow > 0, [currentRow]); - const toggleRow = () => { + const toggleRow = useCallback(() => { if (currentRow === 0 && hasNextRow) { setCurrentRow(currentRow + 1); } else if (currentRow > 0) { setCurrentRow(currentRow - 1); } - }; + }, [currentRow, hasNextRow]); - return ( -
- { - if (!value) { - setDatabaseType(DatabaseType.GENERIC); - } else { - setDatabaseType(value); - onContinue(); - } - }} - type="single" - className="grid grid-flow-row grid-cols-3 gap-6" - > - {Array.from({ length: TOTAL_SLOTS }).map((_, index) => - currentDatabasesTypes?.[index] ? ( - - ) : null - )} + const handleTabChange = useCallback((value: string) => { + setActiveTab(value as 'transactional' | 'analytical'); + setCurrentRow(0); // Reset to first row when switching tabs + }, []); -
+ const renderDatabaseGrid = useCallback( + () => ( +
+ { + if (!value) { + setDatabaseType(DatabaseType.GENERIC); + } else { + setDatabaseType(value); + onContinue(value); + } + }} + type="single" + className="grid grid-flow-row grid-cols-3 content-start gap-4" + > + {Array.from({ length: TOTAL_SLOTS }).map((_, index) => + currentDatabasesTypes?.[index] ? ( + + ) : null + )} + + +
{hasNextRow || hasPreviousRow ? (
+ ), + [ + databaseType, + currentDatabasesTypes, + hasNextRow, + hasPreviousRow, + onContinue, + setDatabaseType, + toggleRow, + currentRow, + ] + ); + + return ( +
+ + + + Transactional + + + Analytical + + + + {renderDatabaseGrid()} + + + {renderDatabaseGrid()} + +
); };