Skip to content

Commit 31378f5

Browse files
committed
refactor(argocd): add input trigger to control ArgoCD application menu
- Updated logic to send null when the input trigger is set to false.
1 parent 3123f72 commit 31378f5

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const Argocd = () => {
1515
});
1616

1717
const [menus, setMenus] = useState({
18-
argocd_application: false,
19-
sync_policy: false
18+
argocd_application: true,
19+
sync_policy: true
2020
});
2121

2222
const [error, setError] = useState(false);
@@ -50,6 +50,16 @@ const Argocd = () => {
5050
}
5151
}, [isSuccess, data])
5252

53+
useEffect(() => {
54+
if (!menus.argocd_application) {
55+
setButtons({
56+
...buttons,
57+
auto_prune: false,
58+
self_heal: false
59+
})
60+
}
61+
}, [menus])
62+
5363
const handleButtons = (button: keyof typeof buttons) => {
5464
setButtons({...buttons, [button]: !buttons[button]})
5565
}
@@ -61,7 +71,7 @@ const Argocd = () => {
6171
const handleSubmit = async () => {
6272
const body = {
6373
argocd_application: (
64-
buttons.auto_prune || buttons.self_heal
74+
menus.argocd_application
6575
? {
6676
sync_policy: {
6777
auto_prune: buttons.auto_prune,
@@ -81,30 +91,32 @@ const Argocd = () => {
8191
<div className="flex flex-col items-center justify-center">
8292
<div className="w-full bg-orange-800 divide-y-2 divide-gray-300 rounded-md max-w-96">
8393
<div className="divide-y-2 divide-gray-300">
84-
<button className="flex items-center justify-between w-full px-4 py-2" onClick={() => handleMenus("argocd_application")}>
94+
<div className="flex items-center justify-between w-full px-4 py-2">
8595
<p>Argocd Application</p>
86-
<FaChevronDown className={cn('transition-all', {"rotate-180": menus.argocd_application})} />
87-
</button>
88-
<div className={cn("divide-y-2 divide-gray-300 max-h-0 overflow-hidden transition-all ease-linear duration-300", {"max-h-96": !menus.argocd_application})}>
96+
<input type="checkbox" className={cn('border-orange-[#2e323a] toggle [--tglbg:#2e323a] bg-orange-300 hover:bg-orange-400', {
97+
'bg-[#5b6372] hover:bg-[#5b6372]': !menus.argocd_application,
98+
}) } checked={menus.argocd_application} onChange={() => {handleMenus("argocd_application")}} />
99+
</div>
100+
<div className={cn("divide-y-2 divide-gray-300 max-h-0 overflow-hidden transition-all ease-linear duration-300", {"max-h-96": menus.argocd_application})}>
89101
<button className="flex items-center justify-between w-full py-2 pl-10 pr-4" onClick={() => handleMenus("sync_policy")}>
90-
<p>Sync Policy</p>
91-
<FaChevronDown className={cn('transition-all', {"rotate-180": menus.sync_policy})} />
92-
</button>
93-
<div className={cn("divide-y-2 divide-gray-300 max-h-0 overflow-hidden transition-all ease-linear duration-300", {"max-h-96": !menus.sync_policy})}>
102+
<p>Sync Policy</p>
103+
<FaChevronDown className={cn('transition-all', {"rotate-180": menus.sync_policy})} />
104+
</button>
105+
<div className={cn("divide-y-2 divide-gray-300 max-h-0 overflow-hidden transition-all ease-linear duration-300", {"max-h-96": menus.sync_policy})}>
94106
<div className="py-2 pl-16 pr-4">
95107
<div className="flex items-center justify-between">
96108
<p>Auto Prune</p>
97109
<input type="checkbox" className={cn('border-orange-[#2e323a] toggle [--tglbg:#2e323a] bg-orange-300 hover:bg-orange-400', {
98110
'bg-[#5b6372] hover:bg-[#5b6372]': !buttons.auto_prune,
99-
}) } defaultChecked={buttons.auto_prune} onClick={() => handleButtons("auto_prune")} />
111+
}) } checked={buttons.auto_prune} onChange={() => handleButtons("auto_prune")} />
100112
</div>
101113
</div>
102114
<div className="py-2 pl-16 pr-4">
103115
<div className="flex items-center justify-between">
104116
<p>Self Heal</p>
105117
<input type="checkbox" className={cn('border-orange-[#2e323a] toggle [--tglbg:#2e323a] bg-orange-300 hover:bg-orange-400', {
106118
'bg-[#5b6372] hover:bg-[#5b6372]': !buttons.self_heal,
107-
}) } defaultChecked={buttons.self_heal} onClick={() => handleButtons("self_heal")} />
119+
}) } checked={buttons.self_heal} onChange={() => handleButtons("self_heal")} />
108120
</div>
109121
</div>
110122
</div>
@@ -114,20 +126,20 @@ const Argocd = () => {
114126
<p>Argocd Repository</p>
115127
<input type="checkbox" className={cn('border-orange-[#2e323a] toggle [--tglbg:#2e323a] bg-orange-300 hover:bg-orange-400', {
116128
'bg-[#5b6372] hover:bg-[#5b6372]': !buttons.argocd_repository,
117-
}) } defaultChecked={buttons.argocd_repository} onClick={() => handleButtons("argocd_repository")} />
129+
}) } checked={buttons.argocd_repository} onChange={() => handleButtons("argocd_repository")} />
118130
</div>
119131
</div>
120132
<div className="px-4 py-2">
121133
<div className="flex items-center justify-between">
122134
<p>Application Depends Repository</p>
123135
<input type="checkbox" className={cn('border-orange-[#2e323a] toggle [--tglbg:#2e323a] bg-orange-300 hover:bg-orange-400', {
124136
'bg-[#5b6372] hover:bg-[#5b6372]': !buttons.application_depends_repository,
125-
}) } defaultChecked={buttons.application_depends_repository} onClick={() => handleButtons("application_depends_repository")} />
137+
}) } checked={buttons.application_depends_repository} onChange={() => handleButtons("application_depends_repository")} />
126138
</div>
127139
</div>
128140
</div>
129141
</div>
130-
<button disabled={isPending} onClick={handleSubmit} className="w-full py-2 mt-4 text-center transition-all bg-orange-800 rounded-md btn max-w-96 hover:bg-orange-900">{isPending ? <div className="flex items-center justify-center gap-4 disabled:opacity-80"><span className="loading loading-spinner"></span>Loading</div>: error ? "Error" : "Submit"}</button>
142+
<button disabled={isPending} onClick={() => handleSubmit()} className="w-full py-2 mt-4 text-center transition-all bg-orange-800 rounded-md btn max-w-96 hover:bg-orange-900">{isPending ? <div className="flex items-center justify-center gap-4 disabled:opacity-80"><span className="loading loading-spinner"></span>Loading</div>: error ? "Error" : "Submit"}</button>
131143
</div>
132144
);
133145
};

0 commit comments

Comments
 (0)