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

[Endpoint] Task/add nav bar #58604

Merged
merged 14 commits into from
Feb 28, 2020
Merged

[Endpoint] Task/add nav bar #58604

merged 14 commits into from
Feb 28, 2020

Conversation

kevinlog
Copy link
Contributor

@kevinlog kevinlog commented Feb 26, 2020

Summary

A PR to add a header nav to the endpoint app. Uses EuiTabs with useHistory to add the urls to our router history. Thanks to RouteCapture, will properly update the URL in the redux store.

Now contains tests.

Implements https://github.com/elastic/endpoint-app-team/issues/174

image

image

Redux:
image

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@oatkiller oatkiller added the Feature:Endpoint Elastic Endpoint feature label Feb 26, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-app-team (Feature:Endpoint)

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.

@kevinlog should the header navigation component be split off into its own separate component instead of placing it into the index.tsx?
Also, the array of Nav tabs might become useful as well in other places (later) if we want to reference a centralized place that holds the to path to the different application pages (in order to build links, or redirect users).

function renderNavTabs(tabs: NavTabs[]) {
return tabs.map((tab, index) => {
return (
<NavLink
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably use theEuiTabs component for this and not the NavLink from react-router. EuiTab allows for href to be set as well as a onClick callback - the callback would be where you can handle calling react-router's history.push. We might need to styled the EuiTabs a little (see example in Ingest just committed recently)

Also - one of the thing the EUI team discourages is to use the internal class names on components directly like this :(

const navTabs: NavTabs[] = [
{
name: 'home',
display: 'Home',
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to i18n all display values

@paul-tavares
Copy link
Contributor

@kevinlog just read your question in the PR description re: redux ++ middleware.
You might not even need it. The determination on whether a Tab is selected or not can be done using useLocation().pathname and comparing that to the value of each Nav's .to value.

@kevinlog
Copy link
Contributor Author

@paul-tavares thanks for the detailed comments. I adjusted the PR to use EuiTabs directly, let me know what you think

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.

LGTM

Only minor change. Thanks

<EuiTab
data-testid={`${tab.id}Link`}
key={index}
onClick={() => {
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 ok this now having an href at this time, but we should decide if we should include one in the tab in order to enable the user to open in separate window/tab.

@paul-tavares
Copy link
Contributor

Actually: question - do you need test cases for this? Probably a few, at least to validate that we're correctly setting the selected tab. Also, what happens when we get routed to an invalid URI (I assume no tab is selected, but nav is still visible).

kevinlog and others added 3 commits February 28, 2020 09:57
…s/header_nav.tsx

Co-Authored-By: Paul Tavares <56442535+paul-tavares@users.noreply.github.com>
@kevinlog kevinlog marked this pull request as ready for review February 28, 2020 15:16
@kevinlog
Copy link
Contributor Author

@elasticmachine merge upstream

@kevinlog kevinlog added release_note:skip Skip the PR/issue when compiling release notes v7.7.0 Team:Endpoint Data Visibility Team managing the endpoint resolver Team:Endpoint Management Team:Endpoint Response Endpoint Response Team labels Feb 28, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-response (Team:Endpoint Response)

@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-management (Team:Endpoint Management)

@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-data-visibility-team (Team:Endpoint Data Visibility)

@kevinlog kevinlog changed the title Task/add nav bar [Endpoint] Task/add nav bar Feb 28, 2020
data-testid={`${tab.id}EndpointTab`}
data-test-subj={`${tab.id}EndpointTab`}
key={index}
href={`/app/endpoint${tab.href}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

🔴 You can't hardcode the /app/endpoint or else you break when kibana is running with base-path. I think @kqualters-elastic has added the use of kibana-react to our application, wich means we can use their hook to retrieve coreStart and then get the base path from the http service (see this: #58288 (comment)).

An alternative for now is to add a basePath prop to this component and then send it in from index.tsx since you should have that info. available there.

@@ -41,6 +42,7 @@ const AppRoot: React.FunctionComponent<RouterProps> = React.memo(({ basename, st
<I18nProvider>
<BrowserRouter basename={basename}>
<RouteCapture>
<HeaderNavigation />
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, you can pass in basename to HeaderNavigation

data-test-subj={`${tab.id}EndpointTab`}
key={index}
href={`/app/endpoint${tab.href}`}
onClick={(event: MouseEvent) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

An idea for how we could emulate react-router when using Eui components.
oatkiller@d6861d8

Things this handles:

  1. useCallback for the callback
  2. doesn't navigate when modifier keys are pressed
  3. can call an additional onClick handler if needed (navigate via a link AND have a callback)
  4. doesn't navigate if event is 'defaultPrevented'
  5. logic copied from react-router's link, so behavior is consistent
  6. should work in EuiLink as well

see react router's implementation for ideas
https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/modules/Link.js

Copy link
Contributor

Choose a reason for hiding this comment

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

Great approach that prevents us having to wrap Eui components 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oatkiller @paul-tavares this doesn't quite work yet, I broke this out to another ticket: https://github.com/elastic/endpoint-app-team/issues/230

Are you OK to merge this as is and I'll investigate the next step for this?

name: i18n.translate('xpack.endpoint.headerNav.management', {
defaultMessage: 'Management',
}),
href: '/management',
Copy link
Contributor

Choose a reason for hiding this comment

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

@paul-tavares does the basePath concern apply here as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

@bkimmel no - here its ok because we're using this value against react-router which we initialize with a basePath (the one provided during plugin initialization). So these should be (absolute) relative to basePath

},
];

const Tabs = styled(EuiTabs)`
Copy link
Contributor

Choose a reason for hiding this comment

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

❔ There is also EuiTabbedContent which seems like it would capture some more of what you're trying to accomplish here. Can you elaborate on why you didn't use the EuiTabbedContent approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bkimmel that styled doesn't make a difference that I can see, so I removed it. m See this for the original context #58604 (comment)

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.

LGTM 👍

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@kevinlog kevinlog merged commit b46a335 into elastic:master Feb 28, 2020
@kevinlog kevinlog deleted the task/add-nav-bar branch February 28, 2020 19:25
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Feb 29, 2020
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 2, 2020
…dex-server-side

* 'master' of github.com:elastic/kibana: (34 commits)
  [Upgrade Assistant] Remove "boom" from reindex service (elastic#58715)
  [data] Clean up QueryStringInput unit tests (elastic#58704)
  [SIEM] Detection Fix typo in Adobe Hijack Persistence rule (elastic#58804)
  Restores [SIEM][CASE] Init Configure Case Page (elastic#58121) (elastic#58924)
  Skips additional failing Ingest Manager integration tests
  Skips failing Ingest Manager integration tests
  Move dev tools styles to NP (elastic#58855)
  change to have kibana --ssl cli option use more recent certs (elastic#57933)
  disable failing suite (elastic#58942)
  Don't start pollEsNodesVersion unless someone subscribes (elastic#56923)
  Do not write UUID file during optimize process (elastic#58899)
  [Endpoint] Task/add nav bar (elastic#58604)
  [Metric Alerts] Add backend support for multiple expressions per alert  (elastic#58672)
  [Metrics Alerts] Fix alerting on a rate aggregation (elastic#58789)
  disable flaky suite (elastic#55953)
  Revert "[SIEM] apollo@3 (elastic#51926)" and "[SIEM][CASE] Init Confi… (elastic#58806)
  [resubmit] Prep agg types for new platform (elastic#58893)
  [Lens] Allow number formatting within Lens (elastic#56253)
  [Autocomplete] Use settings from config rather than UI settings (elastic#58784)
  Improve action and trigger types (elastic#58657)
  ...

# Conflicts:
#	x-pack/plugins/upgrade_assistant/server/routes/reindex_indices/reindex_indices.ts
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

kevinlog added a commit that referenced this pull request Mar 2, 2020
* Add tabs to the Endpoint app.  Uses EuiTabs and browser history for integration with react-router

Co-authored-by: Paul Tavares <56442535+paul-tavares@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Paul Tavares <56442535+paul-tavares@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Endpoint Elastic Endpoint feature release_note:skip Skip the PR/issue when compiling release notes Team:Endpoint Data Visibility Team managing the endpoint resolver Team:Endpoint Response Endpoint Response Team v7.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants