Skip to content

Commit 586fa29

Browse files
committed
preserve enabled field when modifying prune or self heal
Signed-off-by: Atif Ali <[email protected]>
1 parent 1f13388 commit 586fa29

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

ui/src/app/applications/components/application-summary/application-summary.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,18 @@ export const ApplicationSummary = (props: ApplicationSummaryProps) => {
372372
});
373373
}
374374

375-
async function setAutoSync(ctx: ContextApis, confirmationTitle: string, confirmationText: string, prune: boolean, selfHeal: boolean) {
375+
async function setAutoSync(ctx: ContextApis, confirmationTitle: string, confirmationText: string, prune: boolean, selfHeal: boolean, enable: boolean) {
376376
const confirmed = await ctx.popup.confirm(confirmationTitle, confirmationText);
377377
if (confirmed) {
378378
try {
379379
setChangeSync(true);
380380
const updatedApp = JSON.parse(JSON.stringify(props.app)) as models.Application;
381-
if (!updatedApp.spec.syncPolicy) {
381+
if (!updatedApp.spec.syncPolicy) {
382382
updatedApp.spec.syncPolicy = {};
383383
}
384-
updatedApp.spec.syncPolicy.automated = {prune, selfHeal, enabled: true};
384+
//preserve the current enabled state when modifying prune or self heal
385+
const currentEnabled = updatedApp.spec.syncPolicy.automated?.enabled;
386+
updatedApp.spec.syncPolicy.automated = {prune, selfHeal, enabled: currentEnabled ?? enable};
385387
await updateApp(updatedApp, {validate: false});
386388
} catch (e) {
387389
ctx.notifications.show({
@@ -518,7 +520,7 @@ export const ApplicationSummary = (props: ApplicationSummaryProps) => {
518520
<button
519521
className='argo-button argo-button--base'
520522
onClick={() =>
521-
setAutoSync(ctx, 'Enable Auto-Sync?', 'Are you sure you want to enable automated application synchronization?', false, false)
523+
setAutoSync(ctx, 'Enable Auto-Sync?', 'Are you sure you want to enable automated application synchronization?', false, false, true)
522524
}>
523525
<Spinner show={changeSync} style={{marginRight: '5px'}} />
524526
Enable Auto-Sync
@@ -554,8 +556,7 @@ export const ApplicationSummary = (props: ApplicationSummaryProps) => {
554556
await updateApp(updatedApp, {validate: false});
555557
}
556558
}}
557-
checked={!!app.spec.syncPolicy?.automated?.enabled}
558-
id='enable-auto-sync'
559+
checked={app.spec.syncPolicy?.automated ? (app.spec.syncPolicy.automated.enabled !== false) : false} id='enable-auto-sync'
559560
/>
560561
<label htmlFor='enable-auto-sync'>ENABLE AUTO-SYNC</label>
561562
<HelpIcon title='If checked, application will automatically sync when changes are detected' />

0 commit comments

Comments
 (0)