From c0de6a7ac60cf33f2b692078aa5e9ee3dcb64ed2 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 29 May 2024 11:58:09 -0700 Subject: [PATCH] Restructure InsertPanel UI components Signed-off-by: Alex --- .vscode/settings.json | 5 ++- view/src/components/Diagram/Diagram.tsx | 10 +++--- view/src/components/Diagram/InsertPanel.tsx | 39 +++++++++++++-------- view/src/interfaces/InsertItemType.ts | 7 ---- 4 files changed, 33 insertions(+), 28 deletions(-) delete mode 100644 view/src/interfaces/InsertItemType.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 30bf8c2..8b91359 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,8 @@ "out": true // set this to false to include "out" folder in search results }, // Turn off tsc task auto detection since we have the necessary tasks as npm scripts - "typescript.tsc.autoDetect": "off" + "typescript.tsc.autoDetect": "off", + "cSpell.words": [ + "insertable" + ] } \ No newline at end of file diff --git a/view/src/components/Diagram/Diagram.tsx b/view/src/components/Diagram/Diagram.tsx index 75f12eb..855d832 100644 --- a/view/src/components/Diagram/Diagram.tsx +++ b/view/src/components/Diagram/Diagram.tsx @@ -28,8 +28,9 @@ import ReactFlow, { import { InsertPanel, InsertPane, - InstanceItem, - RelationItem, + InstanceInsertItem, + RelationInsertItem, + DefaultRelationIcon, } from "./InsertPanel"; // Icons @@ -41,7 +42,6 @@ import { toPng, toSvg } from "html-to-image"; import Loader from "../shared/Loader"; import ITableData from "../../interfaces/ITableData"; import { LegendItem } from "../../interfaces/LegendItemType"; -import { InsertItem } from "../../interfaces/InsertItemType"; import { VSCodeButton, VSCodeDropdown, @@ -678,12 +678,12 @@ function Diagram({ {insertItems.map((item) => { - return ; + return ; })} {insertItems.map((item) => { - return ; + return ; })} diff --git a/view/src/components/Diagram/InsertPanel.tsx b/view/src/components/Diagram/InsertPanel.tsx index 410d41f..7b1e701 100644 --- a/view/src/components/Diagram/InsertPanel.tsx +++ b/view/src/components/Diagram/InsertPanel.tsx @@ -4,22 +4,34 @@ import invariant from "tiny-invariant"; import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter"; import Node from "reactflow"; -interface InsertItemProps { +interface InstanceInsertItemProps { label: string; - style?: any; + style?: string; } -const InstanceNode: React.FC = (style) => { - return
; -}; +interface RelationInsertItemProps { + label: string; + icon: React.ReactElement +} -export const InstanceItem: React.FC = ({ label, style }) => { +// A default icon for a RelationInsertItem +export const DefaultRelationIcon: React.ReactElement = + +/* + * React component `InstanceInsertItem` is a visual representation of an insertable instance that a user can drag from the instance pane of the instance panel and drop into the diagram view. + * + * @param {string} label - String label for the instance + * @param {string} style - TailwindCSS style to specify style attributes for the InstanceNode + */ +export const InstanceInsertItem: React.FC = ({ label, style }) => { // TODO: Use model's node color property instead of hard-coded color // TODO: handle onDrag Look at react-beautiful-dnd // TODO: handle cloning object after dragging // TODO: handle dropping object after letting go of the mouse - const ref = useRef(null); + const ref = useRef(null); // ref for dragging + const defaultNodeStyle = "bg-[#ff0000]" + // Enable dragging of element useEffect(() => { const el = ref.current; invariant(el); @@ -30,7 +42,7 @@ export const InstanceItem: React.FC = ({ label, style }) => {
@@ -42,12 +54,10 @@ export const InstanceItem: React.FC = ({ label, style }) => { ); }; -export const RelationItem: React.FC = ({ label, style }) => { - // TODO: handle onDrag Look at react-beautiful-dnd - // TODO: handle cloning object after dragging - // TODO: handle dropping object after letting go of the mouse +export const RelationInsertItem: React.FC = ({ label, icon }) => { + // TODO: Find a better way to handle icons const ref = useRef(null); - + useEffect(() => { const el = ref.current; invariant(el); @@ -63,7 +73,7 @@ export const RelationItem: React.FC = ({ label, style }) => { {label} - + {icon}
); @@ -84,7 +94,6 @@ export const InsertPane: React.FC = ({ label, children }) => { }; export const InsertPanel: React.FC = ({ children }) => { - // Refer to http://www.opencaesar.io/oml-tutorials/#tutorial1-create-oml-vocabulary return (
{children} diff --git a/view/src/interfaces/InsertItemType.ts b/view/src/interfaces/InsertItemType.ts deleted file mode 100644 index f70e6e9..0000000 --- a/view/src/interfaces/InsertItemType.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { ReactElement } from "react" - -export type InsertItem = { - label: string, - onItemClicked: () => void, - icon: ReactElement -} \ No newline at end of file