-
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.
- Loading branch information
1 parent
60ed0b5
commit 8be87b9
Showing
6 changed files
with
320 additions
and
176 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
x-pack/plugins/saved_objects_tagging/public/management/actions/assign.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,71 @@ | ||
/* | ||
* 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 { Action as EuiTableAction } from '@elastic/eui/src/components/basic_table/action_types'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { NotificationsStart, OverlayStart } from 'kibana/public'; | ||
import { TagWithRelations } from '../../../common'; | ||
import { ITagsCache } from '../../services/tags'; | ||
import { getAssignFlyoutOpener } from '../../components/assign_flyout'; | ||
import { ITagAssignmentService } from '../../services/assignments'; | ||
|
||
interface GetAssignActionOptions { | ||
overlays: OverlayStart; | ||
notifications: NotificationsStart; | ||
tagCache: ITagsCache; | ||
assignmentService: ITagAssignmentService; | ||
assignableTypes: string[]; | ||
fetchTags: () => Promise<void>; | ||
} | ||
|
||
export const getAssignAction = ({ | ||
notifications, | ||
overlays, | ||
assignableTypes, | ||
assignmentService, | ||
tagCache, | ||
fetchTags, | ||
}: GetAssignActionOptions): EuiTableAction<TagWithRelations> => { | ||
const openFlyout = getAssignFlyoutOpener({ | ||
overlays, | ||
notifications, | ||
tagCache, | ||
assignmentService, | ||
assignableTypes, | ||
}); | ||
|
||
return { | ||
name: ({ name }) => | ||
i18n.translate('xpack.savedObjectsTagging.management.table.actions.assign.title', { | ||
defaultMessage: 'Manage {name} assignments', | ||
values: { name }, | ||
}), | ||
description: i18n.translate( | ||
'xpack.savedObjectsTagging.management.table.actions.assign.description', | ||
{ | ||
defaultMessage: 'Manage assignments', | ||
} | ||
), | ||
type: 'icon', | ||
icon: 'tag', | ||
onClick: async (tag: TagWithRelations) => { | ||
const flyout = await openFlyout({ | ||
tagIds: [tag.id], | ||
}); | ||
|
||
// TODO | ||
/* | ||
canceled$.pipe(takeUntil(from(flyout.onClose))).subscribe(() => { | ||
flyout.close(); | ||
}); | ||
*/ | ||
|
||
await flyout.onClose; | ||
await fetchTags(); | ||
}, | ||
'data-test-subj': 'tagsTableAction-assign', | ||
}; | ||
}; |
82 changes: 82 additions & 0 deletions
82
x-pack/plugins/saved_objects_tagging/public/management/actions/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,82 @@ | ||
/* | ||
* 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 { Action as EuiTableAction } from '@elastic/eui/src/components/basic_table/action_types'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { NotificationsStart, OverlayStart } from 'kibana/public'; | ||
import { TagWithRelations } from '../../../common'; | ||
import { ITagInternalClient } from '../../services/tags'; | ||
|
||
interface GetDeleteActionOptions { | ||
overlays: OverlayStart; | ||
notifications: NotificationsStart; | ||
tagClient: ITagInternalClient; | ||
fetchTags: () => Promise<void>; | ||
} | ||
|
||
export const getDeleteAction = ({ | ||
notifications, | ||
overlays, | ||
tagClient, | ||
fetchTags, | ||
}: GetDeleteActionOptions): EuiTableAction<TagWithRelations> => { | ||
return { | ||
name: ({ name }) => | ||
i18n.translate('xpack.savedObjectsTagging.management.table.actions.delete.title', { | ||
defaultMessage: 'Delete {name} tag', | ||
values: { name }, | ||
}), | ||
description: i18n.translate( | ||
'xpack.savedObjectsTagging.management.table.actions.delete.description', | ||
{ | ||
defaultMessage: 'Delete this tag', | ||
} | ||
), | ||
type: 'icon', | ||
icon: 'trash', | ||
onClick: async (tag: TagWithRelations) => { | ||
const confirmed = await overlays.openConfirm( | ||
i18n.translate('xpack.savedObjectsTagging.modals.confirmDelete.text', { | ||
defaultMessage: | ||
'By deleting this tag, you will no longer be able to assign it to saved objects. ' + | ||
'This tag will be removed from any saved objects that currently use it. ' + | ||
'Are you sure you wish to proceed?', | ||
}), | ||
{ | ||
title: i18n.translate('xpack.savedObjectsTagging.modals.confirmDelete.title', { | ||
defaultMessage: 'Delete "{name}" tag', | ||
values: { | ||
name: tag.name, | ||
}, | ||
}), | ||
confirmButtonText: i18n.translate( | ||
'xpack.savedObjectsTagging.modals.confirmDelete.confirmButtonText', | ||
{ | ||
defaultMessage: 'Delete tag', | ||
} | ||
), | ||
buttonColor: 'danger', | ||
maxWidth: 560, | ||
} | ||
); | ||
if (confirmed) { | ||
await tagClient.delete(tag.id); | ||
|
||
notifications.toasts.addSuccess({ | ||
title: i18n.translate('xpack.savedObjectsTagging.notifications.deleteTagSuccessTitle', { | ||
defaultMessage: 'Deleted "{name}" tag', | ||
values: { | ||
name: tag.name, | ||
}, | ||
}), | ||
}); | ||
|
||
await fetchTags(); | ||
} | ||
}, | ||
'data-test-subj': 'tagsTableAction-delete', | ||
}; | ||
}; |
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/saved_objects_tagging/public/management/actions/edit.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,61 @@ | ||
/* | ||
* 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 { Action as EuiTableAction } from '@elastic/eui/src/components/basic_table/action_types'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { NotificationsStart, OverlayStart } from 'kibana/public'; | ||
import { TagWithRelations } from '../../../common'; | ||
import { ITagInternalClient } from '../../services/tags'; | ||
import { getEditModalOpener } from '../../components/edition_modal'; | ||
|
||
interface GetEditActionOptions { | ||
overlays: OverlayStart; | ||
notifications: NotificationsStart; | ||
tagClient: ITagInternalClient; | ||
fetchTags: () => Promise<void>; | ||
} | ||
|
||
export const getEditAction = ({ | ||
notifications, | ||
overlays, | ||
tagClient, | ||
fetchTags, | ||
}: GetEditActionOptions): EuiTableAction<TagWithRelations> => { | ||
const editModalOpener = getEditModalOpener({ overlays, tagClient }); | ||
return { | ||
name: ({ name }) => | ||
i18n.translate('xpack.savedObjectsTagging.management.table.actions.edit.title', { | ||
defaultMessage: 'Edit {name} tag', | ||
values: { name }, | ||
}), | ||
isPrimary: true, | ||
description: i18n.translate( | ||
'xpack.savedObjectsTagging.management.table.actions.edit.description', | ||
{ | ||
defaultMessage: 'Edit this tag', | ||
} | ||
), | ||
type: 'icon', | ||
icon: 'pencil', | ||
onClick: (tag: TagWithRelations) => { | ||
editModalOpener({ | ||
tagId: tag.id, | ||
onUpdate: (updatedTag) => { | ||
fetchTags(); | ||
notifications.toasts.addSuccess({ | ||
title: i18n.translate('xpack.savedObjectsTagging.notifications.editTagSuccessTitle', { | ||
defaultMessage: 'Saved changes to "{name}" tag', | ||
values: { | ||
name: updatedTag.name, | ||
}, | ||
}), | ||
}); | ||
}, | ||
}); | ||
}, | ||
'data-test-subj': 'tagsTableAction-edit', | ||
}; | ||
}; |
60 changes: 60 additions & 0 deletions
60
x-pack/plugins/saved_objects_tagging/public/management/actions/index.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,60 @@ | ||
/* | ||
* 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 { Action as EuiTableAction } from '@elastic/eui/src/components/basic_table/action_types'; | ||
import { CoreStart } from 'kibana/public'; | ||
import { TagsCapabilities, TagWithRelations } from '../../../common'; | ||
import { ITagInternalClient, ITagAssignmentService, ITagsCache } from '../../services'; | ||
import { getDeleteAction } from './delete'; | ||
import { getEditAction } from './edit'; | ||
import { getAssignAction } from './assign'; | ||
|
||
interface GetActionsOptions { | ||
core: CoreStart; | ||
capabilities: TagsCapabilities; | ||
tagClient: ITagInternalClient; | ||
tagCache: ITagsCache; | ||
assignmentService: ITagAssignmentService; | ||
setLoading: (loading: boolean) => void; | ||
assignableTypes: string[]; | ||
fetchTags: () => Promise<void>; | ||
} | ||
|
||
export const getTableActions = ({ | ||
core: { notifications, overlays }, | ||
capabilities, | ||
tagClient, | ||
tagCache, | ||
assignmentService, | ||
setLoading, | ||
assignableTypes, | ||
fetchTags, | ||
}: GetActionsOptions): Array<EuiTableAction<TagWithRelations>> => { | ||
const actions: Array<EuiTableAction<TagWithRelations>> = []; | ||
|
||
if (capabilities.edit) { | ||
actions.push(getEditAction({ notifications, overlays, tagClient, fetchTags })); | ||
} | ||
|
||
if (capabilities.assign && assignableTypes.length > 0) { | ||
actions.push( | ||
getAssignAction({ | ||
tagCache, | ||
assignmentService, | ||
assignableTypes, | ||
fetchTags, | ||
notifications, | ||
overlays, | ||
}) | ||
); | ||
} | ||
|
||
if (capabilities.delete) { | ||
actions.push(getDeleteAction({ overlays, notifications, tagClient, fetchTags })); | ||
} | ||
|
||
return actions; | ||
}; |
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.