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

docs: move edit date to footer #11667

Merged
merged 2 commits into from
Feb 28, 2025
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
7 changes: 2 additions & 5 deletions www/apps/book/app/learn/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TightLayout } from "docs-ui"
import Feedback from "@/components/Feedback"
import EditButton from "@/components/EditButton"
import Providers from "../../providers"
import Footer from "../../components/Footer"

export default function RootLayout({
children,
Expand All @@ -13,10 +12,8 @@ export default function RootLayout({
sidebarProps={{
expandItems: true,
}}
showPagination={true}
feedbackComponent={<Feedback className="my-2" />}
editComponent={<EditButton />}
ProvidersComponent={Providers}
footerComponent={<Footer />}
>
{children}
</TightLayout>
Expand Down
7 changes: 2 additions & 5 deletions www/apps/book/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { TightLayout } from "docs-ui"
import Feedback from "../components/Feedback"
import EditButton from "../components/EditButton"
import NotFoundContent from "./_not-found.mdx"
import Providers from "../providers"
import Footer from "../components/Footer"

const NotFoundPage = () => {
return (
<TightLayout
sidebarProps={{
expandItems: true,
}}
showPagination={true}
feedbackComponent={<Feedback className="my-2" />}
editComponent={<EditButton />}
footerComponent={<Footer />}
ProvidersComponent={Providers}
>
{/* @ts-ignore React v19 doesn't recognize MDX import as component */}
Expand Down
11 changes: 11 additions & 0 deletions www/apps/book/components/EditButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@

import { EditButton as UiEditButton } from "docs-ui"
import { usePathname } from "next/navigation"
import { useMemo } from "react"
import { generatedEditDates } from "../../generated/edit-dates.mjs"

const EditButton = () => {
const pathname = usePathname()

const editDate = useMemo(
() =>
(generatedEditDates as Record<string, string>)[
`app${pathname.replace(/\/$/, "")}/page.mdx`
],
[pathname]
)

return (
<UiEditButton
filePath={`/www/apps/book/app${pathname.replace(/\/$/, "")}/page.mdx`}
editDate={editDate}
/>
)
}
Expand Down
17 changes: 17 additions & 0 deletions www/apps/book/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use client"

import { Footer as UiFooter } from "docs-ui"
import Feedback from "../Feedback"
import EditButton from "../EditButton"

const Footer = () => {
return (
<UiFooter
showPagination={true}
feedbackComponent={<Feedback className="my-2" />}
editComponent={<EditButton />}
/>
)
}

export default Footer
13 changes: 1 addition & 12 deletions www/apps/book/providers/main-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import {
} from "docs-ui"
import { useMemo } from "react"
import { config } from "../config"
import { usePathname } from "next/navigation"
import { generatedEditDates } from "../generated/edit-dates.mjs"

type MainNavProviderProps = {
children?: React.ReactNode
}

export const MainNavProvider = ({ children }: MainNavProviderProps) => {
const pathname = usePathname()
const navigationDropdownItems = useMemo(
() =>
getNavDropdownItems({
Expand All @@ -23,16 +20,8 @@ export const MainNavProvider = ({ children }: MainNavProviderProps) => {
[]
)

const editDate = useMemo(
() =>
(generatedEditDates as Record<string, string>)[
`app${pathname.replace(/\/$/, "")}/page.mdx`
],
[pathname]
)

return (
<UiMainNavProvider navItems={navigationDropdownItems} editDate={editDate}>
<UiMainNavProvider navItems={navigationDropdownItems}>
{children}
</UiMainNavProvider>
)
Expand Down
6 changes: 2 additions & 4 deletions www/apps/resources/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import "./globals.css"
import { BareboneLayout, TightLayout } from "docs-ui"
import { config } from "@/config"
import clsx from "clsx"
import { Feedback } from "@/components/Feedback"
import EditButton from "@/components/EditButton"
import Footer from "../components/Footer"

const ogImage =
"https://res.cloudinary.com/dza7lstvk/image/upload/v1732200992/Medusa%20Resources/opengraph-image_daq6nx.jpg"
Expand Down Expand Up @@ -68,9 +67,8 @@ export default function RootLayout({
sidebarProps={{
expandItems: true,
}}
feedbackComponent={<Feedback className="my-2" />}
editComponent={<EditButton />}
ProvidersComponent={Providers}
footerComponent={<Footer />}
>
{children}
</TightLayout>
Expand Down
11 changes: 10 additions & 1 deletion www/apps/resources/components/EditButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { usePathname } from "next/navigation"
import { useMemo } from "react"
import { EditButton as UiEditButton } from "docs-ui"
import { filesMap } from "../../generated/files-map.mjs"
import { generatedEditDates } from "../../generated/edit-dates.mjs"

const EditButton = () => {
const pathname = usePathname()
Expand All @@ -12,11 +13,19 @@ const EditButton = () => {
[pathname]
)

const editDate = useMemo(
() =>
(generatedEditDates as Record<string, string>)[
`app${pathname.replace(/\/$/, "")}/page.mdx`
],
[pathname]
)

if (!filePath) {
return <></>
}

return <UiEditButton filePath={filePath.filePath} />
return <UiEditButton filePath={filePath.filePath} editDate={editDate} />
}

export default EditButton
17 changes: 17 additions & 0 deletions www/apps/resources/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use client"

import { Footer as UiFooter } from "docs-ui"
import { Feedback } from "../Feedback"
import EditButton from "../EditButton"

const Footer = () => {
return (
<UiFooter
showPagination={false}
feedbackComponent={<Feedback className="my-2" />}
editComponent={<EditButton />}
/>
)
}

export default Footer
13 changes: 1 addition & 12 deletions www/apps/resources/providers/main-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import {
} from "docs-ui"
import { useMemo } from "react"
import { config } from "../config"
import { usePathname } from "next/navigation"
import { generatedEditDates } from "../generated/edit-dates.mjs"

type MainNavProviderProps = {
children?: React.ReactNode
}

export const MainNavProvider = ({ children }: MainNavProviderProps) => {
const pathname = usePathname()
const navigationDropdownItems = useMemo(
() =>
getNavDropdownItems({
Expand All @@ -23,16 +20,8 @@ export const MainNavProvider = ({ children }: MainNavProviderProps) => {
[]
)

const editDate = useMemo(
() =>
(generatedEditDates as Record<string, string>)[
`app${pathname.replace(/\/$/, "")}/page.mdx`
],
[pathname]
)

return (
<UiMainNavProvider navItems={navigationDropdownItems} editDate={editDate}>
<UiMainNavProvider navItems={navigationDropdownItems}>
{children}
</UiMainNavProvider>
)
Expand Down
2 changes: 2 additions & 0 deletions www/apps/user-guide/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { config } from "@/config"
import clsx from "clsx"
import Feedback from "../components/Feedback"
import EditButton from "../components/EditButton"
import Footer from "../components/Footer"

const ogImage =
"https://res.cloudinary.com/dza7lstvk/image/upload/v1732200992/Medusa%20Resources/opengraph-image_daq6nx.jpg"
Expand Down Expand Up @@ -68,6 +69,7 @@ export default function RootLayout({
expandItems: true,
}}
ProvidersComponent={Providers}
footerComponent={<Footer />}
>
{children}
<Feedback className="my-2" />
Expand Down
11 changes: 11 additions & 0 deletions www/apps/user-guide/components/EditButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,27 @@

import { EditButton as UiEditButton } from "docs-ui"
import { usePathname } from "next/navigation"
import { useMemo } from "react"
import { generatedEditDates } from "../../generated/edit-dates.mjs"

const EditButton = () => {
const pathname = usePathname()

const editDate = useMemo(
() =>
(generatedEditDates as Record<string, string>)[
`app${pathname.replace(/\/$/, "")}/page.mdx`
],
[pathname]
)

return (
<UiEditButton
filePath={`/www/apps/user-guide/app${pathname.replace(
/\/$/,
""
)}/page.mdx`}
editDate={editDate}
/>
)
}
Expand Down
17 changes: 17 additions & 0 deletions www/apps/user-guide/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use client"

import { Footer as UiFooter } from "docs-ui"
import Feedback from "../Feedback"
import EditButton from "../EditButton"

const Footer = () => {
return (
<UiFooter
showPagination={true}
feedbackComponent={<Feedback className="my-2" />}
editComponent={<EditButton />}
/>
)
}

export default Footer
13 changes: 1 addition & 12 deletions www/apps/user-guide/providers/main-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import {
} from "docs-ui"
import { useMemo } from "react"
import { config } from "../config"
import { generatedEditDates } from "../generated/edit-dates.mjs"
import { usePathname } from "next/navigation"

type MainNavProviderProps = {
children?: React.ReactNode
}

export const MainNavProvider = ({ children }: MainNavProviderProps) => {
const pathname = usePathname()
const navigationDropdownItems = useMemo(
() =>
getNavDropdownItems({
Expand All @@ -23,16 +20,8 @@ export const MainNavProvider = ({ children }: MainNavProviderProps) => {
[]
)

const editDate = useMemo(
() =>
(generatedEditDates as Record<string, string>)[
`app${pathname.replace(/\/$/, "")}/page.mdx`
],
[pathname]
)

return (
<UiMainNavProvider navItems={navigationDropdownItems} editDate={editDate}>
<UiMainNavProvider navItems={navigationDropdownItems}>
{children}
</UiMainNavProvider>
)
Expand Down
30 changes: 18 additions & 12 deletions www/packages/docs-ui/src/components/EditButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@ import React from "react"
import Link from "next/link"
import clsx from "clsx"
import { ArrowUpRightOnBox } from "@medusajs/icons"
import { EditDate } from "../EditDate"

type EditButtonProps = {
filePath: string
editDate?: string
}

export const EditButton = ({ filePath }: EditButtonProps) => {
export const EditButton = ({ filePath, editDate }: EditButtonProps) => {
return (
<Link
href={`https://github.com/medusajs/medusa/edit/develop${filePath}`}
className={clsx(
"flex w-fit gap-docs_0.25 my-docs_2 items-center",
"text-medusa-fg-muted hover:text-medusa-fg-subtle",
"text-compact-small-plus"
)}
>
<span>Edit this page</span>
<ArrowUpRightOnBox />
</Link>
<div className="flex flex-wrap gap-docs_0.5 mt-docs_2 text-medusa-fg-subtle">
{editDate && <EditDate date={editDate} />}

<Link
href={`https://github.com/medusajs/medusa/edit/develop${filePath}`}
className={clsx(
"flex w-fit gap-docs_0.25 items-center",
"text-medusa-fg-subtle hover:text-medusa-fg-base",
"text-compact-small-plus"
)}
>
<span>Edit this page</span>
<ArrowUpRightOnBox />
</Link>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from "react"

const DATE_REGEX = /^[a-zA-Z]+ (?<month>[a-zA-Z]+)/

type MainNavEditDateProps = {
type EditDateProps = {
date: string
}

export const MainNavEditDate = ({ date }: MainNavEditDateProps) => {
export const EditDate = ({ date }: EditDateProps) => {
const today = new Date(date)
const dateObj = new Date(date)
const formattedDate = dateObj.toString()
Expand Down
23 changes: 23 additions & 0 deletions www/packages/docs-ui/src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react"
import { Pagination } from "../Pagination"

export type FooterProps = {
editComponent?: React.ReactNode
showPagination?: boolean
feedbackComponent?: React.ReactNode
editDate?: string
}

export const Footer = ({
editComponent,
showPagination,
feedbackComponent,
}: FooterProps) => {
return (
<>
{feedbackComponent}
{showPagination && <Pagination />}
{editComponent}
</>
)
}
Loading
Loading