docs: update api-reference project for v2 (#7307)
* remove everything v1 and make v2 default * move main v2 rewrites to book * move rewrites to book + other fixes
This commit is contained in:
@@ -11,20 +11,19 @@ import { useMemo } from "react"
|
||||
import { config } from "../../config"
|
||||
import { usePathname } from "next/navigation"
|
||||
import VersionSwitcher from "../VersionSwitcher"
|
||||
import { useVersion } from "../../providers/version"
|
||||
import basePathUrl from "../../utils/base-path-url"
|
||||
|
||||
const Navbar = () => {
|
||||
const { setMobileSidebarOpen, mobileSidebarOpen } = useSidebar()
|
||||
const pathname = usePathname()
|
||||
const { isLoading } = usePageLoading()
|
||||
const { isVersioningEnabled } = useVersion()
|
||||
|
||||
const navbarItems = useMemo(
|
||||
() =>
|
||||
getNavbarItems({
|
||||
basePath: config.baseUrl,
|
||||
activePath: pathname,
|
||||
version: process.env.NEXT_PUBLIC_SHOW_V2 ? "v1" : "legacy",
|
||||
version: "v2",
|
||||
}),
|
||||
[pathname]
|
||||
)
|
||||
@@ -32,17 +31,15 @@ const Navbar = () => {
|
||||
return (
|
||||
<UiNavbar
|
||||
logo={{
|
||||
light: "/images/logo-icon.png",
|
||||
dark: "/images/logo-icon-dark.png",
|
||||
light: basePathUrl("/images/logo-icon.png"),
|
||||
dark: basePathUrl("/images/logo-icon-dark.png"),
|
||||
}}
|
||||
items={navbarItems}
|
||||
mobileMenuButton={{
|
||||
setMobileSidebarOpen,
|
||||
mobileSidebarOpen,
|
||||
}}
|
||||
additionalActionsBefore={
|
||||
<>{isVersioningEnabled && <VersionSwitcher />}</>
|
||||
}
|
||||
additionalActionsBefore={<VersionSwitcher />}
|
||||
additionalActionsAfter={<FeedbackModal />}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
"use client"
|
||||
|
||||
import { capitalize } from "docs-ui"
|
||||
import { useArea } from "../../providers/area"
|
||||
import { useVersion } from "../../providers/version"
|
||||
|
||||
type PageHeadingProps = {
|
||||
className?: string
|
||||
}
|
||||
|
||||
const PageHeading = ({ className }: PageHeadingProps) => {
|
||||
const { area } = useArea()
|
||||
const { version, isVersioningEnabled } = useVersion()
|
||||
|
||||
const versionText = isVersioningEnabled ? ` V${version}` : ""
|
||||
|
||||
return (
|
||||
<h1 className={className}>
|
||||
Medusa{versionText} {capitalize(area)} API Reference
|
||||
</h1>
|
||||
)
|
||||
}
|
||||
|
||||
export default PageHeading
|
||||
@@ -4,7 +4,7 @@ import getSectionId from "@/utils/get-section-id"
|
||||
import type { OpenAPIV3 } from "openapi-types"
|
||||
import useSWR from "swr"
|
||||
import type { Operation, PathsObject } from "@/types/openapi"
|
||||
import { useSidebar, swrFetcher, getLinkWithBasePath } from "docs-ui"
|
||||
import { useSidebar, swrFetcher } from "docs-ui"
|
||||
import { Fragment, useEffect, useMemo } from "react"
|
||||
import dynamic from "next/dynamic"
|
||||
import type { TagOperationProps } from "../Operation"
|
||||
@@ -15,7 +15,7 @@ import getTagChildSidebarItems from "@/utils/get-tag-child-sidebar-items"
|
||||
import { useLoading } from "@/providers/loading"
|
||||
import DividedLoading from "@/components/DividedLoading"
|
||||
import { SidebarItemSections, SidebarItemType } from "types"
|
||||
import { useVersion } from "../../../providers/version"
|
||||
import basePathUrl from "../../../utils/base-path-url"
|
||||
|
||||
const TagOperation = dynamic<TagOperationProps>(
|
||||
async () => import("../Operation")
|
||||
@@ -28,7 +28,6 @@ export type TagPathsProps = {
|
||||
const TagPaths = ({ tag, className }: TagPathsProps) => {
|
||||
const tagSlugName = useMemo(() => getSectionId([tag.name]), [tag])
|
||||
const { area } = useArea()
|
||||
const { version } = useVersion()
|
||||
const { items, addItems, findItemInSection } = useSidebar()
|
||||
const { baseSpecs } = useBaseSpecs()
|
||||
const { loading } = useLoading()
|
||||
@@ -44,10 +43,7 @@ const TagPaths = ({ tag, className }: TagPathsProps) => {
|
||||
paths: PathsObject
|
||||
}>(
|
||||
!Object.keys(paths).length
|
||||
? getLinkWithBasePath(
|
||||
`/tag?tagName=${tagSlugName}&area=${area}&version=${version}`,
|
||||
process.env.NEXT_PUBLIC_BASE_PATH
|
||||
)
|
||||
? basePathUrl(`/api/tag?tagName=${tagSlugName}&area=${area}`)
|
||||
: null,
|
||||
swrFetcher,
|
||||
{
|
||||
|
||||
@@ -4,7 +4,6 @@ import getSectionId from "@/utils/get-section-id"
|
||||
import { useInView } from "react-intersection-observer"
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
import {
|
||||
getLinkWithBasePath,
|
||||
isElmWindow,
|
||||
swrFetcher,
|
||||
useScrollController,
|
||||
@@ -25,8 +24,8 @@ import { usePathname } from "next/navigation"
|
||||
import formatReportLink from "@/utils/format-report-link"
|
||||
import { SchemaObject, TagObject } from "@/types/openapi"
|
||||
import useSWR from "swr"
|
||||
import { useVersion } from "@/providers/version"
|
||||
import { TagSectionSchemaProps } from "./Schema"
|
||||
import basePathUrl from "../../../utils/base-path-url"
|
||||
|
||||
export type TagSectionProps = {
|
||||
tag: TagObject
|
||||
@@ -54,14 +53,12 @@ const TagSection = ({ tag }: TagSectionProps) => {
|
||||
const { area } = useArea()
|
||||
const pathname = usePathname()
|
||||
const { scrollableElement } = useScrollController()
|
||||
const { version } = useVersion()
|
||||
const { data } = useSWR<{
|
||||
schema: SchemaObject
|
||||
}>(
|
||||
tag["x-associatedSchema"]
|
||||
? getLinkWithBasePath(
|
||||
`/schema?name=${tag["x-associatedSchema"].$ref}&area=${area}&version=${version}`,
|
||||
process.env.NEXT_PUBLIC_BASE_PATH
|
||||
? basePathUrl(
|
||||
`/api/schema?name=${tag["x-associatedSchema"].$ref}&area=${area}`
|
||||
)
|
||||
: null,
|
||||
swrFetcher,
|
||||
|
||||
@@ -7,12 +7,12 @@ import { useBaseSpecs } from "@/providers/base-specs"
|
||||
import dynamic from "next/dynamic"
|
||||
import type { TagSectionProps } from "./Section"
|
||||
import { useArea } from "@/providers/area"
|
||||
import { swrFetcher, useSidebar, getLinkWithBasePath } from "docs-ui"
|
||||
import { swrFetcher, useSidebar } from "docs-ui"
|
||||
import getSectionId from "@/utils/get-section-id"
|
||||
import { ExpandedDocument } from "@/types/openapi"
|
||||
import getTagChildSidebarItems from "@/utils/get-tag-child-sidebar-items"
|
||||
import { SidebarItemSections } from "types"
|
||||
import { useVersion } from "../../providers/version"
|
||||
import basePathUrl from "../../utils/base-path-url"
|
||||
|
||||
const TagSection = dynamic<TagSectionProps>(
|
||||
async () => import("./Section")
|
||||
@@ -33,14 +33,10 @@ const Tags = () => {
|
||||
const { baseSpecs, setBaseSpecs } = useBaseSpecs()
|
||||
const { addItems } = useSidebar()
|
||||
const { area } = useArea()
|
||||
const { version } = useVersion()
|
||||
|
||||
const { data } = useSWR<ExpandedDocument>(
|
||||
loadData && !baseSpecs
|
||||
? getLinkWithBasePath(
|
||||
`/base-specs?area=${area}&expand=${expand}&version=${version}`,
|
||||
process.env.NEXT_PUBLIC_BASE_PATH
|
||||
)
|
||||
? basePathUrl(`/api/base-specs?area=${area}&expand=${expand}`)
|
||||
: null,
|
||||
swrFetcher,
|
||||
{
|
||||
|
||||
@@ -3,41 +3,20 @@
|
||||
import { Toggle } from "docs-ui"
|
||||
import clsx from "clsx"
|
||||
import { usePathname } from "next/navigation"
|
||||
import { useVersion } from "../../providers/version"
|
||||
|
||||
const VersionSwitcher = () => {
|
||||
const pathname = usePathname()
|
||||
const { version } = useVersion()
|
||||
|
||||
return (
|
||||
<div className="flex gap-0.5 justify-center items-center">
|
||||
<span
|
||||
className={clsx(
|
||||
version === "1" && "text-medusa-fg-subtle",
|
||||
version === "2" && "text-medusa-fg-disabled"
|
||||
)}
|
||||
>
|
||||
V1
|
||||
</span>
|
||||
<span className={clsx("text-medusa-fg-disabled")}>V1</span>
|
||||
<Toggle
|
||||
checked={version === "2"}
|
||||
onCheckedChange={(checked) => {
|
||||
let newPath = pathname.replace("/v2", "")
|
||||
if (checked) {
|
||||
newPath += `/v2`
|
||||
}
|
||||
|
||||
location.href = location.href.replace(pathname, newPath)
|
||||
checked={true}
|
||||
onCheckedChange={() => {
|
||||
location.href = process.env.NEXT_PUBLIC_API_V1_URL + pathname
|
||||
}}
|
||||
/>
|
||||
<span
|
||||
className={clsx(
|
||||
version === "1" && "text-medusa-fg-disabled",
|
||||
version === "2" && "text-medusa-fg-subtle"
|
||||
)}
|
||||
>
|
||||
V2
|
||||
</span>
|
||||
<span className={clsx("text-medusa-fg-subtle")}>V2</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user