Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added class to sub sidebar to use style #56

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/CanvasWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export const CanvasWidget = ({

if (!!node.onNodeDrop) node?.onNodeDrop(monitor, node, engine);
},
[]
[engine]
);

// can drop custom hook
const [{}, dropRef] = useDrop({
const [, dropRef] = useDrop({
accept: CanvasDropTypes.CANVAS_NODE,
// canDrop: () => true,
drop: onDrop,
Expand Down
23 changes: 13 additions & 10 deletions src/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment, useEffect, useState } from 'react';
import React, { Fragment, useCallback, useEffect, useState } from 'react';
import { Box, List } from '@mui/material';

import SidebarItem from './SidebarItem';
Expand All @@ -25,19 +25,22 @@ const Sidebar = ({ engine, sidebarNodes, updateSelection }: ISidebarProps) => {
),
};

const handleSelection = (selectedID: DefaultSidebarNodeTypes) => {
if (currentState) {
stateMap[currentState as DefaultSidebarNodeTypes]?.onExit();
}
const handleSelection = useCallback(
(selectedID: DefaultSidebarNodeTypes) => {
if (currentState) {
stateMap[currentState as DefaultSidebarNodeTypes]?.onExit();
}

setCurrentState(selectedID);
stateMap[selectedID]?.onEnter();
updateSelection(selectedID);
};
setCurrentState(selectedID);
stateMap[selectedID]?.onEnter();
updateSelection(selectedID);
},
[currentState, stateMap, updateSelection]
);

useEffect(() => {
handleSelection(DefaultSidebarNodeTypes.PANNING);
}, []);
}, [handleSelection]);

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/SidebarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const SidebarItem = ({
selected,
handleSelection,
}: SidebarItemProps) => {
const [{}, dragRef, dragPreview] = useDrag(
const [, dragRef, dragPreview] = useDrag(
() => ({
type: CanvasDropTypes.CANVAS_NODE,
item: node,
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/SubSidebarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const SubSidebarItem = ({
selected,
handleSelection,
}: ISubSidebarItemProps) => {
const [{}, dragRef, dragPreview] = useDrag(
const [, dragRef, dragPreview] = useDrag(
() => ({
type: CanvasDropTypes.CANVAS_NODE,
item: node,
Expand Down
2 changes: 1 addition & 1 deletion src/components/sidebar/SubSiderBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const SubSiderBar = ({ nodes, show = false }: ISubSidebar) => {
return (
<>
<Box className="sub-sidebar">
<Collapse orientation="horizontal" in={show}>
<Collapse orientation="horizontal" in={show} className="wrapper">
<List disablePadding component="nav">
{nodes.map(node => (
<Fragment key={node.id}>
Expand Down
11 changes: 6 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const MetaDiagram = forwardRef(
) => {
const classes = useStyles();
const linkRef = React.useRef<any>();
const onMountRef = React.useRef<Function | undefined>(onMount);

// initialize custom diagram state
let state = new DefaultState(globalProps?.createLink);
Expand All @@ -77,7 +78,7 @@ const MetaDiagram = forwardRef(
// Sets up the diagram engine
// By using useMemo, we ensure that the createEngine() function is only called when the component mounts,
// and the same engine instance is reused on subsequent re-renders.
const engine = useMemo(() => createEngine(), [metaNodes, metaLinks]);
const engine = useMemo(() => createEngine(), []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we removing these?


if (metaCallback === undefined) {
metaCallback = (node: any) => {
Expand Down Expand Up @@ -227,13 +228,13 @@ const MetaDiagram = forwardRef(
}

useEffect(() => {
if (onMount === undefined) {
onMount = (engine: any) => {
if (onMountRef.current === undefined) {
onMountRef.current = (engine: any) => {
console.log(engine);
};
}
onMount(engine);
}, []);
onMountRef.current(engine);
}, [engine]);

// expose api
const addNode = (node: any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/react-diagrams/state/CreateLinkState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class CreateLinkState extends State<DiagramEngine> {
} else if (
element instanceof PortModel &&
this.sourcePort &&
element != this.sourcePort
element !== this.sourcePort
) {
if (this.sourcePort.canLinkToPort(element)) {
if (!this.link) return;
Expand Down
Loading