-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ingest pipelines] Delete pipeline (#63635)
- Loading branch information
1 parent
7e7d776
commit 6ffaeda
Showing
12 changed files
with
352 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/delete_modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiConfirmModal, EuiOverlayMask } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
||
import { useKibana } from '../../../shared_imports'; | ||
|
||
export const PipelineDeleteModal = ({ | ||
pipelinesToDelete, | ||
callback, | ||
}: { | ||
pipelinesToDelete: string[]; | ||
callback: (data?: { hasDeletedPipelines: boolean }) => void; | ||
}) => { | ||
const { services } = useKibana(); | ||
|
||
const numPipelinesToDelete = pipelinesToDelete.length; | ||
|
||
const handleDeletePipelines = () => { | ||
services.api | ||
.deletePipelines(pipelinesToDelete) | ||
.then(({ data: { itemsDeleted, errors }, error }) => { | ||
const hasDeletedPipelines = itemsDeleted && itemsDeleted.length; | ||
|
||
if (hasDeletedPipelines) { | ||
const successMessage = | ||
itemsDeleted.length === 1 | ||
? i18n.translate( | ||
'xpack.ingestPipelines.deleteModal.successDeleteSingleNotificationMessageText', | ||
{ | ||
defaultMessage: "Deleted pipeline '{pipelineName}'", | ||
values: { pipelineName: pipelinesToDelete[0] }, | ||
} | ||
) | ||
: i18n.translate( | ||
'xpack.ingestPipelines.deleteModal.successDeleteMultipleNotificationMessageText', | ||
{ | ||
defaultMessage: | ||
'Deleted {numSuccesses, plural, one {# pipeline} other {# pipelines}}', | ||
values: { numSuccesses: itemsDeleted.length }, | ||
} | ||
); | ||
|
||
callback({ hasDeletedPipelines }); | ||
services.notifications.toasts.addSuccess(successMessage); | ||
} | ||
|
||
if (error || errors?.length) { | ||
const hasMultipleErrors = errors?.length > 1 || (error && pipelinesToDelete.length > 1); | ||
const errorMessage = hasMultipleErrors | ||
? i18n.translate( | ||
'xpack.ingestPipelines.deleteModal.multipleErrorsNotificationMessageText', | ||
{ | ||
defaultMessage: 'Error deleting {count} pipelines', | ||
values: { | ||
count: errors?.length || pipelinesToDelete.length, | ||
}, | ||
} | ||
) | ||
: i18n.translate('xpack.ingestPipelines.deleteModal.errorNotificationMessageText', { | ||
defaultMessage: "Error deleting pipeline '{name}'", | ||
values: { name: (errors && errors[0].name) || pipelinesToDelete[0] }, | ||
}); | ||
services.notifications.toasts.addDanger(errorMessage); | ||
} | ||
}); | ||
}; | ||
|
||
const handleOnCancel = () => { | ||
callback(); | ||
}; | ||
|
||
return ( | ||
<EuiOverlayMask> | ||
<EuiConfirmModal | ||
buttonColor="danger" | ||
data-test-subj="deletePipelinesConfirmation" | ||
title={ | ||
<FormattedMessage | ||
id="xpack.ingestPipelines.deleteModal.modalTitleText" | ||
defaultMessage="Delete {numPipelinesToDelete, plural, one {pipeline} other {# pipelines}}" | ||
values={{ numPipelinesToDelete }} | ||
/> | ||
} | ||
onCancel={handleOnCancel} | ||
onConfirm={handleDeletePipelines} | ||
cancelButtonText={ | ||
<FormattedMessage | ||
id="xpack.ingestPipelines.deleteModal.cancelButtonLabel" | ||
defaultMessage="Cancel" | ||
/> | ||
} | ||
confirmButtonText={ | ||
<FormattedMessage | ||
id="xpack.ingestPipelines.deleteModal.confirmButtonLabel" | ||
defaultMessage="Delete {numPipelinesToDelete, plural, one {pipeline} other {pipelines} }" | ||
values={{ numPipelinesToDelete }} | ||
/> | ||
} | ||
> | ||
<> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.ingestPipelines.deleteModal.deleteDescription" | ||
defaultMessage="You are about to delete {numPipelinesToDelete, plural, one {this pipeline} other {these pipelines} }:" | ||
values={{ numPipelinesToDelete }} | ||
/> | ||
</p> | ||
|
||
<ul> | ||
{pipelinesToDelete.map(name => ( | ||
<li key={name}>{name}</li> | ||
))} | ||
</ul> | ||
</> | ||
</EuiConfirmModal> | ||
</EuiOverlayMask> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/ingest_pipelines/server/routes/api/delete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { schema } from '@kbn/config-schema'; | ||
|
||
import { API_BASE_PATH } from '../../../common/constants'; | ||
import { RouteDependencies } from '../../types'; | ||
|
||
const paramsSchema = schema.object({ | ||
names: schema.string(), | ||
}); | ||
|
||
export const registerDeleteRoute = ({ router, license }: RouteDependencies): void => { | ||
router.delete( | ||
{ | ||
path: `${API_BASE_PATH}/{names}`, | ||
validate: { | ||
params: paramsSchema, | ||
}, | ||
}, | ||
license.guardApiRoute(async (ctx, req, res) => { | ||
const { callAsCurrentUser } = ctx.core.elasticsearch.dataClient; | ||
const { names } = req.params; | ||
const pipelineNames = names.split(','); | ||
|
||
const response: { itemsDeleted: string[]; errors: any[] } = { | ||
itemsDeleted: [], | ||
errors: [], | ||
}; | ||
|
||
await Promise.all( | ||
pipelineNames.map(pipelineName => { | ||
return callAsCurrentUser('ingest.deletePipeline', { id: pipelineName }) | ||
.then(() => response.itemsDeleted.push(pipelineName)) | ||
.catch(e => | ||
response.errors.push({ | ||
name: pipelineName, | ||
error: e, | ||
}) | ||
); | ||
}) | ||
); | ||
|
||
return res.ok({ body: response }); | ||
}) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.