Skip to content

Commit

Permalink
feat: add breadcrumbs to details pages
Browse files Browse the repository at this point in the history
  • Loading branch information
roadlittledawn committed Aug 31, 2021
1 parent e3bffe4 commit 2ec9930
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/components/Breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import PropTypes from 'prop-types';
import React from 'react';
import { css } from '@emotion/react';
import { Link } from '@newrelic/gatsby-theme-newrelic';

const Breadcrumbs = ({ segments, separator }) => {
return (
<div
css={css`
margin: 2em 0;
> :first-child {
margin-left: 0;
}
> * {
margin-left: 0.5em;
}
`}
aria-label="breadcrumb"
>
{segments
.map((segment) => {
const elem = segment.url ? (
<Link to={segment.url}>{segment.name}</Link>
) : (
segment.name
);
return <span key={`breadcrumb-${segment.name}`}>{elem}</span>;
})
.reduce((prev, curr) => [
prev,
React.createElement('span', {}, separator),
curr,
])}
</div>
);
};

Breadcrumbs.defaultProps = {
separator: '/',
};

Breadcrumbs.propTypes = {
segments: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string.isRequired,
url: PropTypes.string,
})
),
separator: PropTypes.string,
};

export default Breadcrumbs;
12 changes: 12 additions & 0 deletions src/templates/QuickstartDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ImageGallery from '../components/ImageGallery';
import InstallButton from '../components/InstallButton';
import Markdown from '../components/Markdown';
import QuickstartDataSources from '../components/quickstarts/QuickstartDataSources';
import Breadcrumbs from '../components/Breadcrumbs';
import { quickstart } from '../types';
import {
QUICKSTARTS_REPO,
Expand Down Expand Up @@ -49,6 +50,16 @@ const QuickstartDetails = ({ data, location }) => {
const pack = data.quickstarts;
const packUrl = pack.packUrl || QUICKSTARTS_REPO;
const tessen = useTessen();
const breadcrumbSegments = [
{
name: 'Instant Observability (I/O)',
url: '/instant-observability/',
},
{
name: pack.name,
url: null,
},
];
const handleInstallClick = useInstrumentedHandler(
() => {
tessen.track('observabilityPack', 'packInstall', {
Expand All @@ -66,6 +77,7 @@ const QuickstartDetails = ({ data, location }) => {
return (
<>
<DevSiteSeo title={pack.name} location={location} />
<Breadcrumbs segments={breadcrumbSegments} />
<Tabs>
<PageLayout type={PageLayout.TYPE.RELATED_CONTENT_TABS}>
<PageLayout.Header
Expand Down

0 comments on commit 2ec9930

Please sign in to comment.