-
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
[Security solution][Endpoint] Users can filter trusted apps by policy name #106710
[Security solution][Endpoint] Users can filter trusted apps by policy name #106710
Conversation
…w filtered by policy
…nly when refresh button is clicked
…cause now policies are loaded at the trusted apps list
Pinging @elastic/security-onboarding-and-lifecycle-mgt (Team:Onboarding and Lifecycle Mgt) |
x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/middleware.test.ts
Outdated
Show resolved
Hide resolved
...ck/plugins/security_solution/public/management/pages/trusted_apps/view/trusted_apps_page.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.
just some nits but otherwise looks good.
}; | ||
|
||
expect(getTrustedAppsListPath(location)).toEqual( | ||
'/administration/trusted_apps?page_index=2&page_size=20&view_type=list&show=create' | ||
'/administration/trusted_apps?page_index=2&page_size=20&view_type=list&show=create&filter=test&included_policies=globally&excluded_policies=unassigned' |
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.
non-blocking nit: could use string templating here for location.filter and the location included/excluded policies.
const doEntriesExist = useTrustedAppsSelector(entriesExist) === true; | ||
const navigationCallback = useTrustedAppsNavigateCallback((query: string) => ({ filter: query })); | ||
const didEntriesExist = useTrustedAppsSelector(prevEntriesExist) === true; |
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.
can we just do useTrustedAppsSelector(prevEntriesExist)
without the === true
?
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.
OMG, totally right! Don't know why I write this, I think it came from a copy paste of line 58
@elasticmachine merge upstream |
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.
Left a few comments and suggestion. let me know if you have any questions. This (feature) is looking awesome
@@ -19,3 +21,31 @@ export const parseQueryFilterToKQL = (filter: string, fields: Readonly<string[]> | |||
|
|||
return `(${kuery})`; | |||
}; | |||
|
|||
const getPolicyQuery = (policy: string): 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.
policy
(to me) makes it sound like its the actual endpoint policy. maybe rename it to policyId
instead?
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [policies]); | ||
|
||
const onButtonClick = () => { |
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.
can you wrap this in useCallback()
? Same for the closePopover
below as well.
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.
Yeah, I thought that but following react docs: https://reactjs.org/docs/hooks-reference.html#usestate
It says:
React guarantees that setState function identity is stable and won’t change on re-renders. This is why it’s safe to omit from the useEffect or useCallback dependency list.
As this functions only has setState actions I think is one of those cases you don't need to wrap it in a useCallback as it wouldn't be better in terms on performance.
Note: I'm using the setState param function to avoid memoize the current value.
setIsPopoverOpen((prevIsPopoverOpen) => !prevIsPopoverOpen);
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.
🤔 - true. the setter function provided back by useState()
is guaranteed to now change and thus you can omit that setter function from the dependencies of useCallback.
One of the benefits of using useCallback()
is that the returned function is always the same until the dependencies change. Because onButtonClick
is given as a prop to another component, and because its value (the function) is a new function instance (because its not wrapped in useCallback()
), that will trigger a re-render of the downstream component (prop changed).
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.
☝️ ( 😁 ) - still optional
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.
Oh right, I'm still wondering if it will improve something as there is no changing state/prop related? So the returned function still being the same right?
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, every time this component is rendered, the onButtonClick
will be a new instance (function) because it's not cached. So when that is used below as a prop value, it will cause that comment below to also re-render (because the prop value is new (oldOnButtonClick !== onButtonClick
)
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.
Argh! I see, got it. Thanks!!
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 in: 6e92a6b
onChangeSelection: (items: Item[]) => void; | ||
} | ||
|
||
export interface Item { |
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.
Naming suggestion: PolicySelectionItem
(just because Item
is so generic)
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.
Totally agree, this was cp from eui docs
const policy = generator.generatePolicyPackagePolicy(); | ||
policy.name = 'test policy A'; | ||
policy.id = 'abc123'; | ||
const getElement = (params: Partial<PoliciesSelectorProps>) => { |
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.
Could you set these on every test run so that we avoid mutable state being used between tests?
|
||
export const getPolicyResponse = (): GetPolicyListResponse => ({ | ||
items: [ | ||
{ |
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.
Do we have a generator for policy response? if so, I would suggest inializing a generator here with a seed and then getting the mocked policy response with it, rather than to define the entire response here.
x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/selectors.ts
Show resolved
Hide resolved
x-pack/plugins/security_solution/public/management/pages/trusted_apps/store/selectors.ts
Show resolved
Hide resolved
@@ -922,6 +936,27 @@ describe('When on the Trusted Apps Page', () => { | |||
backButtonUrl: '/fleet', | |||
}); | |||
}); | |||
|
|||
const priorMockImplementation = coreStart.http.get.getMockImplementation(); | |||
// @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.
why the ts-ignore? is it due to the callback overload signatures? If so, I have gotten around this by just accepting options
as the argument and doing a type assertion in the body of the function. see x-pack/plugins/security_solution/public/common/mock/endpoint/http_handler_mock_factory.ts:199
for reference
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.
Changing this by using the getLastLoadedResourceState solves that
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.
Sorry I don't remember why I said that. This was copy&pasted from line 766.
...ck/plugins/security_solution/public/management/pages/trusted_apps/view/trusted_apps_page.tsx
Show resolved
Hide resolved
…ourceState helper function to get the prev state. Use generated data for policies in tests
…47' of github.com:dasansol92/kibana into feat/olm-users_can_filter_Trusted_Apps_by_policy_name-747
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.
Approving 🔥 🔥 🔥
I did leave a few comments that might need follow up, but nothing that should hold this up for now.
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
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.
🔥 🔥 🔥
🚢
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [policies]); | ||
|
||
const onButtonClick = () => { |
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.
☝️ ( 😁 ) - still optional
@@ -922,6 +936,27 @@ describe('When on the Trusted Apps Page', () => { | |||
backButtonUrl: '/fleet', | |||
}); | |||
}); | |||
|
|||
const priorMockImplementation = coreStart.http.get.getMockImplementation(); | |||
// @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.
☝️
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
… name (elastic#106710) * Allow users select policies from a dropdown * Policy filters are passed throguh the API call and the results are now filtered by policy * Moved policies selector inside search component and triggers search only when refresh button is clicked * Fixes tests * Triggers policy filter when policy is selected. Also fix unit test because now policies are loaded at the trusted apps list * Renamed components and added an index.ts for the exports * Adds unit tests for policies selector component * Fix unit tests and changed camelcase by snack case for url params * adds multilang * Fixes i18n keys * Move mock resonse to the mocks file * Use string templating in test * remove === true from boolean comparison * Set function in useCallback. Renames some variables and types. Use reourceState helper function to get the prev state. Use generated data for policies in tests * Fix ts errors * Removes unused type and fix type name for Item * Puts exclude clause on policy dropdown behind a feature flag * Adds missing feature flags in some tests and in global reducer * Fix test adding useExperimentalValua mock for FF * Wrapp handlers in a useCallback in order to prevent useless rerenders Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
… name (#106710) (#107750) * Allow users select policies from a dropdown * Policy filters are passed throguh the API call and the results are now filtered by policy * Moved policies selector inside search component and triggers search only when refresh button is clicked * Fixes tests * Triggers policy filter when policy is selected. Also fix unit test because now policies are loaded at the trusted apps list * Renamed components and added an index.ts for the exports * Adds unit tests for policies selector component * Fix unit tests and changed camelcase by snack case for url params * adds multilang * Fixes i18n keys * Move mock resonse to the mocks file * Use string templating in test * remove === true from boolean comparison * Set function in useCallback. Renames some variables and types. Use reourceState helper function to get the prev state. Use generated data for policies in tests * Fix ts errors * Removes unused type and fix type name for Item * Puts exclude clause on policy dropdown behind a feature flag * Adds missing feature flags in some tests and in global reducer * Fix test adding useExperimentalValua mock for FF * Wrapp handlers in a useCallback in order to prevent useless rerenders Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: David Sánchez <davidsansol92@gmail.com>
… name (elastic#106710) * Allow users select policies from a dropdown * Policy filters are passed throguh the API call and the results are now filtered by policy * Moved policies selector inside search component and triggers search only when refresh button is clicked * Fixes tests * Triggers policy filter when policy is selected. Also fix unit test because now policies are loaded at the trusted apps list * Renamed components and added an index.ts for the exports * Adds unit tests for policies selector component * Fix unit tests and changed camelcase by snack case for url params * adds multilang * Fixes i18n keys * Move mock resonse to the mocks file * Use string templating in test * remove === true from boolean comparison * Set function in useCallback. Renames some variables and types. Use reourceState helper function to get the prev state. Use generated data for policies in tests * Fix ts errors * Removes unused type and fix type name for Item * Puts exclude clause on policy dropdown behind a feature flag * Adds missing feature flags in some tests and in global reducer * Fix test adding useExperimentalValua mock for FF * Wrapp handlers in a useCallback in order to prevent useless rerenders Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Summary
trustedAppsByPolicyEnabled
FF is enabled.Checklist
For maintainers