Skip to content

Commit

Permalink
scroll and show in edit mode a new table when click create table
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyfish authored and guyb1 committed Sep 14, 2024
1 parent 947821e commit c9a03ec
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/context/chartdb-context/chartdb-provider.tsx
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import { DatabaseEdition } from '@/lib/domain/database-edition';
import { DBSchema, schemaNameToSchemaId } from '@/lib/domain/db-schema';
import { useLocalConfig } from '@/hooks/use-local-config';
import { defaultSchemas } from '@/lib/data/default-schemas';
import { useLayout } from '@/hooks/use-layout';

export const ChartDBProvider: React.FC<React.PropsWithChildren> = ({
children,
@@ -39,6 +40,7 @@ export const ChartDBProvider: React.FC<React.PropsWithChildren> = ({
const [tables, setTables] = useState<DBTable[]>([]);
const [relationships, setRelationships] = useState<DBRelationship[]>([]);
const [viewport, setViewport] = useState({ x: 0, y: 0, zoom: 1 });
const { openTableFromSidebar } = useLayout();

const defaultSchemaName = defaultSchemas[databaseType];

@@ -306,9 +308,10 @@ export const ChartDBProvider: React.FC<React.PropsWithChildren> = ({
isView: false,
};
await addTable(table);
openTableFromSidebar(table.id);

return table;
}, [viewport, tables.length, databaseType, addTable]);
}, [viewport, tables.length, databaseType, addTable, openTableFromSidebar]);

const getTable: ChartDBContext['getTable'] = useCallback(
(id: string) => tables.find((table) => table.id === id) ?? null,
Original file line number Diff line number Diff line change
@@ -29,7 +29,9 @@ export const TableList: React.FC<TableListProps> = ({ tables }) => {

useEffect(() => {
if (openedTableInSidebar) {
scrollToTable(openedTableInSidebar);
setTimeout(() => {
scrollToTable(openedTableInSidebar);
}, 100);
}
}, [openedTableInSidebar, scrollToTable]);

0 comments on commit c9a03ec

Please sign in to comment.