-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[SIEM] [Cases] Delete, comment, and reducer updates #59616
[SIEM] [Cases] Delete, comment, and reducer updates #59616
Conversation
Pinging @elastic/siem (Team:SIEM) |
@@ -7,11 +7,3 @@ | |||
export const CASES_URL = `/api/cases`; | |||
export const DEFAULT_TABLE_ACTIVE_PAGE = 1; | |||
export const DEFAULT_TABLE_LIMIT = 5; | |||
export const FETCH_FAILURE = 'FETCH_FAILURE'; |
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 switch from variables to inline strings?
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.
to make the Action
type in the hooks better
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.
cannot we use ActionCreator
from typescript-fsa
as in the rest of the app?
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.
x-pack/legacy/plugins/siem/public/containers/case/use_delete_cases.tsx
Outdated
Show resolved
Hide resolved
@@ -16,6 +16,7 @@ export interface Comment { | |||
export interface Case { | |||
id: string; | |||
comments: Comment[]; | |||
commentIds: string[]; |
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 we need the comment ids in a different array? Aren't included in comments array?
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.
@XavierM had reasons
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.
@cnasikas, you will only get the comments through the API if you set the query parameter includeComments
but we still need to know how many comments are attached to a case to show it in the table. So to avoid a payload of data to just know the number of comment we are using commentIds
.
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.
@XavierM Sorry to insist, but if this is the only use case why the API does not return the count of the comments? Do you think there will be another use case in the future where ids will be needed?
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 agree with you but since we do not have aggregation on the saved object I did that to avoid query every comment for every case. Might not be the most robust way of doing it. However, it will be faster. When we have aggregation in saved_object, we will be able to use that to just get the count like you said
@@ -130,3 +130,25 @@ export const patchComment = async ( | |||
await throwIfNotOk(response.response); | |||
return convertToCamelCase<CommentResponse, Comment>(decodeCommentResponse(response.body)); | |||
}; | |||
|
|||
export const deleteCases = async (caseIds: string[]): Promise<boolean> => { |
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.
What do you think about passing a signal (AbortController) so we can pass it to fetch
?
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.
export const deleteCases = async ({caseIds: string[], signal: AbortSignal}): Promise<boolean> => {
const response = await KibanaServices.get().http.fetch<string>(`${CASES_URL}`, {
method: 'DELETE',
asResponse: true,
signal,
query: { ids: JSON.stringify(caseIds) },
});
await throwIfNotOk(response.response);
return response.body === 'true' ? true : false;
};
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.
related to this comment #59616 (comment)
handleToggleModal: () => void; | ||
} | ||
|
||
export const useDeleteCases = (): UseDeleteCase => { |
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.
What do you think about creating an AbortController, pass it to the API calls and abort in the return 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.
show me?
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.
const dispatchDeleteCases = useCallback(async (caseIds: string[]) => {
let cancel = false;
**const abortCtrl = new AbortController();**
try {
dispatch({ type: 'FETCH_INIT' });
await deleteCases(**{ caseIds, signal: abortCtrl.signal }**);
if (!cancel) {
dispatch({ type: 'FETCH_SUCCESS', payload: true });
}
} catch (error) {
if (!cancel) {
errorToToaster({
title: i18n.ERROR_TITLE,
error: error.body && error.body.message ? new Error(error.body.message) : error,
dispatchToaster,
});
dispatch({ type: 'FETCH_FAILURE' });
}
}
return () => {
cancel = true;
**abortCtrl.abort();**
};
}, []);
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.
@XavierM thoughts?
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.
That's correct, I notice that too but I was thinking that we can change it to a specific PR later on and create an issue to track it. Therefore we can move forward to this PR and staying true to just do deletions and showing comments. I am saying that because that's not the only places we will have to change it and try to get better to avoid big PR. does that make sense?
@elasticmachine merge upstream |
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Test FailuresKibana Pipeline / kibana-xpack-agent / X-Pack Spaces API Integration Tests -- security_and_spaces.x-pack/test/spaces_api_integration/security_and_spaces/apis/copy_to_space·ts.spaces api with security copy to spaces rbac user with all at space from the space_1 space "before each" hook for "should return 200 when copying to space with conflicts without overwriting"Standard Out
Stack Trace
Kibana Pipeline / kibana-xpack-agent / X-Pack Spaces API Integration Tests -- security_and_spaces.x-pack/test/spaces_api_integration/security_and_spaces/apis/copy_to_space·ts.spaces api with security copy to spaces rbac user with all at space from the space_1 space "after each" hook for "should return 200 when copying to space with conflicts without overwriting"Standard Out
Stack Trace
Kibana Pipeline / kibana-xpack-agent / X-Pack Spaces API Integration Tests -- security_and_spaces.x-pack/test/spaces_api_integration/security_and_spaces/apis/copy_to_space·ts.spaces api with security copy to spaces rbac user with all at space from the space_1 space "before each" hook for "should return 200 when copying to space with conflicts without overwriting"Standard Out
Stack Trace
History
To update your PR or re-run it, just comment with: |
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.
LGTM! Great job!
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.
LGTM! Great job!
Summary
Disclaimer: new icons are not yet in Kibana.
magnet
is used as a placeholderThis PR resolves the following All Cases issues from #59041:
commentCount
columnIt also resolves the following Case View issues from #58526:
UI for delete commentnot in scopeAnd miscellaneously because I like to keep you on your toes...