-
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
[Cases] Deleting file attachments from a case #154432
Merged
adcoelho
merged 6 commits into
elastic:cases-detail-view-files-tab
from
adcoelho:file-attachment-delete-button
Apr 6, 2023
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f5167f1
Changed file metadata to have caseId array.
adcoelho a815917
Added api tests for deleteFileAttachments.
adcoelho 483ffce
Changed the gutterSize for actions in case view.
adcoelho 7fba826
Added file deletion confirmation modal.
adcoelho 9009f41
Added delete button tests for file_type.
adcoelho 8941664
Disable delete button if user has no permissions.
adcoelho 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
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/cases/public/components/files/file_delete_button_icon.test.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,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import type { AppMockRenderer } from '../../common/mock'; | ||
|
||
import { createAppMockRenderer } from '../../common/mock'; | ||
import { basicCaseId, basicFileMock } from '../../containers/mock'; | ||
import { useDeleteFileAttachment } from '../../containers/use_delete_file_attachment'; | ||
import { FileDeleteButtonIcon } from './file_delete_button_icon'; | ||
|
||
jest.mock('../../containers/use_delete_file_attachment'); | ||
|
||
const useDeleteFileAttachmentMock = useDeleteFileAttachment as jest.Mock; | ||
|
||
describe('FileDeleteButtonIcon', () => { | ||
let appMockRender: AppMockRenderer; | ||
const mutate = jest.fn(); | ||
|
||
useDeleteFileAttachmentMock.mockReturnValue({ isLoading: false, mutate }); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
appMockRender = createAppMockRenderer(); | ||
}); | ||
|
||
it('renders delete button correctly', async () => { | ||
appMockRender.render(<FileDeleteButtonIcon caseId={basicCaseId} fileId={basicFileMock.id} />); | ||
|
||
expect(await screen.findByTestId('cases-files-delete-button')).toBeInTheDocument(); | ||
|
||
expect(useDeleteFileAttachmentMock).toBeCalledTimes(1); | ||
}); | ||
|
||
it('clicking delete button opens the confirmation modal', async () => { | ||
appMockRender.render(<FileDeleteButtonIcon caseId={basicCaseId} fileId={basicFileMock.id} />); | ||
|
||
const deleteButton = await screen.findByTestId('cases-files-delete-button'); | ||
|
||
expect(deleteButton).toBeInTheDocument(); | ||
|
||
userEvent.click(deleteButton); | ||
|
||
expect(await screen.findAllByTestId('property-actions-confirm-modal')); | ||
}); | ||
|
||
it('clicking delete button in the confirmation modal calls deleteFileAttachment with proper params', async () => { | ||
appMockRender.render(<FileDeleteButtonIcon caseId={basicCaseId} fileId={basicFileMock.id} />); | ||
|
||
const deleteButton = await screen.findByTestId('cases-files-delete-button'); | ||
|
||
expect(deleteButton).toBeInTheDocument(); | ||
|
||
userEvent.click(deleteButton); | ||
|
||
expect(await screen.findAllByTestId('property-actions-confirm-modal')); | ||
|
||
userEvent.click(await screen.findByTestId('confirmModalConfirmButton')); | ||
|
||
await waitFor(() => { | ||
expect(mutate).toHaveBeenCalledTimes(1); | ||
expect(mutate).toHaveBeenCalledWith({ | ||
caseId: basicCaseId, | ||
fileId: basicFileMock.id, | ||
}); | ||
}); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
x-pack/plugins/cases/public/components/files/file_delete_button_icon.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,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { EuiButtonIcon } from '@elastic/eui'; | ||
import * as i18n from './translations'; | ||
import { useDeleteFileAttachment } from '../../containers/use_delete_file_attachment'; | ||
import { useDeletePropertyAction } from '../user_actions/property_actions/use_delete_property_action'; | ||
import { DeleteAttachmentConfirmationModal } from '../user_actions/delete_attachment_confirmation_modal'; | ||
|
||
interface FileDeleteButtonIconProps { | ||
caseId: string; | ||
fileId: string; | ||
} | ||
|
||
const FileDeleteButtonIconComponent: React.FC<FileDeleteButtonIconProps> = ({ caseId, fileId }) => { | ||
const { isLoading, mutate: deleteFileAttachment } = useDeleteFileAttachment(); | ||
|
||
const { showDeletionModal, onModalOpen, onConfirm, onCancel } = useDeletePropertyAction({ | ||
onDelete: () => deleteFileAttachment({ caseId, fileId }), | ||
}); | ||
|
||
return ( | ||
<> | ||
<EuiButtonIcon | ||
iconType={'trash'} | ||
aria-label={i18n.DELETE_FILE} | ||
color={'danger'} | ||
isDisabled={isLoading} | ||
onClick={onModalOpen} | ||
data-test-subj={'cases-files-delete-button'} | ||
/> | ||
{showDeletionModal ? ( | ||
<DeleteAttachmentConfirmationModal | ||
title={i18n.DELETE_FILE_TITLE} | ||
confirmButtonText={i18n.DELETE} | ||
onCancel={onCancel} | ||
onConfirm={onConfirm} | ||
/> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
FileDeleteButtonIconComponent.displayName = 'FileDeleteButtonIcon'; | ||
|
||
export const FileDeleteButtonIcon = React.memo(FileDeleteButtonIconComponent); |
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
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. Can you add a test where we delete a file from the files table? |
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
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
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.
Can you add a test where we delete a file from the user activity?