Skip to content

Commit 879d5d1

Browse files
committed
fix: expand/collapse subgardens
1 parent 360b3b8 commit 879d5d1

File tree

7 files changed

+34
-25
lines changed

7 files changed

+34
-25
lines changed

app/src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const HomePage = () => (
111111
key={feature.title}
112112
className={cn(
113113
"group relative flex flex-col items-center space-y-4 text-center",
114-
"rounded-lg border bg-background p-6 shadow-lg transition-shadow hover:shadow-xl"
114+
"rounded-lg border bg-background p-6 shadow-lg transition-shadow hover:shadow-xl",
115115
)}
116116
>
117117
<div className="rounded-full bg-primary/10 p-4 text-primary">

app/src/components/core/OptionsPanel/OptionsPanel.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ const OptionsPanel = ({
4141
expandSubgardens,
4242
setExpandSubgardens,
4343
}: Props) => {
44-
const [minimized, setMinimized] = useState(true);
44+
// TODO local storage
45+
const [minimized, setMinimized] = useState(false);
4546
const [moving, setMoving] = useState(false);
4647
const [position, setPosition] = useState({ x: 0, y: 0 });
4748

@@ -54,7 +55,7 @@ const OptionsPanel = ({
5455
const store = useStoreApi();
5556
const { isInteractive, minZoomReached, maxZoomReached } = useStore(
5657
selector,
57-
shallow
58+
shallow,
5859
);
5960
const { zoomIn, zoomOut, fitView } = useReactFlow();
6061

@@ -104,9 +105,10 @@ const OptionsPanel = ({
104105
() => [
105106
{
106107
id: "expand-subgardens",
107-
label: expandSubgardens ? "Expand subgardens" : "Condense subgardens",
108+
label: expandSubgardens ? "Condense subgardens" : "Expand subgardens",
108109
onClick: () => {
109110
setExpandSubgardens(!expandSubgardens);
111+
110112
// force re-layout
111113
setInitialized(false);
112114
},
@@ -164,14 +166,14 @@ const OptionsPanel = ({
164166
expandSubgardens,
165167
setExpandSubgardens,
166168
setInitialized,
167-
]
169+
],
168170
);
169171

170172
return (
171173
<div
172174
ref={panelRef}
173175
className={cn(
174-
"absolute top-0 left-0 z-50 m-4 flex flex-col overflow-hidden rounded-lg border border-border bg-card shadow-xl transition-all"
176+
"absolute top-0 left-0 z-50 m-4 flex flex-col overflow-hidden rounded-lg border border-border bg-card shadow-xl transition-all",
175177
)}
176178
style={{
177179
width: 200,
@@ -182,7 +184,7 @@ const OptionsPanel = ({
182184
<div
183185
className={cn(
184186
"group z-50 flex items-center justify-between border-b px-4 py-2",
185-
moving ? "cursor-move" : "cursor-grab"
187+
moving ? "cursor-move" : "cursor-grab",
186188
)}
187189
onMouseDown={(e) => {
188190
e.preventDefault();

app/src/components/visualizer/EditorActions/EditorActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const EditorActions = ({ schemaText, setSchemaText, setError }: Props) => {
3232
!Array.isArray(parsedJson.categories)
3333
) {
3434
throw new Error(
35-
"Invalid schema: missing required fields (name, version, or categories)"
35+
"Invalid schema: missing required fields (name, version, or categories)",
3636
);
3737
}
3838

app/src/components/visualizer/GardenFlowInner/GardenFlowInner.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const GardenFlowInner = ({ gardens }: Props) => {
9191
const { nodes: initialNodes, edges: initialEdges } = gardenToFlow(
9292
activeGarden,
9393
containerWidth,
94-
{ expandSubgardens }
94+
{ expandSubgardens },
9595
);
9696

9797
if (!initialized && initialNodes.length > 0 && initialEdges.length > 0) {
@@ -182,7 +182,7 @@ const GardenFlowInner = ({ gardens }: Props) => {
182182
if (clickedNode.data?.isExpandedSubgardenLabel) {
183183
gardenName = (clickedNode.data?.label as string).replace(
184184
" (Expanded)",
185-
""
185+
"",
186186
);
187187
}
188188

app/src/components/visualizer/Visualizer/Visualizer.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ interface Props {
3030
const Visualizer = ({ gardens }: Props) => {
3131
const { setActiveGarden } = useGardenStore();
3232

33+
// Make garden data available globally for subgarden expansion
34+
useEffect(() => {
35+
if (typeof window !== "undefined") {
36+
window.gardenData = gardens;
37+
}
38+
}, [gardens]);
39+
3340
// load garden from local storage on initial render
3441
useEffect(() => {
3542
if (typeof window !== "undefined") {

app/src/components/visualizer/customNodes/NodeTypes/NodeTypes.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ const NodeTypes = () => ({
3737
default: ({ data }: { data: NodeData }) => {
3838
// check if there are any connections
3939
const hasTopTargets = data.targetConnections?.some(
40-
(id) => id.includes("top") || !id.includes("position")
40+
(id) => id.includes("top") || !id.includes("position"),
4141
);
4242
const hasBottomTargets = data.targetConnections?.some((id) =>
43-
id.includes("bottom")
43+
id.includes("bottom"),
4444
);
4545
const hasLeftTargets = data.targetConnections?.some((id) =>
46-
id.includes("left")
46+
id.includes("left"),
4747
);
4848
const hasTopSources = data.sourceConnections?.some((id) =>
49-
id.includes("top")
49+
id.includes("top"),
5050
);
5151
const hasBottomSources = data.sourceConnections?.some(
52-
(id) => id.includes("bottom") || !id.includes("position")
52+
(id) => id.includes("bottom") || !id.includes("position"),
5353
);
5454

5555
return (

app/src/lib/util/flow.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const generateId = (type: string, name: string): string => {
3636
};
3737

3838
const getNodePositions = (
39-
type: string
39+
type: string,
4040
): { sourcePosition?: Position; targetPosition?: Position } => {
4141
return match(type)
4242
.with(NODE_TYPES.GARDEN, () => ({
@@ -69,7 +69,7 @@ interface FlowOptions {
6969
export const gardenToFlow = (
7070
garden: GardenTypes,
7171
width = 1600,
72-
options: FlowOptions = {}
72+
options: FlowOptions = {},
7373
): { nodes: Node[]; edges: Edge[] } => {
7474
// create a shallow copy to prevent reference issues
7575
const gardenCopy = { ...garden };
@@ -109,7 +109,7 @@ export const gardenToFlow = (
109109
gardenCopy.supergardens.forEach((supergarden: any, index: number) => {
110110
const supergardenId = generateId(
111111
NODE_TYPES.SUPERGARDEN,
112-
supergarden.name
112+
supergarden.name,
113113
);
114114
const xOffset = -400 + index * 150; // Position supergardens to the left and above
115115

@@ -350,13 +350,13 @@ export const gardenToFlow = (
350350
supergardenId: string,
351351
depth = 0,
352352
indexInSupergarden = 0,
353-
xPosition: number = centerX
353+
xPosition: number = centerX,
354354
) => {
355355
if (!category || !category.name) return;
356356

357357
const categoryId = generateId(
358358
NODE_TYPES.CATEGORY,
359-
`${supergardenId}-${category.name}`
359+
`${supergardenId}-${category.name}`,
360360
);
361361

362362
const yPosition = 200 + depth * 200 + indexInSupergarden * 150;
@@ -415,7 +415,7 @@ export const gardenToFlow = (
415415

416416
const itemId = generateId(
417417
NODE_TYPES.ITEM,
418-
`${categoryId}-${item.name}`
418+
`${categoryId}-${item.name}`,
419419
);
420420
const itemYPosition = yPosition + (itemIndex + 1) * 100;
421421

@@ -474,7 +474,7 @@ export const gardenToFlow = (
474474

475475
const refId = generateId(
476476
NODE_TYPES.GARDEN_REF,
477-
`${categoryId}-${gardenRef.name}`
477+
`${categoryId}-${gardenRef.name}`,
478478
);
479479
// Position garden refs to the right of the category
480480
const refXPosition = xPosition + 250;
@@ -536,9 +536,9 @@ export const gardenToFlow = (
536536
categoryId,
537537
depth + 1,
538538
subcategoryIndex,
539-
xPosition + (subcategoryIndex % 2 === 0 ? -150 : 150) // Alternately offset to avoid overlap
539+
xPosition + (subcategoryIndex % 2 === 0 ? -150 : 150), // Alternately offset to avoid overlap
540540
);
541-
}
541+
},
542542
);
543543
}
544544
};
@@ -590,7 +590,7 @@ export const gardenToFlow = (
590590

591591
export const autoLayout = async (
592592
nodes: Node[],
593-
edges: Edge[]
593+
edges: Edge[],
594594
): Promise<{ nodes: Node[]; edges: Edge[] }> => {
595595
if (!nodes?.length || !edges?.length) {
596596
return { nodes: nodes || [], edges: edges || [] };

0 commit comments

Comments
 (0)