collapse all tables/relationships button

This commit is contained in:
Guy Ben-Aharon
2024-08-23 14:37:46 +03:00
parent c223393e89
commit 7ec8783fb3
4 changed files with 26 additions and 3 deletions

View File

@@ -6,9 +6,11 @@ export type SidebarSection = 'tables' | 'relationships';
export interface LayoutContext { export interface LayoutContext {
openedTableInSidebar: string | undefined; openedTableInSidebar: string | undefined;
openTableFromSidebar: (tableId: string) => void; openTableFromSidebar: (tableId: string) => void;
closeAllTablesInSidebar: () => void;
openedRelationshipInSidebar: string | undefined; openedRelationshipInSidebar: string | undefined;
openRelationshipFromSidebar: (relationshipId: string) => void; openRelationshipFromSidebar: (relationshipId: string) => void;
closeAllRelationshipsInSidebar: () => void;
selectedSidebarSection: SidebarSection; selectedSidebarSection: SidebarSection;
selectSidebarSection: (section: SidebarSection) => void; selectSidebarSection: (section: SidebarSection) => void;
@@ -20,7 +22,9 @@ export const layoutContext = createContext<LayoutContext>({
openedRelationshipInSidebar: undefined, openedRelationshipInSidebar: undefined,
openRelationshipFromSidebar: emptyFn, openRelationshipFromSidebar: emptyFn,
closeAllRelationshipsInSidebar: emptyFn,
selectSidebarSection: emptyFn, selectSidebarSection: emptyFn,
openTableFromSidebar: emptyFn, openTableFromSidebar: emptyFn,
closeAllTablesInSidebar: emptyFn,
}); });

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { layoutContext, SidebarSection } from './layout-context'; import { LayoutContext, layoutContext, SidebarSection } from './layout-context';
export const LayoutProvider: React.FC<React.PropsWithChildren> = ({ export const LayoutProvider: React.FC<React.PropsWithChildren> = ({
children, children,
@@ -12,6 +12,11 @@ export const LayoutProvider: React.FC<React.PropsWithChildren> = ({
const [selectedSidebarSection, setSelectedSidebarSection] = const [selectedSidebarSection, setSelectedSidebarSection] =
React.useState<SidebarSection>('tables'); React.useState<SidebarSection>('tables');
const closeAllTablesInSidebar: LayoutContext['closeAllTablesInSidebar'] =
() => setOpenedTableInSidebar('');
const closeAllRelationshipsInSidebar: LayoutContext['closeAllRelationshipsInSidebar'] =
() => setOpenedRelationshipInSidebar('');
return ( return (
<layoutContext.Provider <layoutContext.Provider
value={{ value={{
@@ -21,6 +26,8 @@ export const LayoutProvider: React.FC<React.PropsWithChildren> = ({
selectSidebarSection: setSelectedSidebarSection, selectSidebarSection: setSelectedSidebarSection,
openedRelationshipInSidebar, openedRelationshipInSidebar,
openRelationshipFromSidebar: setOpenedRelationshipInSidebar, openRelationshipFromSidebar: setOpenedRelationshipInSidebar,
closeAllTablesInSidebar,
closeAllRelationshipsInSidebar,
}} }}
> >
{children} {children}

View File

@@ -5,12 +5,14 @@ import { Input } from '@/components/input/input';
import { RelationshipList } from './relationship-list/relationship-list'; import { RelationshipList } from './relationship-list/relationship-list';
import { useChartDB } from '@/hooks/use-chartdb'; import { useChartDB } from '@/hooks/use-chartdb';
import { DBRelationship } from '@/lib/domain/db-relationship'; import { DBRelationship } from '@/lib/domain/db-relationship';
import { useLayout } from '@/hooks/use-layout';
export interface RelationshipsSectionProps {} export interface RelationshipsSectionProps {}
export const RelationshipsSection: React.FC<RelationshipsSectionProps> = () => { export const RelationshipsSection: React.FC<RelationshipsSectionProps> = () => {
const { relationships } = useChartDB(); const { relationships } = useChartDB();
const [filterText, setFilterText] = React.useState(''); const [filterText, setFilterText] = React.useState('');
const { closeAllRelationshipsInSidebar } = useLayout();
const filteredRelationships = useMemo(() => { const filteredRelationships = useMemo(() => {
const filter: (relationship: DBRelationship) => boolean = ( const filter: (relationship: DBRelationship) => boolean = (
@@ -26,7 +28,11 @@ export const RelationshipsSection: React.FC<RelationshipsSectionProps> = () => {
<section className="flex flex-col px-2 overflow-hidden flex-1"> <section className="flex flex-col px-2 overflow-hidden flex-1">
<div className="flex items-center py-1 justify-between gap-4"> <div className="flex items-center py-1 justify-between gap-4">
<div> <div>
<Button variant="ghost" className="p-0 h-8 w-8"> <Button
variant="ghost"
className="p-0 h-8 w-8"
onClick={closeAllRelationshipsInSidebar}
>
<ListCollapse className="w-4 h-4" /> <ListCollapse className="w-4 h-4" />
</Button> </Button>
</div> </div>

View File

@@ -6,11 +6,13 @@ import { Input } from '@/components/input/input';
import { DBTable } from '@/lib/domain/db-table'; import { DBTable } from '@/lib/domain/db-table';
import { useChartDB } from '@/hooks/use-chartdb'; import { useChartDB } from '@/hooks/use-chartdb';
import { useLayout } from '@/hooks/use-layout';
export interface TablesSectionProps {} export interface TablesSectionProps {}
export const TablesSection: React.FC<TablesSectionProps> = () => { export const TablesSection: React.FC<TablesSectionProps> = () => {
const { createTable, tables } = useChartDB(); const { createTable, tables } = useChartDB();
const { closeAllTablesInSidebar } = useLayout();
const [filterText, setFilterText] = React.useState(''); const [filterText, setFilterText] = React.useState('');
const filteredTables = useMemo(() => { const filteredTables = useMemo(() => {
@@ -25,7 +27,11 @@ export const TablesSection: React.FC<TablesSectionProps> = () => {
<section className="flex flex-col px-2 overflow-hidden flex-1"> <section className="flex flex-col px-2 overflow-hidden flex-1">
<div className="flex items-center py-1 justify-between gap-4"> <div className="flex items-center py-1 justify-between gap-4">
<div> <div>
<Button variant="ghost" className="p-0 h-8 w-8"> <Button
variant="ghost"
className="p-0 h-8 w-8"
onClick={closeAllTablesInSidebar}
>
<ListCollapse className="w-4 h-4" /> <ListCollapse className="w-4 h-4" />
</Button> </Button>
</div> </div>