Skip to content

Commit f89505d

Browse files
authored
Merge pull request #169 from ls1intum/fix--connection-new-edge-selected
Fix connection new edge selected, edit edge popover spacing, sidebar new element id for methods and attributes
2 parents 22f0547 + 4032a26 commit f89505d

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

library/lib/components/Sidebar.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,31 @@ const DraggableGhost: React.FC<DraggableGhostProps> = ({
136136
return
137137
}
138138

139+
// Deep clone defaultData to avoid mutating the original config
140+
const defaultData = structuredClone(dropElementConfig.defaultData)
141+
142+
// Assign new IDs to methods and attributes
143+
if (defaultData.methods) {
144+
defaultData.methods = (defaultData.methods as Array<object>).map(
145+
(method) => ({
146+
...method,
147+
id: generateUUID(),
148+
})
149+
)
150+
}
151+
if (defaultData.attributes) {
152+
defaultData.attributes = (defaultData.attributes as Array<object>).map(
153+
(attribute) => ({
154+
...attribute,
155+
id: generateUUID(),
156+
})
157+
)
158+
}
159+
139160
// Prepare the drop data including offset adjustments
140161
const dropData: DropNodeData = {
141162
type: dropElementConfig.type,
142-
data: dropElementConfig.defaultData,
163+
data: defaultData,
143164
offsetX: clickOffset.x / transformScale,
144165
offsetY: clickOffset.y / transformScale,
145166
}
@@ -182,7 +203,7 @@ const DraggableGhost: React.FC<DraggableGhostProps> = ({
182203
height: dropElementConfig.height,
183204
type: dropData.type,
184205
position: { ...position },
185-
data: { ...dropElementConfig.defaultData, ...dropData.data },
206+
data: { ...defaultData, ...dropData.data },
186207
parentId: parentId,
187208
measured: {
188209
width: dropElementConfig.width,
@@ -191,8 +212,6 @@ const DraggableGhost: React.FC<DraggableGhostProps> = ({
191212
selected: false,
192213
}
193214

194-
// Adjust position relative to parent if a parent exists
195-
196215
// Update nodes and resize parent nodes if necessary
197216
const updatedNodes = structuredClone([...nodes, newNode])
198217
if (parentId) {

library/lib/components/popovers/edgePopovers/EdgeEditPopover.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const EdgeEditPopover: React.FC<PopoverProps> = ({ elementId }) => {
3939
const targetName = (targetNode?.data?.name as string) ?? "Target"
4040

4141
return (
42-
<>
42+
<Box sx={{ display: "flex", flexDirection: "column", gap: 1 }}>
4343
{/* Swap icon for source/target swap */}
4444
{handleSwap && (
4545
<Box sx={{ display: "flex", justifyContent: "flex-end" }}>
@@ -112,6 +112,6 @@ export const EdgeEditPopover: React.FC<PopoverProps> = ({ elementId }) => {
112112
size="small"
113113
fullWidth
114114
/>
115-
</>
115+
</Box>
116116
)
117117
}

library/lib/constants/dropElementConfig.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export const dropElementConfigs: Record<DiagramType, DropElementConfig[]> = {
5151
},
5252
{
5353
type: "class",
54-
5554
width: droppedElementWidth,
5655
height: 140,
5756
defaultData: {
@@ -68,7 +67,6 @@ export const dropElementConfigs: Record<DiagramType, DropElementConfig[]> = {
6867
},
6968
{
7069
type: "class",
71-
7270
width: droppedElementWidth,
7371
height: 110,
7472
defaultData: {

library/lib/hooks/useConnect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const useConnect = () => {
8080
...connection,
8181
id: generateUUID(),
8282
type: EDGE_TYPE,
83-
selected: true,
83+
selected: false,
8484
}
8585

8686
addEdge(newEdge)
@@ -156,7 +156,7 @@ export const useConnect = () => {
156156
const onEdgesDelete: OnEdgesDelete = useCallback(() => {
157157
startEdge.current = null
158158
connectionStartParams.current = null
159-
}, [])
159+
}, [setEdges])
160160

161161
return { onConnect, onConnectEnd, onConnectStart, onEdgesDelete }
162162
}

0 commit comments

Comments
 (0)