Skip to content

Commit

Permalink
[8.8] [Cases] Fix attachment's renderer memoization (#156179) (#156201)
Browse files Browse the repository at this point in the history
# 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>
  • Loading branch information
kibanamachine and cnasikas authored Apr 28, 2023
1 parent a5b0071 commit d25736c
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ type BuilderArgs<C, R> = Pick<
/**
* Provides a render function for attachment type
*/
const getAttachmentRenderer = memoize((attachmentViewObject: AttachmentViewObject) => {
const getAttachmentRenderer = memoize(() => {
let AttachmentElement: React.ReactElement;

const renderCallback = (props: object) => {
const renderCallback = (attachmentViewObject: AttachmentViewObject, props: object) => {
if (!attachmentViewObject.children) return;

if (!AttachmentElement) {
Expand Down Expand Up @@ -120,7 +120,7 @@ export const createRegisteredAttachmentUserActionBuilder = <

const attachmentViewObject = attachmentType.getAttachmentViewObject(props);

const renderer = getAttachmentRenderer(attachmentViewObject);
const renderer = getAttachmentRenderer();
const actions = attachmentViewObject.getActions?.(props) ?? [];
const [primaryActions, nonPrimaryActions] = partition(actions, 'isPrimary');
const visiblePrimaryActions = primaryActions.slice(0, 2);
Expand Down Expand Up @@ -164,7 +164,7 @@ export const createRegisteredAttachmentUserActionBuilder = <
/>
</UserActionContentToolbar>
),
children: renderer(props),
children: renderer(attachmentViewObject, props),
},
];
},
Expand Down

0 comments on commit d25736c

Please sign in to comment.