Skip to content

Commit

Permalink
Merge branch 'feat/data-table-medusa-ui' of https://github.com/medusa…
Browse files Browse the repository at this point in the history
…js/medusa into feat/data-table-medusa-ui
  • Loading branch information
kasperkristensen committed Nov 13, 2024
2 parents 1ed5739 + 02fd54b commit 4b88cfa
Show file tree
Hide file tree
Showing 152 changed files with 4,506 additions and 3,293 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docs-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
run: yarn build
env:
NEXT_PUBLIC_BASE_URL: "http://localhost:3000"
NEXT_PUBLIC_BASE_PATH: /api
NEXT_PUBLIC_DOCS_URL: "https://medusa-docs.vercel.app"
NEXT_PUBLIC_UI_URL: "https://docs-ui.vercel.app"
# TODO change once we have actual URLs
Expand Down Expand Up @@ -317,7 +318,7 @@ jobs:
- name: Get Directories to Scan
if: ${{ steps.pr-files.outputs.files_lt_threshold == 'true' }}
working-directory: www/vale
run: ./get-files.sh api-reference app/_mdx
run: ./get-files.sh api-reference markdown
id: directories

- name: Vale Linter
Expand Down
230 changes: 230 additions & 0 deletions packages/core/utils/src/dml/__tests__/entity-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4702,6 +4702,236 @@ describe("Entity builder", () => {
},
})
})

test("define entity with relationship to itself via hasMany", () => {
const user = model.define("user", {
id: model.number(),
username: model.text(),
parent: model.belongsTo(() => user, { mappedBy: "children" }),
children: model.hasMany(() => user, { mappedBy: "parent" }),
})

const [User] = toMikroOrmEntities([user])

expectTypeOf(new User()).toMatchTypeOf<{
id: number
username: string
deleted_at: Date | null
parent: {
id: number
username: string
deleted_at: Date | null
}
children: {
id: number
username: string
deleted_at: Date | null
}[]
}>()

const metaData = MetadataStorage.getMetadataFromDecorator(User)
expect(metaData.className).toEqual("User")
expect(metaData.path).toEqual("User")
expect(metaData.properties).toEqual({
id: {
reference: "scalar",
type: "number",
columnType: "integer",
name: "id",
fieldName: "id",
nullable: false,
getter: false,
setter: false,
},
username: {
reference: "scalar",
type: "string",
columnType: "text",
name: "username",
fieldName: "username",
nullable: false,
getter: false,
setter: false,
},
parent: {
name: "parent",
reference: "m:1",
entity: "User",
persist: false,
nullable: false,
},
parent_id: {
name: "parent_id",
reference: "m:1",
entity: "User",
columnType: "text",
fieldName: "parent_id",
mapToPk: true,
nullable: false,
onDelete: undefined,
isForeignKey: true,
},
children: {
cascade: undefined,
entity: "User",
mappedBy: "parent",
name: "children",
orphanRemoval: true,
reference: "1:m",
},
created_at: {
reference: "scalar",
type: "date",
columnType: "timestamptz",
name: "created_at",
fieldName: "created_at",
defaultRaw: "now()",
onCreate: expect.any(Function),
nullable: false,
getter: false,
setter: false,
},
updated_at: {
reference: "scalar",
type: "date",
columnType: "timestamptz",
name: "updated_at",
fieldName: "updated_at",
defaultRaw: "now()",
onCreate: expect.any(Function),
onUpdate: expect.any(Function),
nullable: false,
getter: false,
setter: false,
},
deleted_at: {
reference: "scalar",
type: "date",
columnType: "timestamptz",
name: "deleted_at",
fieldName: "deleted_at",
nullable: true,
getter: false,
setter: false,
},
})
})

test("define relationship with self via hasOne", () => {
const user = model.define("user", {
id: model.number(),
username: model.text(),
parent: model.belongsTo(() => user, { mappedBy: "child" }),
child: model.hasOne(() => user, { mappedBy: "parent" }),
})

const [User] = toMikroOrmEntities([user])

expectTypeOf(new User()).toMatchTypeOf<{
id: number
username: string
deleted_at: Date | null
parent: {
id: number
username: string
deleted_at: Date | null
}
child: {
id: number
username: string
deleted_at: Date | null
}
}>()

const metaData = MetadataStorage.getMetadataFromDecorator(User)
expect(metaData.className).toEqual("User")
expect(metaData.path).toEqual("User")
expect(metaData.properties).toEqual({
id: {
reference: "scalar",
type: "number",
columnType: "integer",
name: "id",
fieldName: "id",
nullable: false,
getter: false,
setter: false,
},
username: {
reference: "scalar",
type: "string",
columnType: "text",
name: "username",
fieldName: "username",
nullable: false,
getter: false,
setter: false,
},
parent: {
name: "parent",
mappedBy: "child",
reference: "1:1",
entity: "User",
nullable: false,
onDelete: undefined,
owner: true,
},
parent_id: {
name: "parent_id",
type: "string",
columnType: "text",
isForeignKey: true,
persist: false,
reference: "scalar",
getter: false,
setter: false,
nullable: false,
},
child: {
cascade: undefined,
entity: "User",
mappedBy: "parent",
name: "child",
nullable: false,
reference: "1:1",
},
created_at: {
reference: "scalar",
type: "date",
columnType: "timestamptz",
name: "created_at",
fieldName: "created_at",
defaultRaw: "now()",
onCreate: expect.any(Function),
nullable: false,
getter: false,
setter: false,
},
updated_at: {
reference: "scalar",
type: "date",
columnType: "timestamptz",
name: "updated_at",
fieldName: "updated_at",
defaultRaw: "now()",
onCreate: expect.any(Function),
onUpdate: expect.any(Function),
nullable: false,
getter: false,
setter: false,
},
deleted_at: {
reference: "scalar",
type: "date",
columnType: "timestamptz",
name: "deleted_at",
fieldName: "deleted_at",
nullable: true,
getter: false,
setter: false,
},
})
})
})

