Skip to content

Commit 4cd41f7

Browse files
committed
Use components for Selected/Unselected nodes in minimap
1 parent f967946 commit 4cd41f7

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

frontend/src/components/editor/chrome/wrapper/floating-minimap.tsx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,17 @@ const MinimapCell: React.FC<MinimapCellProps> = (props) => {
109109
)}
110110
>
111111
{isSelected ? (
112-
<g transform="translate(0, 0)">
113-
<circle r={getCircleRadius(graph)} fill="currentColor" />
114-
{renderConnections({ cellId, cellPositions, graph })}
115-
</g>
116-
) : isOrphan(graph) ? (
117-
<g transform="translate(0, 0)">
118-
<circle r={getCircleRadius(graph)} fill="currentColor" />
119-
</g>
112+
<SelectedCell
113+
cellId={cellId}
114+
cellPositions={cellPositions}
115+
graph={graph}
116+
/>
120117
) : (
121-
renderConnectionForCell({ cellId, graph, selectedGraph })
118+
<UnselectedCell
119+
cellId={cellId}
120+
graph={graph}
121+
selectedGraph={selectedGraph}
122+
/>
122123
)}
123124
</svg>
124125
</button>
@@ -167,11 +168,11 @@ function codePreview(code: string): string {
167168
}
168169

169170
// Connection paths (for selected)
170-
function renderConnections(options: {
171+
const SelectedCell = (options: {
171172
cellId: CellId;
172173
cellPositions: Record<CellId, number>;
173174
graph: CellGraph;
174-
}) {
175+
}) => {
175176
const { cellId, cellPositions, graph } = options;
176177
const dy = 21;
177178
const paths: React.ReactElement[] = [];
@@ -184,7 +185,7 @@ function renderConnections(options: {
184185
const yDiff = (targetY - currentY) * dy;
185186
paths.push(
186187
<path
187-
key={`up-${cellId}`}
188+
key={`${cellId}-up-${parentCellId}`}
188189
d={`M -3 0 H -7 v ${yDiff} h -4`}
189190
fill="none"
190191
strokeWidth="2"
@@ -201,7 +202,7 @@ function renderConnections(options: {
201202
const yDiff = (targetY - currentY) * dy;
202203
paths.push(
203204
<path
204-
key={`down-${childCellId}`}
205+
key={`${cellId}-down-${childCellId}`}
205206
d={`M 3 0 H 7 v ${yDiff} h 4`}
206207
fill="none"
207208
strokeWidth="2"
@@ -211,8 +212,13 @@ function renderConnections(options: {
211212
}
212213
}
213214

214-
return <g className="pen">{paths}</g>;
215-
}
215+
return (
216+
<g transform="translate(0, 0)">
217+
<circle r={getCircleRadius(graph)} fill="currentColor" />
218+
<g className="pen">{paths}</g>
219+
</g>
220+
);
221+
};
216222

217223
function isOrphan(graph: CellGraph): boolean {
218224
return graph.ancestors.size === 0 && graph.descendants.size === 0;
@@ -223,30 +229,31 @@ function getCircleRadius(graph: CellGraph): number {
223229
}
224230

225231
// Connection indicators for non-selected cells
226-
function renderConnectionForCell(options: {
232+
function UnselectedCell(options: {
227233
cellId: CellId;
228234
graph: CellGraph;
229235
selectedGraph?: CellGraph;
230236
}) {
231237
const { cellId, graph, selectedGraph } = options;
238+
const circleRadius = getCircleRadius(graph);
232239

233240
if (!selectedGraph) {
234241
// if nothing is selected draw the icon centers with
235242
// whiskers indicating any upstream/downstream deps
236243
return drawConnectionGlyph({
244+
circleRadius,
237245
leftWisker: graph.ancestors.size > 0,
238246
rightWisker: graph.descendants.size > 0,
239-
circleRadius: getCircleRadius(graph),
240247
});
241248
}
242249

243250
const isAncestorOfSelected = selectedGraph.ancestors.has(cellId);
244251
const isDescendantOfSelected = selectedGraph.descendants.has(cellId);
245252

246253
return drawConnectionGlyph({
254+
circleRadius,
247255
leftWisker: isDescendantOfSelected,
248256
rightWisker: isAncestorOfSelected,
249-
circleRadius: getCircleRadius(graph),
250257
shift: isAncestorOfSelected
251258
? "left"
252259
: isDescendantOfSelected

0 commit comments

Comments
 (0)