From 9a6c1120f1794ec17a1411d2035a8110954a0b7c Mon Sep 17 00:00:00 2001 From: MariaAga Date: Thu, 27 Apr 2023 14:47:27 +0200 Subject: [PATCH] tmp search --- .../components/Layout/Layout.fixtures.js | 50 +---- .../components/Layout/LayoutSelectors.js | 6 +- .../react_app/components/Layout/Navigation.js | 7 +- .../components/Layout/NavigationSearch.js | 211 ++++++++++++++++++ .../Layout/__tests__/NavigationSearch.test.js | 28 +++ .../LayoutSelectors.test.js.snap | 40 ++-- .../__snapshots__/HeaderToolbar.test.js.snap | 7 + .../react_app/components/Layout/layout.scss | 30 ++- 8 files changed, 305 insertions(+), 74 deletions(-) create mode 100644 webpack/assets/javascripts/react_app/components/Layout/NavigationSearch.js create mode 100644 webpack/assets/javascripts/react_app/components/Layout/__tests__/NavigationSearch.test.js diff --git a/webpack/assets/javascripts/react_app/components/Layout/Layout.fixtures.js b/webpack/assets/javascripts/react_app/components/Layout/Layout.fixtures.js index 8c0a00c57378..43d51d910850 100644 --- a/webpack/assets/javascripts/react_app/components/Layout/Layout.fixtures.js +++ b/webpack/assets/javascripts/react_app/components/Layout/Layout.fixtures.js @@ -15,6 +15,14 @@ const subItemsA = [ href: '/c', id: 'menu_item_cc', }, + + { + title: 'Ac', + isDivider: false, + onClick: mockOnClick, + href: '/ac', + id: 'menu_item_ac', + }, ]; const subItemsB = [ { @@ -26,7 +34,7 @@ const subItemsB = [ }, ]; -const PFitems = [ +export const PFitems = [ { title: 'Monitor', initialActive: true, @@ -40,31 +48,6 @@ const PFitems = [ subItems: subItemsB, }, ]; -// Server Hash Data -const monitorChildren = [ - { - type: 'item', - name: 'Dashboard', - title: 'Dashboard', - exact: true, - url: '/', - }, - { - type: 'item', - name: 'Facts', - title: 'Facts', - url: '/fact_values', - }, -]; - -const hostsChildren = [ - { - type: 'item', - name: 'All Hosts', - title: 'All Hosts', - url: '/hosts/new', - }, -]; const namelessChildren = [ { @@ -76,21 +59,6 @@ const namelessChildren = [ }, ]; -const hashItemsA = [ - { - type: 'sub_menu', - name: 'Monitor', - icon: 'fa fa-tachometer', - children: monitorChildren, - }, - { - type: 'sub_menu', - name: 'Hosts', - icon: 'fa fa-server', - children: hostsChildren, - }, -]; - export const hashItemNameless = [ { type: 'sub_menu', diff --git a/webpack/assets/javascripts/react_app/components/Layout/LayoutSelectors.js b/webpack/assets/javascripts/react_app/components/Layout/LayoutSelectors.js index 5fd99f86544b..918163a0703f 100644 --- a/webpack/assets/javascripts/react_app/components/Layout/LayoutSelectors.js +++ b/webpack/assets/javascripts/react_app/components/Layout/LayoutSelectors.js @@ -1,5 +1,4 @@ import { snakeCase } from 'lodash'; -import { noop } from '../../common/helpers'; export const selectLayout = state => state.layout; @@ -37,7 +36,6 @@ const childToMenuItem = (child, currentLocation, currentOrganization) => ({ child.title === currentLocation || child.title === currentOrganization ? 'mobile-active' : '', - href: child.url || '#', - preventHref: true, - onClick: child.onClick || noop, + href: child.url, + onClick: child.onClick, }); diff --git a/webpack/assets/javascripts/react_app/components/Layout/Navigation.js b/webpack/assets/javascripts/react_app/components/Layout/Navigation.js index 776459189f5f..3490adccde2d 100644 --- a/webpack/assets/javascripts/react_app/components/Layout/Navigation.js +++ b/webpack/assets/javascripts/react_app/components/Layout/Navigation.js @@ -10,6 +10,7 @@ import { NavItemSeparator, } from '@patternfly/react-core'; import { getCurrentPath } from './LayoutHelper'; +import { NavigationSearch } from './NavigationSearch'; const titleWithIcon = (title, iconClass) => (
@@ -43,7 +44,7 @@ const Navigation = ({ items.forEach(item => { item.subItems.forEach(subItem => { - if (!subItem.isDivider) { + if (!subItem.isDivider && subItem.href) { // don't keep the query parameters for the key subItemToItemMap[pathFragment(subItem.href)] = item.title; } @@ -69,7 +70,7 @@ const Navigation = ({ } else { groups[currIndex].groupItems.push({ ...sub, - isActive: pathname === sub.href.split('?')[0], + isActive: pathname === sub.href?.split('?')[0], }); } }); @@ -80,10 +81,12 @@ const Navigation = ({ [items.length] ); + if (!items.length) return null; const groupedItems = getGroupedItems; return (