Skip to content
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

[Security Solution] [Endpoint] Ability to assign existing event filter to the policy flyout #121964

Conversation

dasansol92
Copy link
Contributor

Summary

policy event filters list flyout

For maintainers

@dasansol92 dasansol92 added release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.1.0 labels Dec 23, 2021
'updated_at',
'updated_by',
].forEach((field) => {
delete updatedCommentsEntry[field as keyof UpdateExceptionListItemSchema];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from the middleware to the service as the service is used in other places (with react-query)

return (
<>
{isListLoading && (
<EuiProgress size="xs" color="primary" data-test-subj="artifactsAssignableListLoader" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a progress bar like we have in the other search list areas

);
}

export function useBulkUpdateEventFilters(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generic bulk update action. Using this, we will be able to use the bulk API once is done without changing the components logic, only this hook

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@dasansol92 dasansol92 marked this pull request as ready for review December 23, 2021 15:11
@dasansol92 dasansol92 requested a review from a team as a code owner December 23, 2021 15:11
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-onboarding-and-lifecycle-mgt (Team:Onboarding and Lifecycle Mgt)

@academo
Copy link
Contributor

academo commented Dec 27, 2021

@elasticmachine merge upstream

'updated_at',
'updated_by',
].forEach((field) => {
delete exception[field as keyof UpdateExceptionListItemSchema];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the implementation so that we don't mutate the object that was passed on input to this method. I think that maybe this might work:

async updateOne(
   {
      created_at,
      created_by,
      created_at,
      creatd_by,
      list_id,
      tie_breaker_id,
      updated_at,
      updated_by,
      ...exception
    }: Immutable<UpdateExceptionListItemSchema>
  ): Promise<ExceptionListItemSchema> {

const [currentFilter, setCurrentFilter] = useState<string>('');

const bulkUpdateMutation = useBulkUpdateEventFilters({
onUpdateSuccess: (updatedExceptions: ExceptionListItemSchema[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not worked with react query, so I'm not sure about this - but should these all be memoized? are they triggering unnecessary react render cycles by having new instances created everytime?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, internally react-query is already taking care of this.

…_policy_flyout-2029' of github.com:dasansol92/kibana into feat/olm-ability_to_assign_existing_event_filter_to_the_policy_flyout-2029
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2834 2836 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 4.6MB 4.6MB +6.2KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments and am good if you need to merge this in order to make progress and address them in a subsequent PR.

...exception,
tags: [...testTags, `policy:${policy.id}`],
};
// Clean unnecessary fields for update action
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the same code as the service file? if so, maybe create a utility that does this (TA has a similar one I think) and reuse it.

UpdateExceptionListItemSchema,
} from '@kbn/securitysolution-io-ts-list-types';

const endpointGenerator = new EndpointDocGenerator('seed');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI: This is fine being defined as a singleton, but note that if a new test case is inserted between others, you could get test failures because the data generated will then differ for the tests cases that are present after the one inserted.

My suggestion would be to initialize it for every test via beforeEach()

sort_order: undefined,
},
});
const emptyList = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid using mutable constants in the tests - can you convert this to a function that returns the object?

renderResult = mockedContext.render(
<PolicyEventFiltersFlyout policyItem={policy} onClose={onCloseMock} />
);
await waitFor(mockedApi.responseProvider.eventFiltersList);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is doing what you expect it to be done. What is the intent - to wait for the data to be returned? If so, then you need to check for when it is actually called. maybe something like this:

await waitFor(
  () => expect(mockedApi.responseProvider.eventFiltersList).toHaveBeenCalled()
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. exactly. It was what I was looking for, thanks!

@dasansol92
Copy link
Contributor Author

@paul-tavares Thanks for the suggestions, I will address it in a subsequent PR since I need some of the code here to move on with other issues

@dasansol92 dasansol92 merged commit 14b8e12 into elastic:main Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants