Skip to content

Commit 12830c2

Browse files
committed
chore: update component name JSdoc and use search params for garden tabs
1 parent 9edac41 commit 12830c2

File tree

14 files changed

+95
-52
lines changed

14 files changed

+95
-52
lines changed

app/src/components/core/CustomNodes/CustomNodes.tsx

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@ import { Handle, Position } from "@xyflow/react";
33
import { Icons } from "components/core";
44
import { Button, Card } from "components/ui";
55

6-
const BaseNode = ({
7-
data,
8-
children,
9-
}: {
10-
data: any;
11-
children: React.ReactNode;
12-
}) => <Card className="w-[200px] border-2 shadow-lg">{children}</Card>;
6+
interface NodeData {
7+
label: string;
8+
description?: string;
9+
icon: keyof typeof Icons;
10+
icon_color?: string;
11+
image?: string;
12+
expandable?: boolean;
13+
version?: string;
14+
url?: string;
15+
cta?: {
16+
primary: { label: string; url: string };
17+
secondary?: { label: string; url: string };
18+
};
19+
}
1320

14-
const GardenNode = ({ data }: { data: any }) => (
15-
<BaseNode data={data}>
21+
const GardenNode = ({ data }: { data: NodeData }) => (
22+
<Card className="w-[200px] border-2 shadow-lg">
1623
<div className="flex flex-col items-center justify-center gap-2 rounded-md bg-primary p-4 text-center text-primary-foreground">
1724
<Icons.Sprout className="h-8 w-8" />
1825
<h2 className="font-semibold text-2xl">{data.label}</h2>
@@ -21,14 +28,14 @@ const GardenNode = ({ data }: { data: any }) => (
2128
</div>
2229
<Handle type="target" position={Position.Top} />
2330
<Handle type="source" position={Position.Bottom} />
24-
</BaseNode>
31+
</Card>
2532
);
2633

27-
const CategoryNode = ({ data }: { data: any }) => {
34+
const CategoryNode = ({ data }: { data: NodeData }) => {
2835
const Icon = Icons[data.icon];
2936

3037
return (
31-
<BaseNode data={data}>
38+
<Card className="w-[200px] border-2 shadow-lg">
3239
<Handle type="target" position={Position.Top} />
3340
<Handle type="source" position={Position.Bottom} />
3441
<div className="p-4">
@@ -45,12 +52,12 @@ const CategoryNode = ({ data }: { data: any }) => {
4552
</p>
4653
)}
4754
</div>
48-
</BaseNode>
55+
</Card>
4956
);
5057
};
5158

52-
const ItemNode = ({ data }: { data: any }) => (
53-
<BaseNode data={data}>
59+
const ItemNode = ({ data }: { data: NodeData }) => (
60+
<Card className="w-[200px] border-2 shadow-lg">
5461
<div className="space-y-3">
5562
<div className="aspect-video w-full overflow-hidden rounded-t-lg">
5663
<img
@@ -72,16 +79,17 @@ const ItemNode = ({ data }: { data: any }) => (
7279
variant="default"
7380
size="sm"
7481
className="w-full"
75-
onClick={() => window.open(data.cta.primary.url, "_blank")}
82+
onClick={() => window.open(data.cta?.primary.url, "_blank")}
7683
>
7784
<Icons.ExternalLink className="mr-1 h-4 w-4" />
78-
{data.cta.primary.label}
85+
{data.cta?.primary.label}
7986
</Button>
80-
{data.cta.secondary && (
87+
88+
{data.cta?.secondary && (
8189
<Button
8290
variant="outline"
8391
size="sm"
84-
onClick={() => window.open(data.cta.secondary.url, "_blank")}
92+
onClick={() => window.open(data.cta?.secondary?.url, "_blank")}
8593
>
8694
<Icons.Git className="h-4 w-4" />
8795
</Button>
@@ -90,11 +98,11 @@ const ItemNode = ({ data }: { data: any }) => (
9098
</div>
9199
<Handle type="target" position={Position.Top} />
92100
<Handle type="source" position={Position.Bottom} />
93-
</BaseNode>
101+
</Card>
94102
);
95103

96-
const GardenRefNode = ({ data }: { data: any }) => (
97-
<BaseNode data={data}>
104+
const GardenRefNode = ({ data }: { data: NodeData }) => (
105+
<Card className="w-[200px] border-2 shadow-lg">
98106
<Handle type="target" position={Position.Top} />
99107
<Handle type="target" position={Position.Left} />
100108
<div className="relative flex cursor-pointer flex-col items-center rounded-md border-2 border-primary/50 border-dashed p-4 text-center transition-colors hover:bg-primary-foreground/10">
@@ -127,11 +135,11 @@ const GardenRefNode = ({ data }: { data: any }) => (
127135
</Button>
128136
</div>
129137
</div>
130-
</BaseNode>
138+
</Card>
131139
);
132140

133-
const SupergardenNode = ({ data }: { data: any }) => (
134-
<BaseNode data={data}>
141+
const SupergardenNode = ({ data }: { data: NodeData }) => (
142+
<Card className="w-[200px] border-2 shadow-lg">
135143
<Handle type="source" position={Position.Bottom} />
136144
<div
137145
className="relative flex cursor-pointer flex-col items-center border-2 border-white/70 border-dashed p-4 text-center transition-transform hover:scale-105"
@@ -164,11 +172,11 @@ const SupergardenNode = ({ data }: { data: any }) => (
164172
</Button>
165173
</div>
166174
</div>
167-
</BaseNode>
175+
</Card>
168176
);
169177

170-
const SubgardenNode = ({ data }: { data: any }) => (
171-
<BaseNode data={data}>
178+
const SubgardenNode = ({ data }: { data: NodeData }) => (
179+
<Card className="w-[200px] border-2 shadow-lg">
172180
<Handle type="target" position={Position.Bottom} />
173181
<div
174182
className="relative flex cursor-pointer flex-col items-center p-4 text-center transition-transform hover:scale-105"
@@ -207,7 +215,7 @@ const SubgardenNode = ({ data }: { data: any }) => (
207215
</Button>
208216
</div>
209217
</div>
210-
</BaseNode>
218+
</Card>
211219
);
212220

213221
export const nodeTypes = {
@@ -217,7 +225,7 @@ export const nodeTypes = {
217225
garden_ref: GardenRefNode,
218226
supergarden: SupergardenNode,
219227
subgarden: SubgardenNode,
220-
default: ({ data }: { data: any }) => (
228+
default: ({ data }: { data: NodeData }) => (
221229
<>
222230
<Handle type="source" position={Position.Top} />
223231
<Handle type="source" position={Position.Bottom} />

app/src/components/core/Icons/Icons.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ import {
3535
X,
3636
RefreshCw,
3737
Maximize,
38+
ArrowLeft,
3839
type LucideIcon,
3940
} from "lucide-react";
4041

42+
/**
43+
* Application Icons.
44+
*/
4145
export const Icons: Record<string, LucideIcon> = {
4246
Sprout,
4347
Zap,
@@ -76,4 +80,5 @@ export const Icons: Record<string, LucideIcon> = {
7680
X,
7781
RefreshCw,
7882
Maximize,
83+
ArrowLeft,
7984
};

app/src/components/layout/Footer/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Link from "next/link";
22

33
/**
4-
* Layout header.
4+
* Layout footer.
55
*/
66
const Footer = () => (
77
<footer className="flex w-full shrink-0 flex-col items-center gap-2 border-t px-4 py-6 sm:flex-row md:px-6">

app/src/components/layout/ThemeToggle/ThemeToggle.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { useTheme } from "next-themes";
55
import { Icons } from "components/core";
66
import { Button } from "components/ui";
77

8+
/**
9+
* Layout theme toggle.
10+
*/
811
const ThemeToggle = () => {
912
const { theme, setTheme } = useTheme();
1013

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ interface Props {
1313
garden?: GardenTypes;
1414
}
1515

16+
/**
17+
* Editor Actions.
18+
*/
1619
const EditorActions = ({
1720
schemaText,
1821
setSchemaText,

app/src/components/visualizer/EditorControls/EditorControls.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Icons } from "components/core";
22
import { Button } from "components/ui";
33
import useSearchParams from "lib/hooks/useSearchParams";
44

5+
/**
6+
* Editor Controls.
7+
*/
58
const EditorControls = () => {
69
const [{ fontSize, editorExpanded }, setSearchParams] = useSearchParams();
710

app/src/components/visualizer/GardenFlow/GardenFlow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ interface Props {
88
onNavigateToGarden?: (gardenName: string) => void;
99
}
1010

11-
// Wrap with provider to avoid context issues
11+
/**
12+
* Garden Flow.
13+
*/
1214
const GardenFlow = ({ garden, onNavigateToGarden }: Props) => {
1315
return (
1416
<ReactFlowProvider>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ interface Props {
3030
onNavigateToGarden?: (gardenName: string) => void;
3131
}
3232

33+
/**
34+
* Garden Flow Inner.
35+
*/
3336
const GardenFlowInner = ({ garden, onNavigateToGarden }: Props) => {
3437
const { fitView } = useReactFlow();
3538
const updateNodeInternals = useUpdateNodeInternals();

app/src/components/visualizer/GardenTabs/GardenTabs.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@ import { GardenFlow, SchemaEditor } from "components/visualizer";
44
import { Tabs, TabsContent, TabsList, TabsTrigger } from "components/ui";
55

66
import { Icons } from "components/core";
7+
import useSearchParams from "lib/hooks/useSearchParams";
78

89
import type { GardenTypes } from "generated/garden.types";
910

1011
interface Props {
1112
garden: GardenTypes;
1213
onSchemaChange: (schema: GardenTypes) => void;
13-
activeTab: string;
14-
onTabChange: (tab: string) => void;
1514
onNavigateToGarden?: (gardenName: string) => void;
1615
}
1716

18-
const GardenTabs = ({
19-
garden,
20-
onSchemaChange,
21-
activeTab,
22-
onTabChange,
23-
onNavigateToGarden,
24-
}: Props) => {
17+
/**
18+
* Garden Tabs.
19+
*/
20+
const GardenTabs = ({ garden, onSchemaChange, onNavigateToGarden }: Props) => {
21+
const [{ activeTab }, setSearchParams] = useSearchParams();
22+
2523
return (
26-
<Tabs value={activeTab} onValueChange={onTabChange} className="space-y-6">
24+
<Tabs
25+
value={activeTab}
26+
onValueChange={() =>
27+
setSearchParams({
28+
activeTab: activeTab === "visualize" ? "edit" : "visualize",
29+
})
30+
}
31+
className="space-y-6"
32+
>
2733
<TabsList className="grid w-full max-w-md grid-cols-2">
2834
<TabsTrigger value="visualize" className="flex items-center gap-2">
2935
<Icons.BarChart className="h-4 w-4" />

app/src/components/visualizer/SchemaEditor/SchemaEditor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ interface SchemaEditorProps {
3636

3737
const LOCAL_STORAGE_KEY = "garden-schema-editor-content";
3838

39+
/**
40+
* Schema Editor.
41+
*/
3942
const SchemaEditor = ({ onSchemaChange, garden }: SchemaEditorProps) => {
4043
// Initialize schema text with current garden or stored value
4144
const [schemaText, setSchemaText] = useState<string>("");

0 commit comments

Comments
 (0)