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

Implement new security solution wrapper #100405

Merged
merged 48 commits into from
Jun 23, 2021

Conversation

michaelolo24
Copy link
Contributor

@michaelolo24 michaelolo24 commented May 20, 2021

Summary

This PR introduces the new KibanaPageTemplate nav wrapper to the security solution as detailed here #98359. Of note:

(sample image below)

  1. The template_wrapper folder was added in the public/app/home folder. It contains the new KibanaPageTemplate as well as the code for the global kql header and bottom bar (containing the timeline)
  2. Added a navigation hook within the components/navigation folder for the side nav to meet the the reqs for the solutionNav prop. Pulled in functionality from the TabNavigation component to keep state in sync as well as telemetry. Also, updated the urlState makeMapStateToProps a hook and updated the name for the primary navigation.
  3. The Add Data and Ml Job Settings were moved to the Kibana fixed header to get some more vertical space back. The code for this can be found in public/app/global_header
  4. WrapperPage was renamed to SecuritySolutionPageWrapper. Initially made this change as the pageTemplate code lived in this file, but decided to keep it when I migrated it out into the home folder. Can change it back if people don't prefer this naming scheme, but it seemed in line with other solutions. Note: We have a few wrappers that may eventually be able to be consolidated once all the nav changes are completed.
  5. Moved drag related classnames into their own file as they were causing a circular dependency in drag helpers
  6. Updated the EuiPanel page level components within Security Solution to use the hasBorder prop so they no longer have a shadow border.

Still To Be Done

  1. Empty pages need to be updated to match the new design. That will be done when we have new mocks
  2. We do not yet have the ability to collapse the side nav. This has been discussed internally and the decision as of now is to move forward without that functionality with the hope that it comes in before 7.14.
  3. Another kbnAppWrapper as of now, will need to be added at the kibana app level to force full height for all of the pages
  4. Pages will be broken into new sections once [Security Solution] Application register deepLinks instead of meta.searchDeepLinks #100129 is merged

New Solution Nav

