Skip to content

Commit

Permalink
Merge branch 'develop' into docs/mikro-orm-link-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser authored Jan 23, 2025
2 parents 6a89c86 + c4eb36b commit 66e2474
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-dancers-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---

fix(dashboard): Format i18n schema with Prettier
31 changes: 23 additions & 8 deletions packages/admin/dashboard/scripts/i18n/generate-schema.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require("fs")
const fs = require("fs/promises")
const path = require("path")
const prettier = require("prettier")

const translationsDir = path.join(__dirname, "../../src/i18n/translations")
const enPath = path.join(translationsDir, "en.json")
Expand Down Expand Up @@ -33,17 +34,31 @@ function generateSchemaFromObject(obj) {
}
}

try {
const enJson = JSON.parse(fs.readFileSync(enPath, "utf-8"))
async function outputSchema() {
const enContent = await fs.readFile(enPath, "utf-8")
const enJson = JSON.parse(enContent)

const schema = {
$schema: "http://json-schema.org/draft-07/schema#",
...generateSchemaFromObject(enJson),
}

fs.writeFileSync(schemaPath, JSON.stringify(schema, null, 2))
console.log("Schema generated successfully at:", schemaPath)
} catch (error) {
console.error("Error generating schema:", error.message)
process.exit(1)
const formattedSchema = await prettier.format(
JSON.stringify(schema, null, 2),
{
parser: "json",
}
)

await fs
.writeFile(schemaPath, formattedSchema)
.then(() => {
console.log("Schema generated successfully at:", schemaPath)
})
.catch((error) => {
console.error("Error generating schema:", error.message)
process.exit(1)
})
}

outputSchema()
14 changes: 14 additions & 0 deletions www/apps/api-reference/components/Tags/Section/Schema/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
Badge,
CodeBlock,
isElmWindow,
Link,
Note,
useIsBrowser,
useScrollController,
useSidebar,
Expand All @@ -20,6 +22,7 @@ import { InView } from "react-intersection-observer"
import checkElementInViewport from "../../../../utils/check-element-in-viewport"
import { singular } from "pluralize"
import clsx from "clsx"
import { useArea } from "../../../../providers/area"

export type TagSectionSchemaProps = {
schema: SchemaObject
Expand All @@ -29,6 +32,7 @@ export type TagSectionSchemaProps = {
const TagSectionSchema = ({ schema, tagName }: TagSectionSchemaProps) => {
const paramsRef = useRef<HTMLDivElement>(null)
const { addItems, setActivePath, activePath } = useSidebar()
const { displayedArea } = useArea()
const tagSlugName = useMemo(() => getSectionId([tagName]), [tagName])
const formattedName = useMemo(
() => singular(tagName).replaceAll(" ", ""),
Expand Down Expand Up @@ -129,6 +133,16 @@ const TagSectionSchema = ({ schema, tagName }: TagSectionSchemaProps) => {
mainContent={
<div>
<h2>{formattedName} Object</h2>
<Note>
This object&apos;s schema is as returned by Medusa&apos;s{" "}
{displayedArea} API routes. However, the related model in the
Medusa application may support more fields and relations. To
view the models in the Medusa application and their relations,
visit the{" "}
<Link href="https://docs.medusajs.com/resources/commerce-modules">
Commerce Modules Documentation
</Link>
</Note>
<h4 className="border-medusa-border-base border-b py-1.5 mt-2">
Fields
</h4>
Expand Down
10 changes: 8 additions & 2 deletions www/apps/api-reference/providers/area.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"use client"

import type { Area } from "@/types/openapi"
import { usePrevious, useSearch } from "docs-ui"
import { createContext, useContext, useEffect, useState } from "react"
import { capitalize, usePrevious, useSearch } from "docs-ui"
import { createContext, useContext, useEffect, useMemo, useState } from "react"

type AreaContextType = {
area: Area
prevArea: Area | undefined
displayedArea: string
setArea: (value: Area) => void
}

Expand All @@ -22,6 +23,10 @@ const AreaProvider = ({ area: passedArea, children }: AreaProviderProps) => {
const prevArea = usePrevious(area)
const { defaultFilters, setDefaultFilters } = useSearch()

const displayedArea = useMemo(() => {
return capitalize(area)
}, [area])

useEffect(() => {
if (!defaultFilters.includes(`${area}-v2`)) {
setDefaultFilters([`${area}-v2`])
Expand All @@ -34,6 +39,7 @@ const AreaProvider = ({ area: passedArea, children }: AreaProviderProps) => {
area,
prevArea,
setArea,
displayedArea,
}}
>
{children}
Expand Down
8 changes: 4 additions & 4 deletions www/apps/api-reference/providers/page-title.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client"

import { createContext, useEffect } from "react"
import { capitalize, useSidebar } from "docs-ui"
import { useSidebar } from "docs-ui"
import { useArea } from "./area"
import { SidebarItemLink } from "types"

Expand All @@ -13,10 +13,10 @@ type PageTitleProviderProps = {

const PageTitleProvider = ({ children }: PageTitleProviderProps) => {
const { activePath, activeItem } = useSidebar()
const { area } = useArea()
const { displayedArea } = useArea()

useEffect(() => {
const titleSuffix = `Medusa ${capitalize(area)} API Reference`
const titleSuffix = `Medusa ${displayedArea} API Reference`

if (!activePath?.length) {
document.title = titleSuffix
Expand All @@ -33,7 +33,7 @@ const PageTitleProvider = ({ children }: PageTitleProviderProps) => {
}
}
}
}, [activePath, area, activeItem])
}, [activePath, displayedArea, activeItem])

return (
<PageTitleContext.Provider value={null}>
Expand Down
15 changes: 7 additions & 8 deletions www/packages/docs-ui/src/components/Link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import type { LinkProps as NextLinkProps } from "next/link"
import clsx from "clsx"
import { TriangleRightMini } from "@medusajs/icons"

export type LinkProps = {
href?: string
children?: React.ReactNode
className?: string
target?: string
rel?: string
withIcon?: boolean
} & Partial<NextLinkProps>
export type LinkProps = Partial<NextLinkProps> &
React.AllHTMLAttributes<HTMLAnchorElement> & {
href?: string
children?: React.ReactNode
className?: string
withIcon?: boolean
}

export const Link = ({
href,
Expand Down

0 comments on commit 66e2474

Please sign in to comment.