-
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] Bulk edit tags: Prevent error when updating cases with the same tags #145608
Conversation
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
@@ -37,16 +38,26 @@ export const useTagsAction = ({ onAction, onActionSuccess, isDisabled }: UseActi | |||
(tagsSelection: TagsSelectionState) => { | |||
onAction(); | |||
onFlyoutClosed(); | |||
const casesToUpdate = selectedCasesToEditTags.map((theCase) => { | |||
|
|||
const casesToUpdate = selectedCasesToEditTags.reduce((acc, theCase) => { |
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 changed it to reduce
to map
and filter
at the same time
const tags = difference(theCase.tags, tagsSelection.unSelectedTags); | ||
const uniqueTags = new Set([...tags, ...tagsSelection.selectedTags]); | ||
const uniqueTagsAsArray = Array.from(uniqueTags.values()); | ||
|
||
if (isEqual(theCase.tags, uniqueTagsAsArray)) { |
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.
No need to update the case if the original tags are the same as the new ones
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.
How would sorting work for these arrays? If the arrays contain the same strings but are in a different order isEqual
will return false
. Maybe that's ok though, I'd have to check the backend to see if it would still throw an error in that situation. I suppose ideally we'd just skip the update since reordering the tags doesn't really do much in the UI.
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.
Thanks, I was not aware of that. I fixed it here a200227. As we have already a set of uniqueTags
I iterate through the theCase.tags
and check if it is a member of the uniqueTags
set. If all of the elements are part of the set then the tags are identical and there is no need to do an update.
const tags = difference(theCase.tags, tagsSelection.unSelectedTags); | ||
const uniqueTags = new Set([...tags, ...tagsSelection.selectedTags]); | ||
const uniqueTagsAsArray = Array.from(uniqueTags.values()); | ||
|
||
if (isEqual(theCase.tags, uniqueTagsAsArray)) { |
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.
How would sorting work for these arrays? If the arrays contain the same strings but are in a different order isEqual
will return false
. Maybe that's ok though, I'd have to check the backend to see if it would still throw an error in that situation. I suppose ideally we'd just skip the update since reordering the tags doesn't really do much in the UI.
const uniqueTagsAsArray = Array.from(uniqueTags.values()); | ||
|
||
if (isEqual(theCase.tags, uniqueTagsAsArray)) { | ||
onActionSuccess(); |
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.
Why do we want to call the success callback here? Would that trigger a refresh of the cases?
const tagsAction = useTagsAction({
isDisabled: false,
onAction: closePopover,
onActionSuccess: refreshCases,
});
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.
My mistake! I forgot to remove it.
version: theCase.version, | ||
}, | ||
]; | ||
}, [] as CaseUpdateRequest[]); |
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.
As discussed with @cnasikas , I still see the error toast as an empty array casesToUpdate
is getting sent to the backend.
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.
Fixed in a200227
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.
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.
Created #145736 to fix this in the View case page.
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 latest edits and LGTM
}; | ||
}); | ||
const casesToUpdate = selectedCasesToEditTags.reduce((acc, theCase) => { | ||
const tagsWithoutUnselectedTags = difference(theCase.tags, tagsSelection.unSelectedTags); |
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.
If you make this one a set too you can just use lodash's .isEqual()
instead of the aux function.
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.
Done!
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
Unknown metric groupsESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @cnasikas |
…me tags (elastic#145608) ## Summary This PR fixes a bug where an error occurs when updating the case with the same tags. To fix it, we filter cases without any changes. Fixes: elastic#145217 ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### 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 b1fb286)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…the same tags (#145608) (#145886) # Backport This will backport the following commits from `main` to `8.6`: - [[Cases] Bulk edit tags: Prevent error when updating cases with the same tags (#145608)](#145608) <!--- 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":"2022-11-21T15:51:00Z","message":"[Cases] Bulk edit tags: Prevent error when updating cases with the same tags (#145608)\n\n## Summary\r\n\r\nThis PR fixes a bug where an error occurs when updating the case with\r\nthe same tags. To fix it, we filter cases without any changes.\r\n\r\nFixes: https://github.com/elastic/kibana/issues/145217\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\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":"b1fb286d84158f75b95d4a9f875df6d07d6c1214","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:ResponseOps","Feature:Cases","v8.6.0","v8.7.0"],"number":145608,"url":"https://github.com/elastic/kibana/pull/145608","mergeCommit":{"message":"[Cases] Bulk edit tags: Prevent error when updating cases with the same tags (#145608)\n\n## Summary\r\n\r\nThis PR fixes a bug where an error occurs when updating the case with\r\nthe same tags. To fix it, we filter cases without any changes.\r\n\r\nFixes: https://github.com/elastic/kibana/issues/145217\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\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":"b1fb286d84158f75b95d4a9f875df6d07d6c1214"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145608","number":145608,"mergeCommit":{"message":"[Cases] Bulk edit tags: Prevent error when updating cases with the same tags (#145608)\n\n## Summary\r\n\r\nThis PR fixes a bug where an error occurs when updating the case with\r\nthe same tags. To fix it, we filter cases without any changes.\r\n\r\nFixes: https://github.com/elastic/kibana/issues/145217\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\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":"b1fb286d84158f75b95d4a9f875df6d07d6c1214"}}]}] BACKPORT--> Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
Summary
This PR fixes a bug where an error occurs when updating the case with the same tags. To fix it, we filter cases without any changes.
Fixes: #145217
Checklist
Delete any items that are not applicable to this PR.
For maintainers