Screen Shot 2021-06-09 at 4 20 22 PM

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@michaelolo24 michaelolo24 force-pushed the security-solution-nav-update branch 4 times, most recently from 0651ca2 to 71a6366 Compare May 28, 2021 19:59
@michaelolo24 michaelolo24 force-pushed the security-solution-nav-update branch 3 times, most recently from 29e464e to 360e8aa Compare June 4, 2021 13:26
@michaelolo24 michaelolo24 force-pushed the security-solution-nav-update branch 3 times, most recently from 97ab77a to 871d95f Compare June 9, 2021 18:51
@michaelolo24 michaelolo24 added Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Threat Hunting Security Solution Threat Hunting Team release_note:skip Skip the PR/issue when compiling release notes labels Jun 9, 2021
@@ -247,12 +247,6 @@ export const addFieldToTimelineColumns = ({
*/
export const DRAG_TYPE_FIELD = 'drag-type-field';

/** This class is added to the document body while dragging */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were causing a cyclic dependency so moved them into their own classname constants file


useEffect(() => {
if (pathName || pageName) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

primary changes in this file were renaming the component and updating it to purely use hooks. See useUrlState. Also the primary nav no longer uses this but uses the hook in this file use_security_solution_navigation

@@ -27,25 +27,6 @@ SecuritySolutionAppWrapper.displayName = 'SecuritySolutionAppWrapper';
and `EuiPopover`, `EuiToolTip` global styles
*/
export const AppGlobalStyle = createGlobalStyle<{ theme: { eui: { euiColorPrimary: string } } }>`
// fixes double scrollbar on views with EventsTable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These overrides were causing visual issues with the new template.

const SHOW_HIDE_GLOBAL_TRANSLATE_Y = 50; // px
const SHOW_HIDE_TIMELINE_TRANSLATE_Y = 0; // px

const Container = styled.div.attrs<{ $isGlobal: boolean }>(({ $isGlobal = true }) => ({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The template bottomBar handles a lot of this logic already, but any additional timeline specific logic was added to the styles seen in template_wrapper/index

@michaelolo24 michaelolo24 marked this pull request as ready for review June 9, 2021 20:39
@michaelolo24 michaelolo24 requested review from a team as code owners June 9, 2021 20:39
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting (Team:Threat Hunting)

@michaelolo24 michaelolo24 requested a review from cchaos June 9, 2021 22:33
* 2.0.
*/

/** This class is added to the document body while dragging */
Copy link
Contributor

Choose a reason for hiding this comment

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

oh this is going to be fun!!! I moved them in packages to be shared between security solution and timelines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea... 😅

timeline,
timerange,
}: PrimaryNavigationProps): KibanaPageTemplateProps['solutionNav'] => {
const mapLocationToTab = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

you do not need to use useCallback here, it does not matter if the mapLocationToTab reference change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of this is taken from the tab navigation file to keep in sync with the logic there, but it actually makes sense to have it based on the function being called in the useEffect

Copy link
Contributor

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

Thanks for all the comments Mike! 💪

<EuiHeaderLink
color="primary"
data-test-subj="add-data"
href={`${basePath}${ADD_DATA_PATH}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think we could do href={http.basePath.prepend(ADD_DATA_PATH)} that'll prepend base path to the passed in URL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, that worked. Updated it thanks!

// should be consistent across every render. The primary nav tabs here are from a constants file
// not dynamically generated, so their order will remain consistent across renders.
// eslint-disable-next-line react-hooks/rules-of-hooks
const { formatUrl } = useFormatUrl(((pageId ?? id) as unknown) as SecurityPageName);
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 super familiar with this code but could we set pageId on all the tabs here: https://github.com/elastic/kibana/blob/master/x-pack/plugins/security_solution/public/app/home/home_navigations.tsx#L21 ? Then we could avoid the casting right?

It might also help clean up a few places where we need to check whether id or pageId is set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was actually able to remove this entirely. Kept a lot of logic from the tab navigation that wasn't necessary

const handleClick = (ev: React.MouseEvent) => {
ev.preventDefault();
if (id in SecurityPageName && pageId == null) {
navigateToApp(`${APP_ID}:${id}`, { path: urlSearch });
Copy link
Contributor

Choose a reason for hiding this comment

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

I think navigateToApp does a history.push or history.replace under the scenes so just curious why we couldn't use navigateToApp for both situations here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was just maintaining the logic that was used in the tabNavigation, but this isn't necessary for the primary navigation so I've removed it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the reason was to avoid a mount of the app

Copy link
Contributor

Choose a reason for hiding this comment

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

but all this stuff will be changed in follow up PR with @semd

// Rules of hooks prevents hooks from being called in callbacks as the order of the hooks
// should be consistent across every render. The primary nav tabs here are from a constants file
// not dynamically generated, so their order will remain consistent across renders.
// eslint-disable-next-line react-hooks/rules-of-hooks
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably not worth the effort but would the alternative be to return a callback instead of navItems that could be called while iterating over navTabs? So the caller of usePrimaryNavigationItems would have to do the looping and call the callback returned by usePrimaryNavigationItems. Or would that not work?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the great comment by the way though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, that would work. Actually probably a better route to go to not have to disable any rules of hooks that could cause bugginess in the future if anything changed. Turns out though that I didn't need this code at all as the primary nav doesn't have sub-tabs. Once @semd's changes are in we should be able to get rid of all pageId references and do a final nav cleanup

return shouldShowCallout ? (
<>
<CallOutPersistentSwitcher
condition={shouldShowCallout}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this ever receive false? Also I think the only place CallOutPersistentSwitcher is used is here. I think we could remove the condition prop right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, fixed it. Thanks!

Copy link
Contributor

@XavierM XavierM left a comment

Choose a reason for hiding this comment

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

let me know if you need help to merge with master and then I will approve it

@michaelolo24
Copy link
Contributor Author

let me know if you need help to merge with master and then I will approve it

@XavierM No worries, I merged master earlier this morning, updated the references, and everything looks good. 🤞🏾

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2189 2194 +5

Async chunks

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

id before after diff
cases 507.5KB 507.8KB +292.0B
securitySolution 6.5MB 6.5MB -365.0B
total -73.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
core 411.5KB 412.4KB +952.0B
securitySolution 197.8KB 197.7KB -114.0B
total +838.0B
Unknown metric groups

References to deprecated APIs

id before after diff
securitySolution 390 394 +4

History

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


// build a list of tabs to exclude
const tabsToExclude = new Set<string>([
...(hideDetectionEngine ? [SecurityPageName.detections] : []),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@XavierM did not see this used or called anywhere?

Copy link
Contributor

Choose a reason for hiding this comment

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

good, it was an old Feature flag fro 7.5

Copy link
Contributor

@XavierM XavierM left a comment

Choose a reason for hiding this comment

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

LGTM, I reviewed code and tested locally.

@michaelolo24 michaelolo24 merged commit 702661d into elastic:master Jun 23, 2021
@michaelolo24 michaelolo24 deleted the security-solution-nav-update branch June 23, 2021 15:00
@michaelolo24 michaelolo24 restored the security-solution-nav-update branch June 23, 2021 17:50
michaelolo24 added a commit to michaelolo24/kibana that referenced this pull request Jun 24, 2021
Co-authored-by: cchaos <caroline.horn@elastic.co>
# Conflicts:
#	x-pack/plugins/security_solution/cypress/integration/timelines/data_providers.spec.ts
#	x-pack/plugins/security_solution/cypress/integration/timelines/pagination.spec.ts
michaelolo24 added a commit to michaelolo24/kibana that referenced this pull request Jun 24, 2021
Co-authored-by: cchaos <caroline.horn@elastic.co>
# Conflicts:
#	x-pack/plugins/security_solution/cypress/integration/timelines/data_providers.spec.ts
#	x-pack/plugins/security_solution/cypress/integration/timelines/pagination.spec.ts
michaelolo24 added a commit that referenced this pull request Jun 24, 2021
* Implement new security solution wrapper (#100405)

Co-authored-by: cchaos <caroline.horn@elastic.co>
# Conflicts:
#	x-pack/plugins/security_solution/cypress/integration/timelines/data_providers.spec.ts
#	x-pack/plugins/security_solution/cypress/integration/timelines/pagination.spec.ts

* test fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Threat Hunting Security Solution Threat Hunting Team v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants