Skip to content

Commit 3123f72

Browse files
committed
refactor(argocd): handle null value when subsets of argo application are unchecked
1 parent 7503f4a commit 3123f72

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

web/src/features/terraform/components/Argocd.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const Argocd = () => {
2121

2222
const [error, setError] = useState(false);
2323

24-
const {data, isPending, isError, isSuccess, mutate} = useMutation<AxiosResponse, Error, {body: {argocd_application: {sync_policy: {auto_prune: boolean, self_heal: boolean}}, argocd_repository: boolean, application_depends_repository: boolean}}>({
24+
const {data, isPending, isError, isSuccess, mutate} = useMutation<AxiosResponse, Error, {body: {argocd_application: {sync_policy: {auto_prune: boolean, self_heal: boolean}} | null, argocd_repository: boolean, application_depends_repository: boolean}}>({
2525
mutationKey: ["argocd"],
2626
mutationFn: async ({body}) => {
2727
await apiClient.post(Endpoints.POST_IAC_ARGOCD, {...body});
@@ -43,7 +43,7 @@ const Argocd = () => {
4343
const blob = new Blob([data.data], { type: data.headers['content-type'] });
4444
const link = document.createElement('a');
4545
link.href = URL.createObjectURL(blob);
46-
link.download = "Argpcd.zip";
46+
link.download = "Argocd.zip";
4747
document.body.appendChild(link);
4848
link.click();
4949
document.body.removeChild(link);
@@ -60,15 +60,19 @@ const Argocd = () => {
6060

6161
const handleSubmit = async () => {
6262
const body = {
63-
"argocd_application": {
64-
"sync_policy": {
65-
"auto_prune": buttons.auto_prune,
66-
"self_heal": buttons.self_heal
67-
}
68-
},
69-
"argocd_repository": buttons.argocd_repository,
70-
"application_depends_repository": buttons.application_depends_repository
71-
}
63+
argocd_application: (
64+
buttons.auto_prune || buttons.self_heal
65+
? {
66+
sync_policy: {
67+
auto_prune: buttons.auto_prune,
68+
self_heal: buttons.self_heal
69+
}
70+
}
71+
: null
72+
),
73+
argocd_repository: buttons.argocd_repository,
74+
application_depends_repository: buttons.application_depends_repository
75+
};
7276

7377
mutate({body})
7478
}

0 commit comments

Comments
 (0)