PageNav.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2019 Red Hat, Inc. and/or its affiliates.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import * as React from "../../common/keycloak/web_modules/react.js";
  17. import { withRouter } from "../../common/keycloak/web_modules/react-router-dom.js";
  18. import { Nav, NavList } from "../../common/keycloak/web_modules/@patternfly/react-core.js";
  19. import { makeNavItems, flattenContent } from "./ContentPages.js";
  20. class PageNavigation extends React.Component {
  21. constructor(props) {
  22. super(props);
  23. }
  24. findActiveItem() {
  25. const currentPath = this.props.location.pathname;
  26. const items = flattenContent(content);
  27. const firstItem = items[0];
  28. for (let item of items) {
  29. const itemPath = '/' + item.path;
  30. if (itemPath === currentPath) {
  31. return item;
  32. }
  33. }
  34. ;
  35. return firstItem;
  36. }
  37. render() {
  38. const activeItem = this.findActiveItem();
  39. return React.createElement(Nav, null, React.createElement(NavList, null, makeNavItems(activeItem)));
  40. }
  41. }
  42. export const PageNav = withRouter(PageNavigation);
  43. //# sourceMappingURL=PageNav.js.map