-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Ingest pipelines] Delete pipeline #63635
Merged
alisonelizabeth
merged 7 commits into
elastic:feature/ingest-node-pipelines
from
alisonelizabeth:ingest-pipelines/delete
Apr 20, 2020
+352
−11
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5572566
add delete route
alisonelizabeth afcefef
add delete modal
alisonelizabeth 384391c
fix bug with table selection
alisonelizabeth 34740e4
fix tests
alisonelizabeth d85d4b5
Merge branch 'feature/ingest-node-pipelines' into ingest-pipelines/de…
elasticmachine 9c48fdb
Merge branch 'feature/ingest-node-pipelines' into ingest-pipelines/de…
elasticmachine 9f97dba
address review feedback
alisonelizabeth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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({ | ||
nameOrNames: schema.string(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit; can be shortened to just |
||
}); | ||
|
||
export const registerDeleteRoute = ({ router, license }: RouteDependencies): void => { | ||
router.delete( | ||
{ | ||
path: `${API_BASE_PATH}/{nameOrNames}`, | ||
validate: { | ||
params: paramsSchema, | ||
}, | ||
}, | ||
license.guardApiRoute(async (ctx, req, res) => { | ||
const { callAsCurrentUser } = ctx.core.elasticsearch.dataClient; | ||
const { nameOrNames } = req.params; | ||
const pipelineNames = nameOrNames.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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
NotificationsStart
should be available onKibanaContextProvider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember I made a similar comment on one of your previous PRs, but I think I was incorrect. It actually looks like this is not possible with
KibanaContextProvider
, only if you create your own context withcreateKibanaReactContext
. I'm going to leave it as is for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, thanks for clarifying!