Skip to content

Commit e187715

Browse files
chore: argocd view
1 parent 8169ac3 commit e187715

File tree

4 files changed

+119
-10
lines changed

4 files changed

+119
-10
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import type { UseFormReturn } from "react-hook-form";
2+
import Editor from "@monaco-editor/react";
3+
import yaml from "js-yaml";
4+
import _ from "lodash";
5+
import { z } from "zod";
6+
7+
import { useTheme } from "~/components/ThemeProvider";
8+
import { FormField } from "~/components/ui/form";
9+
10+
// Example default ArgoCD Application YAML config shown if the config is empty
11+
const DEFAULT_CONFIG = {
12+
apiVersion: "argoproj.io/v1alpha1",
13+
kind: "Application",
14+
metadata: {
15+
name: "{{.Resource.Name}}-application",
16+
namespace: "argocd",
17+
labels: {
18+
"app.kubernetes.io/name": "{{.Resource.Name}}",
19+
environment: "{{.Environment.Name}}",
20+
deployment: "{{.Deployment.Name}}",
21+
resource: "{{.Resource.Name}}",
22+
},
23+
},
24+
spec: {
25+
project: "default",
26+
source: {
27+
repoURL: "https://github.com/YOUR_ORG/YOUR_REPO.git",
28+
path: "YOUR_PATH_IN_REPO",
29+
targetRevision: "HEAD",
30+
helm: {
31+
releaseName: "{{.Resource.Name}}",
32+
},
33+
},
34+
destination: {
35+
name: "{{.Resource.Identifier}}",
36+
namespace: "default",
37+
},
38+
syncPolicy: {
39+
automated: {
40+
prune: true,
41+
selfHeal: true,
42+
},
43+
syncOptions: ["CreateNamespace=true"],
44+
},
45+
},
46+
};
47+
48+
const formSchema = z.object({
49+
jobAgentId: z.string(),
50+
jobAgentConfig: z.record(z.any()),
51+
});
52+
53+
function getParsedConfig(config: Record<string, any>): Record<string, any> {
54+
const template = config.template ?? "";
55+
const yamlParsed = yaml.load(template) as Record<string, any>;
56+
if ("spec" in yamlParsed) return yamlParsed;
57+
58+
const jsonParsed = JSON.parse(template) as Record<string, any>;
59+
if ("spec" in jsonParsed) return jsonParsed;
60+
61+
return DEFAULT_CONFIG;
62+
}
63+
64+
type Form = UseFormReturn<z.infer<typeof formSchema>>;
65+
66+
type ArgoCDConfigProps = { form: Form };
67+
68+
export function ArgoCDConfig({ form }: ArgoCDConfigProps) {
69+
const { theme } = useTheme();
70+
console.log(theme);
71+
return (
72+
<FormField
73+
control={form.control}
74+
name="jobAgentConfig"
75+
render={({ field: { value, onChange } }) => {
76+
const config = getParsedConfig(value);
77+
const configString = yaml.dump(config);
78+
79+
const handleChange = (newValue: string) =>
80+
onChange({ template: newValue });
81+
82+
return (
83+
<div className="border">
84+
<Editor
85+
language="yaml"
86+
theme={theme === "dark" ? "vs-dark" : "vs-light"}
87+
options={{ minimap: { enabled: false } }}
88+
value={configString}
89+
onChange={(newValue) => handleChange(newValue ?? "")}
90+
height="400px"
91+
/>
92+
</div>
93+
);
94+
}}
95+
/>
96+
);
97+
}

apps/web/app/routes/ws/deployments/settings/page.$deploymentId.job-agent.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from "~/components/ui/select";
2626
import { useWorkspace } from "~/components/WorkspaceProvider";
2727
import { useDeployment } from "../_components/DeploymentProvider";
28+
import { ArgoCDConfig } from "./_components/ArgoCD";
2829
import { GithubAgentConfig } from "./_components/GithubAgentConfig";
2930
import { useAllJobAgents, useSelectedJobAgent } from "./_hooks/job-agents";
3031

@@ -90,6 +91,9 @@ function JobAgentConfigSection({
9091
{selectedJobAgent?.type === "github-app" && (
9192
<GithubAgentConfig form={form} />
9293
)}
94+
{selectedJobAgent?.type === "argo-cd" && (
95+
<ArgoCDConfig form={form} />
96+
)}
9397
</>
9498
</FormControl>
9599
<FormMessage />

apps/web/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@dagrejs/dagre": "^1.1.5",
1818
"@hookform/resolvers": "catalog:",
1919
"@icons-pack/react-simple-icons": "^10.2.0",
20-
"@monaco-editor/react": "^4.7.0",
20+
"@monaco-editor/react": "4.8.0-rc.2",
2121
"@radix-ui/react-accordion": "^1.2.11",
2222
"@radix-ui/react-alert-dialog": "^1.1.14",
2323
"@radix-ui/react-avatar": "^1.1.10",
@@ -51,6 +51,7 @@
5151
"cmdk": "^1.1.1",
5252
"date-fns": "^4.1.0",
5353
"isbot": "^5.1.31",
54+
"js-yaml": "^4.1.0",
5455
"ldrs": "^1.1.9",
5556
"lodash": "catalog:",
5657
"lucide-react": "^0.441.0",
@@ -80,6 +81,7 @@
8081
"@openapitools/openapi-generator-cli": "^2.21.0",
8182
"@react-router/dev": "^7.9.2",
8283
"@tailwindcss/vite": "^4.1.13",
84+
"@types/js-yaml": "^4.0.9",
8385
"@types/lodash": "catalog:",
8486
"@types/node": "^22",
8587
"@types/react": "catalog:react19",

pnpm-lock.yaml

Lines changed: 15 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)