Skip to content

Commit

Permalink
feat(ui): Show prompt when every resource requires pruning (argoproj#…
Browse files Browse the repository at this point in the history
…16603)

* fix(ui): show prompt when using prune option

Signed-off-by: ashutosh16 <11219262+ashutosh16@users.noreply.github.com>

* fix(ui): show prompt when using prune option

Signed-off-by: ashutosh16 <11219262+ashutosh16@users.noreply.github.com>

* fix(ui): show prompt when using prune option

Signed-off-by: ashutosh16 <11219262+ashutosh16@users.noreply.github.com>

fix(ui): show prompt when using prune option

Signed-off-by: ashutosh16 <11219262+ashutosh16@users.noreply.github.com>

* chore: update message and simplify code

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* don't warn on partial sync

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* fix(ui): lint

Signed-off-by: ashutosh16 <11219262+ashutosh16@users.noreply.github.com>

---------

Signed-off-by: ashutosh16 <11219262+ashutosh16@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Kevin Lyda <kevin@lyda.ie>
  • Loading branch information
2 people authored and lyda committed Mar 28, 2024
1 parent bc7a575 commit b235f19
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import './application-sync-options.scss';

export const REPLACE_WARNING = `The resources will be synced using 'kubectl replace/create' command that is a potentially destructive action and might cause resources recreation.`;
export const FORCE_WARNING = `The resources will be synced using '--force' that is a potentially destructive action and will immediately remove resources from the API and bypasses graceful deletion. Immediate deletion of some resources may result in inconsistency or data loss.`;
export const PRUNE_ALL_WARNING = `The resources will be synced using '--prune', and all resources are marked to be pruned. Only continue if you want to delete all of the Application's resources.`;

export interface ApplicationSyncOptionProps {
options: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import {Consumer} from '../../../shared/context';
import * as models from '../../../shared/models';
import {services} from '../../../shared/services';
import {ApplicationRetryOptions} from '../application-retry-options/application-retry-options';
import {ApplicationManualSyncFlags, ApplicationSyncOptions, FORCE_WARNING, SyncFlags, REPLACE_WARNING} from '../application-sync-options/application-sync-options';
import {
ApplicationManualSyncFlags,
ApplicationSyncOptions,
FORCE_WARNING,
SyncFlags,
REPLACE_WARNING,
PRUNE_ALL_WARNING
} from '../application-sync-options/application-sync-options';
import {ComparisonStatusIcon, getAppDefaultSource, nodeKey} from '../utils';

import './application-sync-panel.scss';
Expand Down Expand Up @@ -57,9 +64,25 @@ export const ApplicationSyncPanel = ({application, selectedResource, hide}: {app
})}
onSubmit={async (params: any) => {
setPending(true);
let resources = appResources.filter((_, i) => params.resources[i]);
if (resources.length === appResources.length) {
resources = null;
let selectedResources = appResources.filter((_, i) => params.resources[i]);
const allResourcesAreSelected = selectedResources.length === appResources.length;
const syncFlags = {...params.syncFlags} as SyncFlags;

const allRequirePruning = !selectedResources.some(resource => !resource?.requiresPruning);
if (syncFlags.Prune && allRequirePruning && allResourcesAreSelected) {
const confirmed = await ctx.popup.confirm('Prune all resources?', () => (
<div>
<i className='fa fa-exclamation-triangle' style={{color: ARGO_WARNING_COLOR}} />
{PRUNE_ALL_WARNING} Are you sure you want to continue?
</div>
));
if (!confirmed) {
setPending(false);
return;
}
}
if (allResourcesAreSelected) {
selectedResources = null;
}
const replace = params.syncOptions?.findIndex((opt: string) => opt === 'Replace=true') > -1;
if (replace) {
Expand All @@ -74,7 +97,6 @@ export const ApplicationSyncPanel = ({application, selectedResource, hide}: {app
}
}

const syncFlags = {...params.syncFlags} as SyncFlags;
const force = syncFlags.Force || false;

if (syncFlags.ApplyOnly) {
Expand Down Expand Up @@ -102,7 +124,7 @@ export const ApplicationSyncPanel = ({application, selectedResource, hide}: {app
syncFlags.Prune || false,
syncFlags.DryRun || false,
syncStrategy,
resources,
selectedResources,
params.syncOptions,
params.retryStrategy
);
Expand Down

0 comments on commit b235f19

Please sign in to comment.