feat(dashboard,types,sdk,medusa,ui): ProductCategory domain (#7675)
**What** - Add missing features to ProductCategory domain in admin - Add types - Add SDK **UI** - Moves the TooltipProvider from the component to an export. Users should now wrap their entire application in a TooltipProvider. This change was made to take advantage of the built-in features of Radix Tooltip, and allows us to skip the delayDuration when moving the cursor from one tooltip to another within 500ms. - Fixes the layout of the Hint component, as the create form revealed that it was off. - Fixes an issue where focus styles were missing from the dropdown menu. **Note** - ~~We currently don't have an endpoint for deleting categories, so I have disabled the button in the admin. See CORE--2286~~ PR has been opened to add delete endpoint, so I have re-enabled the delete button. - The update category workflow seems to be broken, it's possible for the `mpath` of a category to reach an invalid state, that breaks `include_descendants_tree` from working. See CORE-2287. - The ProductCategory model is incorrect. All fields are optional and it's not possible to set the description to null, which means the only way of unsetting it is to set it to `""`. See CORE-2276. - The design for the Organize drag-n-drop form is not final. Ludvig will create a final design, and we can then update the form. - Currently, all things related to Metadata is left out, as we need to update the flow for metadata according to the latest designs. RESOLVES CORE-1960, CORE-2230 *except for the above mentioned issues.
This commit is contained in:
1 parent
73ca358606
commit
2f76fbc6ed
71 files changed
+2207
-186
No files matched your search
@@ -5,6 +5,7 @@ import { FulfillmentSet } from "./fulfillment-set"
|
||||
import { Invite } from "./invite"
|
||||
import { Order } from "./order"
|
||||
import { Product } from "./product"
|
||||
import { ProductCategory } from "./product-category"
|
||||
import { ProductCollection } from "./product-collection"
|
||||
import { Region } from "./region"
|
||||
import { SalesChannel } from "./sales-channel"
|
||||
@@ -20,6 +21,7 @@ export class Admin {
|
||||
public invite: Invite
|
||||
public customer: Customer
|
||||
public productCollection: ProductCollection
|
||||
public productCategory: ProductCategory
|
||||
public product: Product
|
||||
public upload: Upload
|
||||
public region: Region
|
||||
@@ -38,6 +40,7 @@ export class Admin {
|
||||
this.invite = new Invite(client)
|
||||
this.customer = new Customer(client)
|
||||
this.productCollection = new ProductCollection(client)
|
||||
this.productCategory = new ProductCategory(client)
|
||||
this.product = new Product(client)
|
||||
this.upload = new Upload(client)
|
||||
this.region = new Region(client)
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { Client } from "../client"
|
||||
import { ClientHeaders } from "../types"
|
||||
|
||||
export class ProductCategory {
|
||||
private client: Client
|
||||
constructor(client: Client) {
|
||||
this.client = client
|
||||
}
|
||||
|
||||
async create(
|
||||
body: HttpTypes.AdminCreateProductCategory,
|
||||
query?: HttpTypes.AdminProductCategoryParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return this.client.fetch<HttpTypes.AdminProductCategoryResponse>(
|
||||
`/admin/product-categories`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
body: HttpTypes.AdminUpdateProductCategory,
|
||||
query?: HttpTypes.AdminProductCategoryParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return this.client.fetch<HttpTypes.AdminProductCategoryResponse>(
|
||||
`/admin/product-categories/${id}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async list(
|
||||
query?: HttpTypes.AdminProductCategoryListParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return this.client.fetch<HttpTypes.AdminProductCategoryListResponse>(
|
||||
`/admin/product-categories`,
|
||||
{
|
||||
headers,
|
||||
query: query,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async retrieve(
|
||||
id: string,
|
||||
query?: HttpTypes.AdminProductCategoryParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return this.client.fetch<HttpTypes.AdminProductCategoryResponse>(
|
||||
`/admin/product-categories/${id}`,
|
||||
{
|
||||
query,
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async delete(id: string, headers?: ClientHeaders) {
|
||||
return this.client.fetch<HttpTypes.AdminProductCategoryDeleteResponse>(
|
||||
`/admin/product-categories/${id}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async updateProducts(
|
||||
id: string,
|
||||
body: HttpTypes.AdminUpdateProductCategoryProducts,
|
||||
query?: HttpTypes.AdminProductCategoryParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return this.client.fetch<HttpTypes.AdminProductCategoryResponse>(
|
||||
`/admin/product-categories/${id}/products`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
query,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { PaginatedResponse } from "../common"
|
||||
import { ProductCategoryResponse } from "./common"
|
||||
|
||||
export interface AdminProductCategoryResponse {
|
||||
product_category: ProductCategoryResponse
|
||||
}
|
||||
|
||||
export type AdminProductCategoryListResponse = PaginatedResponse<{
|
||||
product_categories: ProductCategoryResponse[]
|
||||
}>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { AdminProduct } from "../../product"
|
||||
import { BaseProductCategory } from "../common"
|
||||
|
||||
export interface AdminProductCategory
|
||||
extends Omit<
|
||||
BaseProductCategory,
|
||||
"products" | "category_children" | "parent_category"
|
||||
> {
|
||||
category_children: AdminProductCategory[]
|
||||
parent_category: AdminProductCategory | null
|
||||
products?: AdminProduct[]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from "./entities"
|
||||
export * from "./payloads"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
@@ -0,0 +1,26 @@
|
||||
export interface AdminCreateProductCategory {
|
||||
name: string
|
||||
description?: string
|
||||
handle?: string
|
||||
is_internal?: boolean
|
||||
is_active?: boolean
|
||||
parent_category_id?: string
|
||||
rank?: number
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface AdminUpdateProductCategory {
|
||||
name?: string
|
||||
description?: string
|
||||
handle?: string
|
||||
is_internal?: boolean
|
||||
is_active?: boolean
|
||||
parent_category_id?: string | null
|
||||
rank?: number
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface AdminUpdateProductCategoryProducts {
|
||||
add?: string[]
|
||||
remove?: string[]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import {
|
||||
BaseProductCategoryListParams,
|
||||
BaseProductCategoryParams,
|
||||
} from "../common"
|
||||
|
||||
export interface AdminProductCategoryListParams
|
||||
extends BaseProductCategoryListParams {
|
||||
is_internal?: boolean
|
||||
is_active?: boolean
|
||||
}
|
||||
|
||||
export interface AdminProductCategoryParams extends BaseProductCategoryParams {}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
||||
import { AdminProductCategory } from "./entities"
|
||||
|
||||
export interface AdminProductCategoryResponse {
|
||||
product_category: AdminProductCategory
|
||||
}
|
||||
|
||||
export interface AdminProductCategoryListResponse
|
||||
extends PaginatedResponse<{
|
||||
product_categories: AdminProductCategory[]
|
||||
}> {}
|
||||
|
||||
export interface AdminProductCategoryDeleteResponse
|
||||
extends DeleteResponse<"product_category"> {}
|
||||
@@ -1,15 +1,43 @@
|
||||
export interface ProductCategoryResponse {
|
||||
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||
import { FindParams, SelectParams } from "../common"
|
||||
import { BaseProduct } from "../product/common"
|
||||
|
||||
export interface BaseProductCategory {
|
||||
id: string
|
||||
name: string
|
||||
description: string | null
|
||||
handle: string | null
|
||||
description: string
|
||||
handle: string
|
||||
is_active: boolean
|
||||
is_internal: boolean
|
||||
rank: number | null
|
||||
parent_category_id: string | null
|
||||
created_at: string | Date
|
||||
updated_at: string | Date
|
||||
parent_category: BaseProductCategory | null
|
||||
category_children: BaseProductCategory[]
|
||||
products?: BaseProduct[]
|
||||
created_at: string
|
||||
updated_at: string
|
||||
deleted_at: string | null
|
||||
}
|
||||
|
||||
parent_category: ProductCategoryResponse
|
||||
category_children: ProductCategoryResponse[]
|
||||
export interface BaseProductCategoryListParams
|
||||
extends FindParams,
|
||||
BaseFilterable<BaseProductCategoryListParams> {
|
||||
q?: string
|
||||
id?: string | string[]
|
||||
name?: string | string[]
|
||||
description?: string | string[]
|
||||
parent_category_id?: string | string[] | null
|
||||
handle?: string | string[]
|
||||
is_active?: boolean
|
||||
is_internal?: boolean
|
||||
include_descendants_tree?: boolean
|
||||
include_ancestors_tree?: boolean
|
||||
created_at?: OperatorMap<string>
|
||||
updated_at?: OperatorMap<string>
|
||||
deleted_at?: OperatorMap<string>
|
||||
}
|
||||
|
||||
export interface BaseProductCategoryParams extends SelectParams {
|
||||
include_ancestors_tree?: boolean
|
||||
include_descendants_tree?: boolean
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { PaginatedResponse } from "../common"
|
||||
import { ProductCategoryResponse } from "./common"
|
||||
|
||||
export interface StoreProductCategoryResponse {
|
||||
product_category: ProductCategoryResponse
|
||||
}
|
||||
|
||||
export type StoreProductCategoryListResponse = PaginatedResponse<{
|
||||
product_categories: ProductCategoryResponse[]
|
||||
}>
|
||||
@@ -0,0 +1,6 @@
|
||||
import { StoreProduct } from "../../product/store"
|
||||
import { BaseProductCategory } from "../common"
|
||||
|
||||
export interface StoreProductCategory extends BaseProductCategory {
|
||||
products?: StoreProduct[]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from "./entities"
|
||||
export * from "./queries"
|
||||
export * from "./responses"
|
||||
@@ -0,0 +1,9 @@
|
||||
import {
|
||||
BaseProductCategoryListParams,
|
||||
BaseProductCategoryParams,
|
||||
} from "../common"
|
||||
|
||||
export interface StoreProductCategoryListParams
|
||||
extends BaseProductCategoryListParams {}
|
||||
|
||||
export interface StoreProductCategoryParams extends BaseProductCategoryParams {}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { PaginatedResponse } from "../../common"
|
||||
import { StoreProductCategory } from "./entities"
|
||||
|
||||
export interface StoreProductCategoryResponse {
|
||||
product_category: StoreProductCategory
|
||||
}
|
||||
|
||||
export interface StoreProductCategoryListResponse
|
||||
extends PaginatedResponse<{
|
||||
product_categories: StoreProductCategory[]
|
||||
}> {}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { AdminPrice } from "../../pricing"
|
||||
import { AdminProductCategory } from "../../product-category"
|
||||
import { AdminSalesChannel } from "../../sales-channel"
|
||||
import {
|
||||
BaseProduct,
|
||||
BaseProductCategory,
|
||||
BaseProductImage,
|
||||
BaseProductOption,
|
||||
BaseProductOptionValue,
|
||||
@@ -12,10 +12,6 @@ import {
|
||||
ProductStatus,
|
||||
} from "../common"
|
||||
|
||||
export interface AdminProductCategory extends BaseProductCategory {
|
||||
is_active?: boolean
|
||||
is_internal?: boolean
|
||||
}
|
||||
export interface AdminProductVariant extends BaseProductVariant {
|
||||
prices: AdminPrice[] | null
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
BaseProductCategoryParams,
|
||||
BaseProductOptionParams,
|
||||
BaseProductParams,
|
||||
BaseProductTagParams,
|
||||
@@ -15,4 +14,3 @@ export interface AdminProductParams extends BaseProductParams {
|
||||
price_list_id?: string | string[]
|
||||
variants?: AdminProductVariantParams
|
||||
}
|
||||
export interface AdminProductCategoryParams extends BaseProductCategoryParams {}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { BaseFilterable, OperatorMap } from "../../dal"
|
||||
import { BaseCollection } from "../collection/common"
|
||||
import { FindParams } from "../common"
|
||||
import { BaseProductCategory } from "../product-category/common"
|
||||
|
||||
export type ProductStatus = "draft" | "proposed" | "published" | "rejected"
|
||||
export interface BaseProduct {
|
||||
@@ -64,21 +65,6 @@ export interface BaseProductVariant {
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
export interface BaseProductCategory {
|
||||
id: string
|
||||
name: string
|
||||
description: string | null
|
||||
handle: string
|
||||
rank?: number
|
||||
parent_category?: BaseProductCategory | null
|
||||
parent_category_id?: string | null
|
||||
category_children?: BaseProductCategory[]
|
||||
products?: BaseProduct[]
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
metadata?: Record<string, unknown> | null
|
||||
}
|
||||
|
||||
export interface BaseProductTag {
|
||||
id: string
|
||||
value: string
|
||||
@@ -183,17 +169,3 @@ export interface BaseProductVariantParams
|
||||
product_id?: string | string[]
|
||||
options?: Record<string, string>
|
||||
}
|
||||
|
||||
export interface BaseProductCategoryParams
|
||||
extends FindParams,
|
||||
BaseFilterable<BaseProductCategoryParams> {
|
||||
q?: string
|
||||
id?: string | string[]
|
||||
name?: string | string[]
|
||||
parent_category_id?: string | string[] | null
|
||||
handle?: string | string[]
|
||||
is_active?: boolean
|
||||
is_internal?: boolean
|
||||
include_descendants_tree?: boolean
|
||||
include_ancestors_tree?: boolean
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { StoreProductCategory } from "../../product-category"
|
||||
import {
|
||||
BaseProduct,
|
||||
BaseProductCategory,
|
||||
BaseProductImage,
|
||||
BaseProductOption,
|
||||
BaseProductOptionValue,
|
||||
@@ -10,8 +10,9 @@ import {
|
||||
ProductStatus,
|
||||
} from "../common"
|
||||
|
||||
export interface StoreProduct extends BaseProduct {}
|
||||
export interface StoreProductCategory extends BaseProductCategory {}
|
||||
export interface StoreProduct extends Omit<BaseProduct, "categories"> {
|
||||
categories?: StoreProductCategory[] | null
|
||||
}
|
||||
export interface StoreProductVariant extends BaseProductVariant {}
|
||||
export interface StoreProductTag extends BaseProductTag {}
|
||||
export interface StoreProductType extends BaseProductType {}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
BaseProductCategoryParams,
|
||||
BaseProductParams,
|
||||
BaseProductOptionParams,
|
||||
BaseProductParams,
|
||||
BaseProductTagParams,
|
||||
BaseProductTypeParams,
|
||||
BaseProductVariantParams,
|
||||
@@ -17,4 +16,3 @@ export interface StoreProductParams extends BaseProductParams {
|
||||
currency_code?: string
|
||||
variants?: StoreProductVariantParams
|
||||
}
|
||||
export interface StoreProductCategoryParams extends BaseProductCategoryParams {}
|
||||
Reference in new issue
Block a user