describe("Entity builder | manyToMany", () => {
Expand Down
10 changes: 0 additions & 10 deletions www/.eslintrc.js

This file was deleted.

11 changes: 0 additions & 11 deletions www/apps/api-reference/.eslintrc.js

This file was deleted.

5 changes: 4 additions & 1 deletion www/apps/api-reference/app/admin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import AreaProvider from "@/providers/area"
import AdminContent from "../_mdx/admin.mdx"
import AdminContent from "@/markdown/admin.mdx"
import Tags from "@/components/Tags"
import PageTitleProvider from "@/providers/page-title"
import { H1 } from "docs-ui"
import { getBaseSpecs } from "../../lib"
import BaseSpecsProvider from "../../providers/base-specs"
import clsx from "clsx"
import React from "react"

const AdminPage = async () => {
const data = await getBaseSpecs("admin")
Expand All @@ -23,6 +25,7 @@ const AdminPage = async () => {
>
Medusa V2 Admin API Reference
</H1>
{/* @ts-ignore React v19 doesn't see MDX as valid component */}
<AdminContent />
<Tags tags={data?.tags} />
</PageTitleProvider>
Expand Down
7 changes: 4 additions & 3 deletions www/apps/api-reference/app/download/[area]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { NextResponse } from "next/server"
import path from "path"

type DownloadParams = {
params: {
params: Promise<{
area: string
}
}>
}

export function GET(request: Request, { params }: DownloadParams) {
export async function GET(request: Request, props: DownloadParams) {
const params = await props.params
const { area } = params
const filePath = path.join(process.cwd(), "specs", area, "openapi.full.yaml")

Expand Down
4 changes: 3 additions & 1 deletion www/apps/api-reference/app/store/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import AreaProvider from "@/providers/area"
import StoreContent from "../_mdx/store.mdx"
import StoreContent from "@/markdown/store.mdx"
import Tags from "@/components/Tags"
import PageTitleProvider from "@/providers/page-title"
import { H1 } from "docs-ui"
Expand All @@ -23,6 +24,7 @@ const StorePage = async () => {
>
Medusa V2 Store API Reference
</H1>
{/* @ts-ignore React v19 doesn't see MDX as valid component */}
<StoreContent />
<Tags tags={data?.tags} />
</PageTitleProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ const TagOperationParametersObject = ({
properties[property2].isRequired
? 0
: properties[property1].isRequired
? -1
: 1
? -1
: 1
}
)
const content = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,21 @@ const TagOperationParamatersOneOf = ({
return (
<>
<div className={clsx("flex items-center gap-1 pl-1")}>
<span className="inline-block">One of</span>
<ul className="mb-0 flex list-none gap-1">
<span className="inline-block text-compact-x-small">One of</span>
<ul className="mb-0 flex list-none gap-0.5 flex-wrap">
{schema.oneOf?.map((item, index) => (
<li
key={index}
className={clsx(
"rounded-xs cursor-pointer p-0.5",
"border border-solid",
"rounded-full cursor-pointer px-[10px]",
"flex justify-center items-center text-compact-small-plus",
"focus:shadow-borders-interactive-with-focus transition-colors",
activeTab === index && [
"bg-medusa-bg-subtle border-medusa-border-strong",
"text-medusa-fg-base bg-medusa-bg-base",
"shadow-elevation-card-rest dark:shadow-elevation-card-rest-dark",
],
activeTab !== index && [
"bg-medusa-bg-base border-medusa-border-base",
"text-medusa-fg-muted hover:text-medusa-fg-base",
]
)}
onClick={() => setActiveTab(index)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const TagOperationParametersUnion = ({
const objectSchema = schema.anyOf
? schema.anyOf.find((item) => item.type === "object" && item.properties)
: schema.allOf
? mergeAllOfTypes(schema)
: undefined
? mergeAllOfTypes(schema)
: undefined

if (!objectSchema) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const TagSectionSchema = ({ schema, tagName }: TagSectionSchemaProps) => {
return (
<Suspense>
<InView
// @ts-expect-error Type is being read as undefined
as="div"
id={schemaSlug}
initialInView={true}
Expand Down
Loading

0 comments on commit 4b88cfa

Please sign in to comment.