import React, { 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'; export interface SelectDatabaseContentProps { databaseType: DatabaseType; setDatabaseType: React.Dispatch>; onContinue: () => void; } const ROW_SIZE = 3; const ROWS = 2; const TOTAL_SLOTS = ROW_SIZE * ROWS; const SUPPORTED_DB_TYPES: DatabaseType[] = [ DatabaseType.MYSQL, DatabaseType.POSTGRESQL, DatabaseType.MARIADB, DatabaseType.SQLITE, DatabaseType.SQL_SERVER, DatabaseType.ORACLE, DatabaseType.COCKROACHDB, DatabaseType.CLICKHOUSE, ]; export const SelectDatabaseContent: React.FC = ({ databaseType, setDatabaseType, onContinue, }) => { const [currentRow, setCurrentRow] = useState(0); const currentDatabasesTypes = useMemo( () => SUPPORTED_DB_TYPES.slice( currentRow * ROW_SIZE, currentRow * ROW_SIZE + TOTAL_SLOTS ), [currentRow] ); const hasNextRow = useMemo( () => (currentRow + 1) * ROW_SIZE < SUPPORTED_DB_TYPES.length, [currentRow] ); const hasPreviousRow = useMemo(() => currentRow > 0, [currentRow]); const toggleRow = () => { if (currentRow === 0 && hasNextRow) { setCurrentRow(currentRow + 1); } else if (currentRow > 0) { setCurrentRow(currentRow - 1); } }; 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 )}
{hasNextRow || hasPreviousRow ? ( ) : null}
); };