Skip to content

Commit

Permalink
feat: Add ArgoApp delete confirmation (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmevladik authored and MykolaMarusenko committed Aug 6, 2024
1 parent 3d025a5 commit 3c55435
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/components/LogViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export function SearchPopover(props: SearchPopoverProps) {
});
} catch (e) {
// Catch invalid regular expression error
console.log('Error searching logs: ', e);
// console.log('Error searching logs: ', e);
searchAddonRef.current?.findNext('');
}

Expand Down
4 changes: 3 additions & 1 deletion src/k8s/groups/EDP/Codemie/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const {
version,
} = CodemieKubeObjectConfig;

export class CodemieKubeObject extends K8s.cluster.makeKubeObject<CodemieKubeObjectInterface>(singularForm) {
export class CodemieKubeObject extends K8s.cluster.makeKubeObject<CodemieKubeObjectInterface>(
singularForm
) {
static apiEndpoint = ApiProxy.apiFactoryWithNamespace(group, version, pluralForm);

static get className(): string {
Expand Down
4 changes: 3 additions & 1 deletion src/k8s/groups/EDP/CodemieProject/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const {
version,
} = CodemieProjectKubeObjectConfig;

export class CodemieProjectKubeObject extends K8s.cluster.makeKubeObject<CodemieProjectKubeObjectInterface>(singularForm) {
export class CodemieProjectKubeObject extends K8s.cluster.makeKubeObject<CodemieProjectKubeObjectInterface>(
singularForm
) {
static apiEndpoint = ApiProxy.apiFactoryWithNamespace(group, version, pluralForm);

static get className(): string {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { FieldValues, useFormContext } from 'react-hook-form';
import { editResource } from '../../../../../k8s/common/editResource';
import { ApplicationKubeObjectInterface } from '../../../../../k8s/groups/ArgoCD/Application/types';
import { useCreateCleanPipelineRun } from '../../../../../k8s/groups/Tekton/PipelineRun/hooks/useCreateCleanPipelineRun';
import { useCreateDeployPipelineRun } from '../../../../../k8s/groups/Tekton/PipelineRun/hooks/useCreateDeployPipelineRun';
import {
Expand Down Expand Up @@ -98,18 +97,14 @@ export const useConfigurationHandlers = ({
setSelected,
enrichedApplicationsByApplicationName,
enrichedApplicationsWithArgoApplications,
deleteArgoApplication,
setDeleteDialogOpen,
}: {
values: FieldValues;
selected: string[];
setSelected: React.Dispatch<React.SetStateAction<string[]>>;
enrichedApplicationsByApplicationName: Map<string, EnrichedApplicationWithArgoApplication>;
enrichedApplicationsWithArgoApplications: EnrichedApplicationWithArgoApplication[];
deleteArgoApplication: ({
argoApplication,
}: {
argoApplication: ApplicationKubeObjectInterface;
}) => Promise<void>;
setDeleteDialogOpen?: React.Dispatch<React.SetStateAction<boolean>>;
}) => {
const { CDPipeline } = useDataContext();
const {
Expand Down Expand Up @@ -348,27 +343,8 @@ export const useConfigurationHandlers = ({
}, [handleClean, setDialog]);

const handleClickUninstall = React.useCallback(async () => {
for (const enrichedApplication of enrichedApplicationsWithArgoApplications) {
const appName = enrichedApplication.application.metadata.name;

if (!selected.includes(appName)) {
continue;
}

const argoApplication = enrichedApplicationsByApplicationName.get(appName)?.argoApplication;

await deleteArgoApplication({
argoApplication,
});
}
setSelected([]);
}, [
deleteArgoApplication,
enrichedApplicationsByApplicationName,
enrichedApplicationsWithArgoApplications,
selected,
setSelected,
]);
setDeleteDialogOpen(true);
}, [setDeleteDialogOpen]);

return {
handleClickDeploy,
Expand Down
20 changes: 19 additions & 1 deletion src/pages/stage-details/components/Applications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useCreateArgoApplication } from '../../../../k8s/groups/ArgoCD/Applicat
import { APPLICATIONS_TABLE_MODE } from '../../constants';
import { usePermissionsContext } from '../../providers/Permissions/hooks';
import { EnrichedApplicationWithArgoApplication } from '../../types';
import { ApplicationsMultiDeletion } from '../ApplicationsMultiDeletion';
import { useButtonsEnabledMap } from './hooks/useButtonsEnabled';
import { useColumns } from './hooks/useColumns';
import { useConfigurationHandlers } from './hooks/useConfigurationHandlers';
Expand All @@ -25,6 +26,10 @@ export const Applications = ({
}: ApplicationsProps) => {
const permissions = usePermissionsContext();

const allArgoApplications = enrichedApplicationsWithArgoApplications?.map(
({ argoApplication }) => argoApplication
);

const enrichedApplicationsByApplicationName = React.useMemo(() => {
return (
enrichedApplicationsWithArgoApplications &&
Expand All @@ -46,7 +51,9 @@ export const Applications = ({
);

const [selected, setSelected] = React.useState<string[]>([]);

const [mode, setMode] = React.useState<ApplicationsTableMode>(APPLICATIONS_TABLE_MODE.PREVIEW);
const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false);

const toggleMode = () =>
mode === APPLICATIONS_TABLE_MODE.PREVIEW
Expand Down Expand Up @@ -74,8 +81,8 @@ export const Applications = ({
setSelected,
enrichedApplicationsByApplicationName,
enrichedApplicationsWithArgoApplications,
deleteArgoApplication,
values,
setDeleteDialogOpen,
});

const buttonsEnabledMap = useButtonsEnabledMap({
Expand Down Expand Up @@ -239,6 +246,17 @@ export const Applications = ({
}
>
<Table<EnrichedApplicationWithArgoApplication> {..._TableProps} />
<ApplicationsMultiDeletion
applications={allArgoApplications}
selected={selected}
open={deleteDialogOpen}
handleClose={() => setDeleteDialogOpen(false)}
onDelete={() => {
setSelected([]);
setDeleteDialogOpen(false);
}}
deleteArgoApplication={deleteArgoApplication}
/>
</TabSection>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {
Button,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
TextField,
} from '@mui/material';
import React from 'react';
import { APPLICATION_LABEL_SELECTOR_APP_NAME } from '../../../../k8s/groups/ArgoCD/Application/labels';
import { ApplicationMultiDeletionProps } from './types';

const CONFIRM_TEXT_VALUE = 'confirm';

export const ApplicationsMultiDeletion = ({
applications,
open,
handleClose,
selected,
onDelete,
deleteArgoApplication,
}: ApplicationMultiDeletionProps) => {
const [value, setValue] = React.useState('');

const deletionDisabled = value !== CONFIRM_TEXT_VALUE;

const selectedApplications = React.useMemo(
() =>
applications?.filter((application) =>
selected.includes(application?.metadata?.labels?.[APPLICATION_LABEL_SELECTOR_APP_NAME])
),
[applications, selected]
);

const handleDelete = React.useCallback(() => {
if (deletionDisabled || !selectedApplications || !selectedApplications.length) {
return;
}

selectedApplications.forEach((application) => {
deleteArgoApplication({ argoApplication: application });
});

setValue('');

if (onDelete) {
onDelete();
}
}, [deleteArgoApplication, deletionDisabled, onDelete, selectedApplications]);

return (
<Dialog open={open} onClose={handleClose}>
<DialogTitle>Are you sure you want to delete the selected applications?</DialogTitle>
<DialogContent sx={{ pt: '20px !important' }}>
<Table sx={{ mb: (t) => t.typography.pxToRem(20) }}>
<TableHead>
<TableRow>
<TableCell>Application name</TableCell>
<TableCell>ArgoCD Application name</TableCell>
</TableRow>
</TableHead>
<TableBody>
{selectedApplications &&
selectedApplications?.map((application, index) => (
<TableRow key={index}>
<TableCell>
{application?.metadata?.labels?.[APPLICATION_LABEL_SELECTOR_APP_NAME]}
</TableCell>
<TableCell>{application?.metadata.name}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
<TextField
label={`Enter "${CONFIRM_TEXT_VALUE}" to start deletion`}
value={value}
onChange={(e) => setValue(e.target.value)}
variant="outlined"
fullWidth
/>
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>Cancel</Button>
<Button onClick={handleDelete} disabled={deletionDisabled} color="primary">
Delete
</Button>
</DialogActions>
</Dialog>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApplicationKubeObjectInterface } from '../../../../k8s/groups/ArgoCD/Application/types';

export interface ApplicationMultiDeletionProps {
applications: ApplicationKubeObjectInterface[];
selected: string[];
open: boolean;
handleClose: () => void;
onDelete: () => void;
deleteArgoApplication: ({ argoApplication }) => Promise<void>;
}
2 changes: 1 addition & 1 deletion src/widgets/AIChat/components/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const Chat = ({
setIsRequestLoading(true);
},
onFinish: (data) => {
console.log('finish', data);
// console.log('finish', data);
},
onError: (error) => console.log('error', error),
});
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/AIChat/hooks/useStreaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const useStreaming = <I, A, C>({
} catch (error) {
// Request was aborted by user
// if (error.name === ABORT_ERROR) return handleAbort(chat, reader);
console.log(error.name);
// console.log(error.name);
throw error;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from './Alias';
export * from './TokenName';
export * from './Type';
export * from './URL';

Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './Token';

0 comments on commit 3c55435

Please sign in to comment.