-
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] Attaching files to cases #154436
[Cases] Attaching files to cases #154436
Conversation
Fixes #151723 This PR adds a way for users to: View a list of all files attached to a case(with pagination). Attach files to a case. Preview image files attached to a case. Search for files attached to a case by file name. Download files attached to a case.
**Merging to a feature branch** ## Summary In this PR we display the number of files attached to a case in the Files tab in the case detail view. https://user-images.githubusercontent.com/1533137/228211345-58ff8c16-7201-4192-9e2e-f8c854b47da9.mov
Fixes #152088 ## Summary Users are now able to see file activity in the case detail view. - Image files have a different icon and a clickable file name to preview - Other files have a standard "document" icon and the name is not clickable - The file can be downloaded by clicking the download icon <img width="1456" alt="Screenshot 2023-03-29 at 17 31 06" src="https://user-images.githubusercontent.com/1533137/228590244-c924bf2a-c5ac-47a0-ac1e-438cd089361b.png"> If the file has invalid metadata (not likely) we display the activity item below: <img width="808" alt="Screenshot 2023-03-29 at 17 36 25" src="https://user-images.githubusercontent.com/1533137/228591686-0bdf4077-ddbf-4da1-9d23-67c02e969c2c.png">
In this PR we add the ability to delete files attached to a case. This can be done in the Case detail view either in the <details><summary>Files tab</summary> <img width="720" alt="Screenshot 2023-04-05 at 10 29 39" src="https://user-images.githubusercontent.com/1533137/230027093-072a622d-9fed-47d1-b2ac-bf4bcd14d5da.png"> </details> or the <details><summary>Activity tab</summary> <img width="1436" alt="Screenshot 2023-04-05 at 10 29 53" src="https://user-images.githubusercontent.com/1533137/230027406-509773bc-7aec-4c38-abeb-3487ca531e74.png"> </details> <details><summary>When a file is deleted the file activity item is replaced by a removed attachment activity item.</summary> <img width="1438" alt="Screenshot 2023-04-05 at 10 30 05" src="https://user-images.githubusercontent.com/1533137/230028060-a1804fd4-6484-4cb0-9147-a649c4a29ead.png"> </details>
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
Fix failing ftr tests.
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.
Great work @adcoelho ! I made it about half way through so I'll take a look at the rest later.
x-pack/plugins/cases/public/components/files/file_delete_button_icon.tsx
Outdated
Show resolved
Hide resolved
it('event renders a clickable name if the file is an image', async () => { | ||
appMockRender = createAppMockRenderer(); | ||
|
||
// @ts-ignore |
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.
Are these ts-ignore
because the event
can be a string or component?
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.
Just because event
is possibly undefined
.
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.
This is a nit but if it's because it could be undefined and we know it won't in the test we could add the !
. When I see ts-ignore
it isn't immediately clear why we need it.
...ic/components/user_actions/property_actions/registered_attachments_property_actions.test.tsx
Outdated
Show resolved
Hide resolved
.../public/components/user_actions/property_actions/registered_attachments_property_actions.tsx
Show resolved
Hide resolved
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.
Tested locally, feature looks great!! 🎉 👏
customDataTestSubj={customDataTestSubj} | ||
/> | ||
)) || | ||
(action.type === AttachmentActionType.CUSTOM && action.render())} |
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: Maybe we should check whether action.render
is not undefined?
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.
@adcoelho This looks good! I just had two comments:
- I don't think we need the button in the empty state of the table. We have the one by the search bar always there, so I think the one in the table isn't necessary.
- Are we able to add a modal around the preview of the file? I think we need the close and it would be nice to have the download / delete options for this as well. (though not as necessary)
Update translations.
Update page bundle limit.
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
Unknown metric groupsasync chunk count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @adcoelho |
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.
## Summary One of the leftover issues from #154436 was adding a few e2e tests. This PR adds e2e tests for: - Attaching a file to a case - Deleting a file attached to a case - Opening and closing the file preview in the Cases detail view - Guarantee the File User Activity is rendered correctly ## Flaky Test Runner https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2177#0187bd93-edc9-4af0-85c4-5df3f55c418c Flaky tests: (`x-pack/test/functional_with_es_ssl/apps/cases/group1/config.ts` x 50) --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
## Summary PR #154436 changed the memoization function (my fault 🙂) and that caused the attachments to rerender each time a user does an action in cases. This PR fixes this issue. **Before:** https://user-images.githubusercontent.com/7871006/235171360-62be773f-8317-4762-9f14-0310d3825a1e.mov **After:** https://user-images.githubusercontent.com/7871006/235171429-5e06f9c4-9c0a-4148-8580-bde2360169af.mov ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
## Summary PR elastic#154436 changed the memoization function (my fault 🙂) and that caused the attachments to rerender each time a user does an action in cases. This PR fixes this issue. **Before:** https://user-images.githubusercontent.com/7871006/235171360-62be773f-8317-4762-9f14-0310d3825a1e.mov **After:** https://user-images.githubusercontent.com/7871006/235171429-5e06f9c4-9c0a-4148-8580-bde2360169af.mov ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) (cherry picked from commit 60e3d98)
# Backport This will backport the following commits from `main` to `8.8`: - [[Cases] Fix attachment's renderer memoization (#156179)](#156179) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Christos Nasikas","email":"christos.nasikas@elastic.co"},"sourceCommit":{"committedDate":"2023-04-28T16:14:41Z","message":"[Cases] Fix attachment's renderer memoization (#156179)\n\n## Summary\r\n\r\nPR #154436 changed the memoization\r\nfunction (my fault 🙂) and that caused the attachments to rerender each\r\ntime a user does an action in cases. This PR fixes this issue.\r\n\r\n**Before:**\r\n\r\n\r\n\r\nhttps://user-images.githubusercontent.com/7871006/235171360-62be773f-8317-4762-9f14-0310d3825a1e.mov\r\n\r\n**After:**\r\n\r\n\r\n\r\nhttps://user-images.githubusercontent.com/7871006/235171429-5e06f9c4-9c0a-4148-8580-bde2360169af.mov\r\n\r\n\r\n\r\n### For maintainers\r\n\r\n- [x] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"60e3d98ba837d31130bf104681381ebe5a2df5c2","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:ResponseOps","Feature:Cases","v8.8.0","v8.9.0"],"number":156179,"url":"https://github.com/elastic/kibana/pull/156179","mergeCommit":{"message":"[Cases] Fix attachment's renderer memoization (#156179)\n\n## Summary\r\n\r\nPR #154436 changed the memoization\r\nfunction (my fault 🙂) and that caused the attachments to rerender each\r\ntime a user does an action in cases. This PR fixes this issue.\r\n\r\n**Before:**\r\n\r\n\r\n\r\nhttps://user-images.githubusercontent.com/7871006/235171360-62be773f-8317-4762-9f14-0310d3825a1e.mov\r\n\r\n**After:**\r\n\r\n\r\n\r\nhttps://user-images.githubusercontent.com/7871006/235171429-5e06f9c4-9c0a-4148-8580-bde2360169af.mov\r\n\r\n\r\n\r\n### For maintainers\r\n\r\n- [x] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"60e3d98ba837d31130bf104681381ebe5a2df5c2"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156179","number":156179,"mergeCommit":{"message":"[Cases] Fix attachment's renderer memoization (#156179)\n\n## Summary\r\n\r\nPR #154436 changed the memoization\r\nfunction (my fault 🙂) and that caused the attachments to rerender each\r\ntime a user does an action in cases. This PR fixes this issue.\r\n\r\n**Before:**\r\n\r\n\r\n\r\nhttps://user-images.githubusercontent.com/7871006/235171360-62be773f-8317-4762-9f14-0310d3825a1e.mov\r\n\r\n**After:**\r\n\r\n\r\n\r\nhttps://user-images.githubusercontent.com/7871006/235171429-5e06f9c4-9c0a-4148-8580-bde2360169af.mov\r\n\r\n\r\n\r\n### For maintainers\r\n\r\n- [x] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"60e3d98ba837d31130bf104681381ebe5a2df5c2"}}]}] BACKPORT--> Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
## Summary Things got a bit out of control ever since we merged #154436. In this PR I managed to reduce the cases bundle size from 166.0k to 140.0k. This was done in several different steps: ### Removing the usage of `query-string` This package took over 0.6% of the size of all chunks. <img width="694" alt="Screenshot 2023-05-12 at 15 10 52" src="https://github.com/elastic/kibana/assets/1533137/4fd4f3e3-4f58-4160-8f95-919e78c23525"> All functionality it provides could be replaced by the native [URLSearchParans](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams). I removed the package in 1ef0211. ### @kbn/cases-components The cases plugin used imports from `@kbn-cases-components` in several places, these took up 4.4% of the bundle size. <img width="757" alt="Screenshot 2023-05-12 at 15 13 48" src="https://github.com/elastic/kibana/assets/1533137/e007a239-5439-4ff2-9e5b-75fc942e86d9"> This would normally be fine but it seemed like `webpack`'s tree shaking wasn't working correctly when doing imports from the top like `import {...} from '@kbn/cases-components'`. The plugin bundle seemed to be getting too much unnecessary code so I changed the imports in 547755c to be more specific. Now `@kbn/cases-components` only takes up 0.1% of the bundle size. <img width="761" alt="Screenshot 2023-05-12 at 15 17 24" src="https://github.com/elastic/kibana/assets/1533137/99426547-de38-47f2-9f3c-aabf881a2854"> ### Removing unnecessary public exports > Code that is shared statically with other plugins will contribute to the page load bundle size of that plugin. This includes exports from the `public/index.ts` file and any file referenced by the `extraPublicDirs` manifest property. I read the above in the documentation and checked what we exported. I found a bunch of things that we were exporting but that actually weren't being used by other plugins. I removed those unnecessary exports in 6a0ff8c. ### Unnecessary exports part 2 After merging the multiple file-related branches we were exporting the `imageMimeTypes` variable(a quite large array) twice. 53135ec It belonged to `common/` that is referenced in `extraPublicDirs` so that saved us a few more Ks. ### Cases plugin > Code that is shared statically with other plugins will contribute to the page load bundle size of that plugin. In the cases plugin `start` we were returning a deprecated function that was not being used anywhere any more. I removed it -0.9K 🤷 42b30b3 ### Making the `clientAPI` lazy Once again, > Code that is shared statically with other plugins will contribute to the page load bundle size of that plugin. I was going over everything that our plugin exports to see if something was not used and noticed that the functions we return in `cases.api` are not used by everyone. They were already promises so I changed the implementation to lazy load the code. A good rule of thumb here is that if the chunk is not always needed at setup/start time it might benefit from being lazy loaded. <ins>Some</ins> plugins need <ins>some</ins> of this code so we can `async import()` and reduce the `page load bundle size` significantly. See e201ab1. ### Lazy loading components in the file attachment During the cases plugin setup step we register the file's internal attachment. This defines how the file user action will look on the Case Detail page so naturally it requires a bunch of components to be loaded. The mistake here was that we don't need those components to be loaded right away. I followed [React's guidelines](https://react.dev/reference/react/lazy#lazy) for lazy loading all components in the registered object greatly decreasing the bundle size in 1c9ede7.
Fixes #151595
Summary
In this PR we will be merging a feature branch into
main
.This feature branch is a collection of several different PRs with file functionality for cases.
Most of the code was already reviewed so this will mainly be used for testing.
clickable.
Release notes
Support file attachments in Cases.