mirror of
https://github.com/chartdb/chartdb.git
synced 2025-10-23 07:11:56 +00:00
fix for schemas
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import type { DBTable } from '@/lib/domain/db-table';
|
import type { DBTable } from '@/lib/domain/db-table';
|
||||||
import type { Area } from '@/lib/domain/area';
|
import type { Area } from '@/lib/domain/area';
|
||||||
import { calcTableHeight } from '@/lib/domain/db-table';
|
import {
|
||||||
|
calcTableHeight,
|
||||||
|
shouldShowTablesBySchemaFilter,
|
||||||
|
} from '@/lib/domain/db-table';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a table is inside an area based on their positions and dimensions
|
* Check if a table is inside an area based on their positions and dimensions
|
||||||
@@ -53,9 +56,31 @@ const findContainingArea = (table: DBTable, areas: Area[]): Area | null => {
|
|||||||
*/
|
*/
|
||||||
export const updateTablesParentAreas = (
|
export const updateTablesParentAreas = (
|
||||||
tables: DBTable[],
|
tables: DBTable[],
|
||||||
areas: Area[]
|
areas: Area[],
|
||||||
|
hiddenTableIds?: string[],
|
||||||
|
filteredSchemas?: string[]
|
||||||
): DBTable[] => {
|
): DBTable[] => {
|
||||||
return tables.map((table) => {
|
return tables.map((table) => {
|
||||||
|
// Check if table is hidden by direct hiding or schema filter
|
||||||
|
const isHiddenDirectly = hiddenTableIds?.includes(table.id) ?? false;
|
||||||
|
const isHiddenBySchema = !shouldShowTablesBySchemaFilter(
|
||||||
|
table,
|
||||||
|
filteredSchemas
|
||||||
|
);
|
||||||
|
const isHidden = isHiddenDirectly || isHiddenBySchema;
|
||||||
|
|
||||||
|
// If table is hidden, remove it from any area
|
||||||
|
if (isHidden) {
|
||||||
|
if (table.parentAreaId !== null) {
|
||||||
|
return {
|
||||||
|
...table,
|
||||||
|
parentAreaId: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For visible tables, find containing area as before
|
||||||
const containingArea = findContainingArea(table, areas);
|
const containingArea = findContainingArea(table, areas);
|
||||||
const newParentAreaId = containingArea?.id || null;
|
const newParentAreaId = containingArea?.id || null;
|
||||||
|
|
||||||
|
@@ -132,15 +132,13 @@ export const CanvasFilter: React.FC<CanvasFilterProps> = ({ onClose }) => {
|
|||||||
// Convert to tree nodes
|
// Convert to tree nodes
|
||||||
const nodes: TreeNode<NodeType, NodeContext>[] = [];
|
const nodes: TreeNode<NodeType, NodeContext>[] = [];
|
||||||
|
|
||||||
// Sort areas by order or name
|
// Sort all areas by order or name (including empty ones)
|
||||||
const sortedAreas = areas
|
const sortedAreas = areas.sort((a, b) => {
|
||||||
.filter((area) => tablesByArea.has(area.id))
|
if (a.order !== undefined && b.order !== undefined) {
|
||||||
.sort((a, b) => {
|
return a.order - b.order;
|
||||||
if (a.order !== undefined && b.order !== undefined) {
|
}
|
||||||
return a.order - b.order;
|
return a.name.localeCompare(b.name);
|
||||||
}
|
});
|
||||||
return a.name.localeCompare(b.name);
|
|
||||||
});
|
|
||||||
|
|
||||||
sortedAreas.forEach((area) => {
|
sortedAreas.forEach((area) => {
|
||||||
const areaTables = tablesByArea.get(area.id) || [];
|
const areaTables = tablesByArea.get(area.id) || [];
|
||||||
@@ -400,13 +398,16 @@ export const CanvasFilter: React.FC<CanvasFilterProps> = ({ onClose }) => {
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="size-7 h-fit p-0"
|
className="size-7 h-fit p-0"
|
||||||
|
disabled={!node.children || node.children.length === 0}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
// Toggle all tables in this area
|
// Toggle all tables in this area
|
||||||
const allHidden =
|
const allHidden =
|
||||||
node.children?.every((child) =>
|
(node.children?.length > 0 &&
|
||||||
hiddenTableIds?.includes(child.id)
|
node.children?.every((child) =>
|
||||||
) ?? false;
|
hiddenTableIds?.includes(child.id)
|
||||||
|
)) ||
|
||||||
|
false;
|
||||||
|
|
||||||
node.children?.forEach((child) => {
|
node.children?.forEach((child) => {
|
||||||
if (child.type === 'table') {
|
if (child.type === 'table') {
|
||||||
|
@@ -154,6 +154,21 @@ const areaToAreaNode = (
|
|||||||
const tablesInArea = tables.filter(
|
const tablesInArea = tables.filter(
|
||||||
(table) => table.parentAreaId === area.id
|
(table) => table.parentAreaId === area.id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Don't hide area if it has no tables (empty area)
|
||||||
|
if (tablesInArea.length === 0) {
|
||||||
|
return {
|
||||||
|
id: area.id,
|
||||||
|
type: 'area',
|
||||||
|
position: { x: area.x, y: area.y },
|
||||||
|
data: { area },
|
||||||
|
width: area.width,
|
||||||
|
height: area.height,
|
||||||
|
zIndex: -10,
|
||||||
|
hidden: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const allTablesHidden = tablesInArea.every(
|
const allTablesHidden = tablesInArea.every(
|
||||||
(table) =>
|
(table) =>
|
||||||
hiddenTableIds?.includes(table.id) ||
|
hiddenTableIds?.includes(table.id) ||
|
||||||
@@ -490,7 +505,12 @@ export const Canvas: React.FC<CanvasProps> = ({ initialTables }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkParentAreas = debounce(() => {
|
const checkParentAreas = debounce(() => {
|
||||||
const updatedTables = updateTablesParentAreas(tables, areas);
|
const updatedTables = updateTablesParentAreas(
|
||||||
|
tables,
|
||||||
|
areas,
|
||||||
|
hiddenTableIds,
|
||||||
|
filteredSchemas
|
||||||
|
);
|
||||||
const needsUpdate: Array<{
|
const needsUpdate: Array<{
|
||||||
id: string;
|
id: string;
|
||||||
parentAreaId: string | null;
|
parentAreaId: string | null;
|
||||||
@@ -530,7 +550,14 @@ export const Canvas: React.FC<CanvasProps> = ({ initialTables }) => {
|
|||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
checkParentAreas();
|
checkParentAreas();
|
||||||
}, [tablePositions, areas, updateTablesState, tables]);
|
}, [
|
||||||
|
tablePositions,
|
||||||
|
areas,
|
||||||
|
updateTablesState,
|
||||||
|
tables,
|
||||||
|
hiddenTableIds,
|
||||||
|
filteredSchemas,
|
||||||
|
]);
|
||||||
|
|
||||||
const onConnectHandler = useCallback(
|
const onConnectHandler = useCallback(
|
||||||
async (params: AddEdgeParams) => {
|
async (params: AddEdgeParams) => {
|
||||||
|
Reference in New Issue
Block a user