| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 1 | import { v4 as uuidv4 } from "uuid"; |
| 2 | import { NodeRect } from './node-rect'; |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 3 | import { useStateStore, ServiceNode, ServiceTypes, nodeLabel, BoundEnvVar, AppState, nodeIsConnectable, GatewayTCPNode, GatewayHttpsNode, AppNode } from '@/lib/state'; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 4 | import { KeyboardEvent, FocusEvent, useCallback, useEffect, useMemo, useState } from 'react'; |
| 5 | import { z } from "zod"; |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 6 | import { DeepPartial, EventType, useForm, ControllerRenderProps, FieldPath } from 'react-hook-form'; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 7 | import { zodResolver } from '@hookform/resolvers/zod'; |
| 8 | import { Form, FormControl, FormField, FormItem, FormMessage } from './ui/form'; |
| 9 | import { Input } from './ui/input'; |
| 10 | import { Button } from './ui/button'; |
| gio | 33990c6 | 2025-05-06 07:51:24 +0000 | [diff] [blame] | 11 | import { Handle, Position, useNodes } from "@xyflow/react"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 12 | import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select"; |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 13 | import { PencilIcon, XIcon } from "lucide-react"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 14 | import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip"; |
| gio | 9116561 | 2025-05-03 17:07:38 +0000 | [diff] [blame] | 15 | import { Textarea } from "./ui/textarea"; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 16 | |
| 17 | export function NodeApp(node: ServiceNode) { |
| 18 | const { id, selected } = node; |
| 19 | const isConnectablePorts = useMemo(() => nodeIsConnectable(node, "ports"), [node]); |
| 20 | const isConnectableRepository = useMemo(() => nodeIsConnectable(node, "repository"), [node]); |
| 21 | return ( |
| gio | 1dc800a | 2025-04-24 17:15:43 +0000 | [diff] [blame] | 22 | <NodeRect id={id} selected={selected} type={node.type} state={node.data.state}> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 23 | <div style={{ padding: '10px 20px' }}> |
| 24 | {nodeLabel(node)} |
| 25 | <Handle |
| 26 | id="repository" |
| 27 | type={"target"} |
| 28 | position={Position.Left} |
| 29 | isConnectableStart={isConnectableRepository} |
| 30 | isConnectableEnd={isConnectableRepository} |
| 31 | isConnectable={isConnectableRepository} |
| 32 | /> |
| 33 | <Handle |
| 34 | id="ports" |
| 35 | type={"source"} |
| 36 | position={Position.Top} |
| 37 | isConnectableStart={isConnectablePorts} |
| 38 | isConnectableEnd={isConnectablePorts} |
| 39 | isConnectable={isConnectablePorts} |
| 40 | /> |
| 41 | <Handle |
| 42 | id="env_var" |
| 43 | type={"target"} |
| 44 | position={Position.Bottom} |
| 45 | isConnectableStart={true} |
| 46 | isConnectableEnd={true} |
| 47 | isConnectable={true} |
| 48 | /> |
| 49 | </div> |
| 50 | </NodeRect> |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | const schema = z.object({ |
| 55 | name: z.string().min(1, "requried"), |
| 56 | type: z.enum(ServiceTypes), |
| 57 | }); |
| 58 | |
| 59 | const portSchema = z.object({ |
| 60 | name: z.string().min(1, "required"), |
| 61 | value: z.coerce.number().gt(0, "can not be negative"), |
| 62 | }); |
| 63 | |
| gio | 33990c6 | 2025-05-06 07:51:24 +0000 | [diff] [blame] | 64 | const sourceSchema = z.object({ |
| 65 | id: z.string().min(1, "required"), |
| 66 | branch: z.string(), |
| 67 | rootDir: z.string(), |
| 68 | }); |
| 69 | |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 70 | export function NodeAppDetails({ id, data }: ServiceNode) { |
| 71 | const store = useStateStore(); |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 72 | const nodes = useNodes<AppNode>(); |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 73 | const form = useForm<z.infer<typeof schema>>({ |
| 74 | resolver: zodResolver(schema), |
| 75 | mode: "onChange", |
| 76 | defaultValues: { |
| 77 | name: data.label, |
| 78 | type: data.type, |
| 79 | } |
| 80 | }); |
| 81 | const portForm = useForm<z.infer<typeof portSchema>>({ |
| 82 | resolver: zodResolver(portSchema), |
| 83 | mode: "onSubmit", |
| 84 | defaultValues: { |
| 85 | name: "", |
| 86 | value: 0, |
| 87 | } |
| 88 | }); |
| 89 | const onSubmit = useCallback((values: z.infer<typeof portSchema>) => { |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 90 | const portId = uuidv4(); |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 91 | store.updateNodeData<"app">(id, { |
| 92 | ports: (data.ports || []).concat({ |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 93 | id: portId, |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 94 | name: values.name, |
| 95 | value: values.value, |
| gio | 355883e | 2025-04-23 14:10:51 +0000 | [diff] [blame] | 96 | }), |
| 97 | envVars: (data.envVars || []).concat({ |
| 98 | id: uuidv4(), |
| 99 | source: null, |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 100 | portId, |
| gio | 355883e | 2025-04-23 14:10:51 +0000 | [diff] [blame] | 101 | name: `DODO_PORT_${values.name.toUpperCase()}`, |
| 102 | }), |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 103 | }); |
| 104 | portForm.reset(); |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 105 | }, [id, data, portForm, store]); |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 106 | useEffect(() => { |
| 107 | const sub = form.watch((value: DeepPartial<z.infer<typeof schema>>, { name, type }: { name?: keyof z.infer<typeof schema> | undefined, type?: EventType | undefined }) => { |
| 108 | console.log({ name, type }); |
| 109 | if (type !== "change") { |
| 110 | return; |
| 111 | } |
| 112 | switch (name) { |
| 113 | case "name": |
| 114 | if (!value.name) { |
| 115 | break; |
| 116 | } |
| 117 | store.updateNodeData<"app">(id, { |
| 118 | label: value.name, |
| 119 | }); |
| 120 | break; |
| 121 | case "type": |
| 122 | if (!value.type) { |
| 123 | break; |
| 124 | } |
| 125 | store.updateNodeData<"app">(id, { |
| 126 | type: value.type, |
| 127 | }) |
| 128 | break; |
| 129 | } |
| 130 | }); |
| 131 | return () => sub.unsubscribe(); |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 132 | }, [id, form, store]); |
| 133 | const focus = useCallback((field: ControllerRenderProps<z.infer<typeof schema>, FieldPath<z.infer<typeof schema>>>, name: string) => { |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 134 | return (e: HTMLElement | null) => { |
| 135 | field.ref(e); |
| 136 | if (e != null && name === data.activeField) { |
| 137 | console.log(e); |
| 138 | e.focus(); |
| 139 | store.updateNodeData(id, { |
| 140 | activeField: undefined, |
| 141 | }); |
| 142 | } |
| 143 | } |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 144 | }, [id, data, store]); |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 145 | const [typeProps, setTypeProps] = useState({}); |
| 146 | useEffect(() => { |
| 147 | if (data.activeField === "type") { |
| 148 | setTypeProps({ |
| 149 | open: true, |
| 150 | onOpenChange: () => store.updateNodeData(id, { activeField: undefined }), |
| 151 | }); |
| 152 | } else { |
| 153 | setTypeProps({}); |
| 154 | } |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 155 | }, [id, data, store, setTypeProps]); |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 156 | const editAlias = useCallback((e: BoundEnvVar) => { |
| 157 | return () => { |
| 158 | store.updateNodeData(id, { |
| 159 | ...data, |
| 160 | envVars: data.envVars!.map((o) => { |
| 161 | if (o.id !== e.id) { |
| 162 | return o; |
| 163 | } else return { |
| 164 | ...o, |
| 165 | isEditting: true, |
| 166 | } |
| 167 | }), |
| 168 | }); |
| 169 | }; |
| 170 | }, [id, data, store]); |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 171 | const saveAlias = useCallback((e: BoundEnvVar, value: string, store: AppState) => { |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 172 | store.updateNodeData(id, { |
| 173 | ...data, |
| 174 | envVars: data.envVars!.map((o) => { |
| 175 | if (o.id !== e.id) { |
| 176 | return o; |
| 177 | } |
| 178 | if (value) { |
| 179 | return { |
| 180 | ...o, |
| 181 | isEditting: false, |
| 182 | alias: value.toUpperCase(), |
| 183 | } |
| 184 | } |
| 185 | console.log(o); |
| 186 | if ("alias" in o) { |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 187 | const { alias: _, ...rest } = o; |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 188 | console.log(rest); |
| 189 | return { |
| 190 | ...rest, |
| 191 | isEditting: false, |
| 192 | }; |
| 193 | } |
| 194 | return { |
| 195 | ...o, |
| 196 | isEditting: false, |
| 197 | }; |
| 198 | }), |
| 199 | }); |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 200 | }, [id, data]); |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 201 | const saveAliasOnEnter = useCallback((e: BoundEnvVar) => { |
| 202 | return (event: KeyboardEvent<HTMLInputElement>) => { |
| 203 | if (event.key === "Enter") { |
| 204 | event.preventDefault(); |
| 205 | saveAlias(e, event.currentTarget.value, store); |
| 206 | } |
| 207 | } |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 208 | }, [store, saveAlias]); |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 209 | const saveAliasOnBlur = useCallback((e: BoundEnvVar) => { |
| 210 | return (event: FocusEvent<HTMLInputElement>) => { |
| 211 | saveAlias(e, event.currentTarget.value, store); |
| 212 | } |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 213 | }, [store, saveAlias]); |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 214 | const removePort = useCallback((portId: string) => { |
| gio | aba9a96 | 2025-04-25 14:19:40 +0000 | [diff] [blame] | 215 | // TODO(gio): this is ugly |
| 216 | const tcpRemoved = new Set<string>(); |
| 217 | console.log(store.edges); |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 218 | store.setEdges(store.edges.filter((e) => { |
| 219 | if (e.source !== id || e.sourceHandle !== "ports") { |
| 220 | return true; |
| 221 | } |
| gio | aba9a96 | 2025-04-25 14:19:40 +0000 | [diff] [blame] | 222 | const tn = store.nodes.find((n) => n.id == e.target)!; |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 223 | if (e.targetHandle === "https") { |
| gio | aba9a96 | 2025-04-25 14:19:40 +0000 | [diff] [blame] | 224 | const t = tn as GatewayHttpsNode; |
| 225 | if (t.data.https?.serviceId === id && t.data.https.portId === portId) { |
| 226 | return false; |
| 227 | } |
| 228 | } |
| 229 | if (e.targetHandle === "tcp") { |
| 230 | const t = tn as GatewayTCPNode; |
| 231 | if (tcpRemoved.has(t.id)) { |
| 232 | return true; |
| 233 | } |
| 234 | if (t.data.exposed.find((e) => e.serviceId === id && e.portId === portId)) { |
| gio | aba9a96 | 2025-04-25 14:19:40 +0000 | [diff] [blame] | 235 | tcpRemoved.add(t.id); |
| 236 | return false; |
| 237 | } |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 238 | } |
| 239 | if (e.targetHandle === "env_var") { |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 240 | if (tn && (tn.data.envVars || []).find((ev) => ev.source === id && "portId" in ev && ev.portId === portId)) { |
| 241 | return false; |
| 242 | } |
| 243 | } |
| 244 | return true; |
| 245 | })); |
| 246 | store.nodes.filter((n) => n.type === "gateway-https" && n.data.https && n.data.https.serviceId === id && n.data.https.portId === portId).forEach((n) => { |
| 247 | store.updateNodeData<"gateway-https">(n.id, { |
| 248 | https: undefined, |
| 249 | }); |
| 250 | }); |
| gio | aba9a96 | 2025-04-25 14:19:40 +0000 | [diff] [blame] | 251 | store.nodes.filter((n) => n.type === "gateway-tcp").forEach((n) => { |
| 252 | const filtered = n.data.exposed.filter((e) => { |
| 253 | if (e.serviceId === id && e.portId === portId) { |
| 254 | return false; |
| 255 | } else { |
| 256 | return true; |
| 257 | } |
| 258 | }) |
| 259 | if (filtered.length != n.data.exposed.length) { |
| 260 | store.updateNodeData<"gateway-tcp">(n.id, { |
| 261 | exposed: filtered, |
| 262 | }); |
| 263 | } |
| 264 | }); |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 265 | store.nodes.filter((n) => n.type === "app" && n.data.envVars).forEach((n) => { |
| 266 | store.updateNodeData<"app">(n.id, { |
| 267 | envVars: n.data.envVars.filter((ev) => { |
| 268 | if (ev.source === id && "portId" in ev && ev.portId === portId) { |
| 269 | return false; |
| 270 | } |
| 271 | return true; |
| 272 | }) |
| 273 | }); |
| gio | aba9a96 | 2025-04-25 14:19:40 +0000 | [diff] [blame] | 274 | }); |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 275 | store.updateNodeData<"app">(id, { |
| 276 | ports: (data.ports || []).filter((p) => p.id !== portId), |
| 277 | envVars: (data.envVars || []).filter((ev) => !(ev.source === null && "portId" in ev && ev.portId === portId)), |
| 278 | }); |
| 279 | }, [id, data, store]); |
| gio | 9116561 | 2025-05-03 17:07:38 +0000 | [diff] [blame] | 280 | const setPreBuildCommands = useCallback((e: React.ChangeEvent<HTMLTextAreaElement>) => { |
| 281 | store.updateNodeData<"app">(id, { |
| 282 | preBuildCommands: e.currentTarget.value, |
| 283 | }); |
| 284 | }, [id, store]); |
| gio | 33990c6 | 2025-05-06 07:51:24 +0000 | [diff] [blame] | 285 | |
| 286 | const sourceForm = useForm<z.infer<typeof sourceSchema>>({ |
| 287 | resolver: zodResolver(sourceSchema), |
| 288 | mode: "onChange", |
| 289 | defaultValues: { |
| 290 | id: data?.repository?.id, |
| 291 | branch: data.repository && "branch" in data.repository ? data.repository.branch : undefined, |
| 292 | rootDir: data.repository && "rootDir" in data.repository ? data.repository.rootDir : undefined, |
| 293 | }, |
| 294 | }); |
| 295 | useEffect(() => { |
| 296 | const sub = sourceForm.watch((value: DeepPartial<z.infer<typeof sourceSchema>>, { name }: { name?: keyof z.infer<typeof sourceSchema> | undefined, type?: EventType | undefined }) => { |
| 297 | console.log(value); |
| 298 | if (name === "id") { |
| 299 | let edges = store.edges; |
| 300 | if (data?.repository?.id !== undefined) { |
| 301 | edges = edges.filter((e) => { |
| 302 | if (e.target === id && e.targetHandle === "repository" && e.source === data.repository.id) { |
| 303 | return false; |
| 304 | } else { |
| 305 | return true; |
| 306 | } |
| 307 | }); |
| 308 | } |
| 309 | if (value.id !== undefined) { |
| 310 | edges = edges.concat({ |
| 311 | id: uuidv4(), |
| 312 | source: value.id, |
| 313 | sourceHandle: "repository", |
| 314 | target: id, |
| 315 | targetHandle: "repository", |
| 316 | }); |
| 317 | } |
| 318 | store.setEdges(edges); |
| 319 | store.updateNodeData<"app">(id, { |
| 320 | repository: { |
| 321 | id: value.id, |
| 322 | }, |
| 323 | }); |
| 324 | } else if (name === "branch") { |
| 325 | store.updateNodeData<"app">(id, { |
| 326 | repository: { |
| 327 | ...data?.repository, |
| 328 | branch: value.branch, |
| 329 | }, |
| 330 | }); |
| 331 | } else if (name === "rootDir") { |
| 332 | store.updateNodeData<"app">(id, { |
| 333 | repository: { |
| 334 | ...data?.repository, |
| 335 | rootDir: value.rootDir, |
| 336 | }, |
| 337 | }); |
| 338 | } |
| 339 | }); |
| 340 | return () => sub.unsubscribe(); |
| 341 | }, [id, data, sourceForm, store]); |
| 342 | |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 343 | return ( |
| 344 | <> |
| 345 | <Form {...form}> |
| 346 | <form> |
| 347 | <FormField |
| 348 | control={form.control} |
| 349 | name="name" |
| 350 | render={({ field }) => ( |
| 351 | <FormItem> |
| 352 | <FormControl> |
| 353 | <Input placeholder="name" className="border border-black" {...field} ref={focus(field, "name")} /> |
| 354 | </FormControl> |
| 355 | <FormMessage /> |
| 356 | </FormItem> |
| 357 | )} |
| 358 | /> |
| 359 | <FormField |
| 360 | control={form.control} |
| 361 | name="type" |
| 362 | render={({ field }) => ( |
| 363 | <FormItem> |
| 364 | <Select onValueChange={field.onChange} defaultValue={field.value} {...typeProps}> |
| 365 | <FormControl> |
| 366 | <SelectTrigger> |
| 367 | <SelectValue placeholder="Runtime" /> |
| 368 | </SelectTrigger> |
| 369 | </FormControl> |
| 370 | <SelectContent> |
| 371 | {ServiceTypes.map((t) => ( |
| 372 | <SelectItem key={t} value={t}>{t}</SelectItem> |
| 373 | ))} |
| 374 | </SelectContent> |
| 375 | </Select> |
| 376 | <FormMessage /> |
| 377 | </FormItem> |
| 378 | )} |
| 379 | /> |
| 380 | </form> |
| 381 | </Form> |
| gio | 33990c6 | 2025-05-06 07:51:24 +0000 | [diff] [blame] | 382 | Source |
| 383 | <Form {...sourceForm}> |
| 384 | <form className="space-y-2"> |
| 385 | <FormField |
| 386 | control={sourceForm.control} |
| 387 | name="id" |
| 388 | render={({ field }) => ( |
| 389 | <FormItem> |
| 390 | <Select onValueChange={field.onChange} defaultValue={field.value}> |
| 391 | <FormControl> |
| 392 | <SelectTrigger> |
| 393 | <SelectValue placeholder="Repository" /> |
| 394 | </SelectTrigger> |
| 395 | </FormControl> |
| 396 | <SelectContent> |
| gio | 6cf8c27 | 2025-05-08 09:01:38 +0000 | [diff] [blame] | 397 | {(nodes.filter((n) => n.type === "github" && n.data.repository?.id !== undefined) as GithubNode[]).map((n) => ( |
| gio | 7f98e77 | 2025-05-07 11:00:14 +0000 | [diff] [blame] | 398 | <SelectItem key={n.id} value={n.id}>{`${n.data.repository?.sshURL}`}</SelectItem> |
| gio | 33990c6 | 2025-05-06 07:51:24 +0000 | [diff] [blame] | 399 | ))} |
| 400 | </SelectContent> |
| 401 | </Select> |
| 402 | <FormMessage /> |
| 403 | </FormItem> |
| 404 | )} |
| 405 | /> |
| 406 | <FormField |
| 407 | control={sourceForm.control} |
| 408 | name="branch" |
| 409 | render={({ field }) => ( |
| 410 | <FormItem> |
| 411 | <FormControl> |
| 412 | <Input placeholder="master" className="border border-black" {...field} /> |
| 413 | </FormControl> |
| 414 | <FormMessage /> |
| 415 | </FormItem> |
| 416 | )} |
| 417 | /> |
| 418 | <FormField |
| 419 | control={sourceForm.control} |
| 420 | name="rootDir" |
| 421 | render={({ field }) => ( |
| 422 | <FormItem> |
| 423 | <FormControl> |
| 424 | <Input placeholder="/" className="border border-black" {...field} /> |
| 425 | </FormControl> |
| 426 | <FormMessage /> |
| 427 | </FormItem> |
| 428 | )} |
| 429 | /> |
| 430 | </form> |
| 431 | </Form> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 432 | Ports |
| 433 | <ul> |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 434 | {data && data.ports && data.ports.map((p) => (<li key={p.id}><Button size={"icon"} variant={"ghost"} onClick={() => removePort(p.id)}><XIcon /></Button> {p.name} - {p.value}</li>))} |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 435 | </ul> |
| 436 | <Form {...portForm}> |
| 437 | <form className="flex flex-row space-x-1" onSubmit={portForm.handleSubmit(onSubmit)}> |
| 438 | <FormField |
| 439 | control={portForm.control} |
| 440 | name="name" |
| 441 | render={({ field }) => ( |
| 442 | <FormItem> |
| 443 | <FormControl> |
| 444 | <Input placeholder="name" className="border border-black" {...field} /> |
| 445 | </FormControl> |
| 446 | <FormMessage /> |
| 447 | </FormItem> |
| 448 | )} |
| 449 | /> |
| 450 | <FormField |
| 451 | control={portForm.control} |
| 452 | name="value" |
| 453 | render={({ field }) => ( |
| 454 | <FormItem> |
| 455 | <FormControl> |
| 456 | <Input placeholder="value" className="border border-black" {...field} /> |
| 457 | </FormControl> |
| 458 | <FormMessage /> |
| 459 | </FormItem> |
| 460 | )} |
| 461 | /> |
| 462 | <Button type="submit">Add Port</Button> |
| 463 | </form> |
| 464 | </Form> |
| 465 | Env Vars |
| 466 | <ul> |
| 467 | {data && data.envVars && data.envVars.map((v) => { |
| 468 | if ("name" in v) { |
| 469 | const value = "alias" in v ? v.alias : v.name; |
| 470 | if (v.isEditting) { |
| 471 | return (<li key={v.id}><Input type="text" className="border border-black" defaultValue={value} onKeyUp={saveAliasOnEnter(v)} onBlur={saveAliasOnBlur(v)} autoFocus={true} /></li>); |
| 472 | } |
| 473 | return ( |
| 474 | <li key={v.id} onClick={editAlias(v)}> |
| 475 | <TooltipProvider> |
| 476 | <Tooltip> |
| 477 | <TooltipTrigger> |
| gio | b41ecae | 2025-04-24 08:46:50 +0000 | [diff] [blame] | 478 | <Button size={"icon"} variant={"ghost"}><PencilIcon /></Button> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 479 | {value} |
| 480 | </TooltipTrigger> |
| 481 | <TooltipContent> |
| 482 | {v.name} |
| 483 | </TooltipContent> |
| 484 | </Tooltip> |
| 485 | </TooltipProvider> |
| 486 | </li> |
| 487 | ); |
| 488 | } |
| 489 | })} |
| 490 | </ul> |
| gio | 9116561 | 2025-05-03 17:07:38 +0000 | [diff] [blame] | 491 | Pre-Build Commands |
| 492 | <Textarea placeholder="new line separated list of commands to run before running the service" value={data.preBuildCommands} onChange={setPreBuildCommands} /> |
| gio | 5f2f100 | 2025-03-20 18:38:48 +0400 | [diff] [blame] | 493 | </>); |
| 494 | } |