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

[Homepage] populate use case dropdown from use case pages #13325

Merged
merged 2 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions website/components/subnav/index.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Subnav from '@hashicorp/react-subnav'
import menuItems from 'data/subnav'
import { useRouter } from 'next/router'

export default function ProductSubnav() {
export default function ProductSubnav({ menuItems }) {
const router = useRouter()

return (
Expand All @@ -20,8 +19,7 @@ export default function ProductSubnav() {
},
{
text: 'Try Cloud',
url:
'https://portal.cloud.hashicorp.com/sign-up?utm_source=vault_io&utm_content=top_nav_vault',
url: 'https://portal.cloud.hashicorp.com/sign-up?utm_source=vault_io&utm_content=top_nav_vault',
},
{
text: 'Download',
Expand Down
23 changes: 0 additions & 23 deletions website/data/subnav.js

This file was deleted.

47 changes: 47 additions & 0 deletions website/layouts/standard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import query from './query.graphql'
import ProductSubnav from 'components/subnav'
import HashiStackMenu from '@hashicorp/react-hashi-stack-menu'
import Footer from 'components/footer'
import { open } from '@hashicorp/react-consent-manager'

export default function StandardLayout(props: Props): React.ReactElement {
const { useCaseNavItems } = props.data

return (
<>
<HashiStackMenu />
<ProductSubnav
menuItems={[
{ text: 'Overview', url: '/' },
{
text: 'Use Cases',
submenu: useCaseNavItems,
},
{
text: 'Enterprise',
url: 'https://www.hashicorp.com/products/vault/enterprise',
},
'divider',
{ text: 'Tutorials', url: 'https://learn.hashicorp.com/vault' },
{ text: 'Docs', url: '/docs' },
{ text: 'API', url: '/api-docs' },
{ text: 'Community', url: '/community' },
]}
/>
{props.children}
<Footer openConsentManager={open} />
</>
)
}

StandardLayout.rivetParams = {
query,
dependencies: [],
}

interface Props {
children: React.ReactChildren
data: {
useCaseNavItems: Array<{ slug: string; text: string }>
}
}
6 changes: 6 additions & 0 deletions website/layouts/standard/query.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query UseCasesQuery {
useCaseNavItems: allVaultUseCases {
url: slug
text: heroHeading
}
}
33 changes: 24 additions & 9 deletions website/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ import '@hashicorp/platform-util/nprogress/style.css'

import Router from 'next/router'
import Head from 'next/head'
import rivetQuery from '@hashicorp/nextjs-scripts/dato/client'
import { ErrorBoundary } from '@hashicorp/platform-runtime-error-monitoring'
import createConsentManager from '@hashicorp/react-consent-manager/loader'
import NProgress from '@hashicorp/platform-util/nprogress'
import useFathomAnalytics from '@hashicorp/platform-analytics'
import useAnchorLinkAnalytics from '@hashicorp/platform-util/anchor-link-analytics'
import HashiHead from '@hashicorp/react-head'
import ProductSubnav from 'components/subnav'
import HashiStackMenu from '@hashicorp/react-hashi-stack-menu'
import Footer from 'components/footer'
import Error from './_error'
import AlertBanner from '@hashicorp/react-alert-banner'
import alertBannerData, { ALERT_BANNER_ACTIVE } from '../data/alert-banner'
import StandardLayout from 'layouts/standard'

NProgress({ Router })
const { ConsentManager, openConsentManager } = createConsentManager({
const { ConsentManager } = createConsentManager({
preset: 'oss',
})

export default function App({ Component, pageProps }) {
export default function App({ Component, pageProps, layoutData }) {
useFathomAnalytics()
useAnchorLinkAnalytics()

const Layout = Component.layout ?? StandardLayout

return (
<ErrorBoundary FallbackComponent={Error}>
<HashiHead
Expand Down Expand Up @@ -59,11 +60,25 @@ export default function App({ Component, pageProps }) {
{ALERT_BANNER_ACTIVE && (
<AlertBanner {...alertBannerData} product="vault" hideOnMobile />
)}
<HashiStackMenu />
<ProductSubnav />
<Component {...pageProps} />
<Footer openConsentManager={openConsentManager} />
<Layout {...(layoutData && { data: layoutData })}>
<Component {...pageProps} />
</Layout>
<ConsentManager className="g-consent-manager" />
</ErrorBoundary>
)
}

App.getInitialProps = async ({ Component, ctx }) => {
const layoutQuery = Component.layout
? Component.layout?.rivetParams ?? null
Copy link
Contributor

Choose a reason for hiding this comment

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

They're not perfect, and it's not a blocker by any means, but here's what I put in the global types for RivetParams

interface RivetParams {
  query: string
  dependencies?: any[]
  variables?: Record<string, any>
  fragments?: any[]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will keep in mind, currently app is not a TS file.

: StandardLayout.rivetParams

const layoutData = layoutQuery ? await rivetQuery(layoutQuery) : null

let pageProps = {}

if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}
return { pageProps, layoutData }
}