Skip to content

Commit

Permalink
add CommonDialogProvider and improve error handling in ScreenDropZone
Browse files Browse the repository at this point in the history
  • Loading branch information
sokphaladam committed Jan 10, 2025
1 parent bbe50fe commit eaf3fe8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/app/(theme)/playground/client/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
DropdownMenuSeparator,
} from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";
import { CommonDialogProvider } from "@/components/common-dialog";

function OverlayAround({
x,
Expand Down Expand Up @@ -324,10 +325,12 @@ export default function PlaygroundEditorBody({

return (
<>
<Script src="/sqljs/sql-wasm.js" onReady={onReady} />
<ScreenDropZone onFileDrop={setHandler} />
<Onboarding />
{dom}
<CommonDialogProvider>
<Script src="/sqljs/sql-wasm.js" onReady={onReady} />
<ScreenDropZone onFileDrop={setHandler} />
<Onboarding />
{dom}
</CommonDialogProvider>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function ERDTableColumn({
}) {
return (
<TableRow className="group relative text-xs">
<TableCell className="p-0 pl-0 pr-6 font-light h-[30px] text-sm pl-2 font-mono">
<TableCell className="p-0 pr-6 font-light h-[30px] text-sm pl-2 font-mono">
<BaseHandle
id={column.title}
type="target"
Expand All @@ -23,11 +23,11 @@ export default function ERDTableColumn({
{column.pk && <Key size={15} color={"rgb(153 27 27)"} />}
{column.fk && <Key size={15} color={"rgb(245 158 11)"} />}
</div>
<div>{column.title}</div>
<div className="max-w-[120px] truncate">{column.title}</div>
</div>
</TableCell>
<TableCell className="p-0 pr-0 text-right font-thin h-[30px] text-sm">
<div className="h-[30px] flex items-center justify-end pr-2 font-mono text-muted-foreground">
<div className="h-[30px] flex items-center justify-end pr-2 font-mono text-muted-foreground max-w-[75px] truncate">
{column.type}
</div>
<BaseHandle
Expand Down
22 changes: 13 additions & 9 deletions src/components/gui/tabs/relational-diagram-tab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ function mapSchema(

initialEdges.push({
type: "smoothstep",
markerStart: {
markerEnd: {
type: MarkerType.ArrowClosed,
width: 14,
height: 14,
},
id: `${item.name}-${constraint.foreignKey.foreignTableName}`,
target: item.name,
source: constraint.foreignKey.foreignTableName || "",
targetHandle: columnName,
sourceHandle: constraint.foreignKey.foreignColumns
source: item.name,
target: constraint.foreignKey.foreignTableName || "",
sourceHandle: columnName,
targetHandle: constraint.foreignKey.foreignColumns
? constraint.foreignKey.foreignColumns[0]
: "",
animated: true,
Expand Down Expand Up @@ -203,12 +203,16 @@ function mapSchema(
// Rearrange the nodes with relationship
// We need to find the position
const relationshipRightPosition =
(Math.max(...layoutRelationship.nodes.map((x) => x.position.x)) ?? 0) +
NODE_MARGIN +
MAX_NODE_WIDTH;
layoutRelationship.nodes.length === 0
? 0
: (Math.max(...layoutRelationship.nodes.map((x) => x.position.x)) ?? 0) +
NODE_MARGIN +
MAX_NODE_WIDTH;

const relationshipTopPosition =
Math.min(...layoutRelationship.nodes.map((x) => x.position.y)) ?? 0;
layoutRelationship.nodes.length === 0
? 0
: Math.min(...layoutRelationship.nodes.map((x) => x.position.y)) ?? 0;

// Calculate estimate area of the nodes without relationship
const area =
Expand Down
15 changes: 13 additions & 2 deletions src/components/screen-dropzone.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"use client";

import { useEffect } from "react";
import { useCommonDialog } from "./common-dialog";

interface Props {
onFileDrop: (handler: FileSystemFileHandle) => void;
}

export default function ScreenDropZone({ onFileDrop }: Props) {
const { showDialog } = useCommonDialog();

useEffect(() => {
const dropEventHandler = (e: DragEvent) => {
e.preventDefault();
Expand All @@ -17,7 +20,15 @@ export default function ScreenDropZone({ onFileDrop }: Props) {
if (!fileList) return;
if (fileList.length === 0) return;

(fileList[0] as any).getAsFileSystemHandle().then(onFileDrop);
try {
(fileList[0] as any).getAsFileSystemHandle().then(onFileDrop);
} catch (error) {
showDialog({
destructive: true,
title: "Warning",
content: "Your browser are not support. please use another browser.",
});
}
};

const dragEventHandler = (e: DragEvent) => {
Expand All @@ -33,7 +44,7 @@ export default function ScreenDropZone({ onFileDrop }: Props) {
window.document.removeEventListener("dragover", dragEventHandler);
window.document.removeEventListener("drop", dropEventHandler);
};
}, [onFileDrop]);
}, [onFileDrop, showDialog]);

return <></>;
}

0 comments on commit eaf3fe8

Please sign in to comment.