Skip to content

Commit

Permalink
Merge branch 'develop' into fix/add-nostore-option-to-js-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl authored Oct 21, 2024
2 parents 3031f99 + 9f53683 commit 4d59580
Show file tree
Hide file tree
Showing 70 changed files with 486 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import { useState } from "react"
import { useTranslation } from "react-i18next"
import { useSearchParams } from "react-router-dom"

export type DataTableOrderByKey<TData> = {
key: keyof TData
label: string
}

type DataTableOrderByProps<TData> = {
keys: (keyof TData)[]
keys: DataTableOrderByKey<TData>[]
prefix?: string
}

Expand Down Expand Up @@ -38,18 +43,6 @@ const initState = (params: URLSearchParams, prefix?: string): SortState => {
}
}

const formatKey = (key: string) => {
const words = key.split("_")
const formattedWords = words.map((word, index) => {
if (index === 0) {
return word.charAt(0).toUpperCase() + word.slice(1)
} else {
return word
}
})
return formattedWords.join(" ")
}

export const DataTableOrderBy = <TData,>({
keys,
prefix,
Expand Down Expand Up @@ -116,15 +109,15 @@ export const DataTableOrderBy = <TData,>({
onValueChange={handleKeyChange}
>
{keys.map((key) => {
const stringKey = String(key)
const stringKey = String(key.key)

return (
<DropdownMenu.RadioItem
key={stringKey}
value={stringKey}
onSelect={(event) => event.preventDefault()}
>
{formatKey(stringKey)}
{key.label}
</DropdownMenu.RadioItem>
)
})}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Filter } from ".."
import { DataTableFilter } from "../data-table-filter"
import { DataTableOrderBy } from "../data-table-order-by"
import { DataTableOrderBy, DataTableOrderByKey } from "../data-table-order-by"
import { DataTableSearch } from "../data-table-search"

export interface DataTableQueryProps {
export interface DataTableQueryProps<TData> {
search?: boolean | "autofocus"
orderBy?: (string | number)[]
orderBy?: DataTableOrderByKey<TData>[]
filters?: Filter[]
prefix?: string
}

export const DataTableQuery = ({
export const DataTableQuery = <TData,>({
search,
orderBy,
filters,
prefix,
}: DataTableQueryProps) => {
}: DataTableQueryProps<TData>) => {
return (
(search || orderBy || filters || prefix) && (
<div className="flex items-start justify-between gap-x-4 px-6 py-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DataTableRoot, DataTableRootProps } from "./data-table-root"

interface DataTableProps<TData>
extends Omit<DataTableRootProps<TData>, "noResults">,
DataTableQueryProps {
DataTableQueryProps<TData> {
isLoading?: boolean
pageSize: number
queryObject?: Record<string, any>
Expand All @@ -16,7 +16,7 @@ interface DataTableProps<TData>

// Maybe we should use the memoized version of DataTableRoot
// const MemoizedDataTableRoot = memo(DataTableRoot) as typeof DataTableRoot
const MemoizedDataTableQuery = memo(DataTableQuery)
const MemoizedDataTableQuery = memo(DataTableQuery) as typeof DataTableQuery

export const DataTable = <TData,>({
table,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PromotionDTO } from "@medusajs/types"
import { HttpTypes } from "@medusajs/types"
import { useTranslation } from "react-i18next"
import {
getPromotionStatus,
Expand All @@ -7,7 +7,7 @@ import {
import { StatusCell as StatusCell_ } from "../../common/status-cell"

type PromotionCellProps = {
promotion: PromotionDTO
promotion: HttpTypes.AdminPromotion
}
type StatusColors = "grey" | "orange" | "green" | "red"
type StatusMap = Record<string, [StatusColors, string]>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PromotionDTO } from "@medusajs/types"
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
import { HttpTypes } from "@medusajs/types"
import { createColumnHelper } from "@tanstack/react-table"
import { useMemo } from "react"
import { useTranslation } from "react-i18next"

Expand All @@ -13,7 +13,7 @@ import {
} from "../../../components/table/table-cells/common/text-cell"
import { StatusCell } from "../../../components/table/table-cells/promotion/status-cell"

const columnHelper = createColumnHelper<PromotionDTO>()
const columnHelper = createColumnHelper<HttpTypes.AdminPromotion>()

export const usePromotionTableColumns = () => {
const { t } = useTranslation()
Expand Down Expand Up @@ -44,6 +44,6 @@ export const usePromotionTableColumns = () => {
cell: ({ row }) => <StatusCell promotion={row.original} />,
}),
],
[]
) as ColumnDef<PromotionDTO>[]
[t]
)
}
8 changes: 7 additions & 1 deletion packages/admin/dashboard/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,8 @@
"groups": "Groups"
},
"registered": "Registered",
"guest": "Guest"
"guest": "Guest",
"hasAccount": "Has account"
},
"customerGroups": {
"domain": "Customer Groups",
Expand Down Expand Up @@ -1268,6 +1269,11 @@
"confirmed": "Order edit #{{editId}} confirmed"
}
}
},
"fields": {
"displayId": "Display ID",
"refundableAmount": "Refundable amount",
"returnableQuantity": "Returnable quantity"
}
},
"draftOrders": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,20 @@ export const ApiKeySalesChannelSection = ({
isLoading={isLoading}
queryObject={raw}
navigateTo={(row) => `/settings/sales-channels/${row.id}`}
orderBy={["name", "created_at", "updated_at"]}
orderBy={[
{
key: "name",
label: t("fields.name"),
},
{
key: "created_at",
label: t("fields.createdAt"),
},
{
key: "updated_at",
label: t("fields.updatedAt"),
},
]}
commands={[
{
action: handleRemove,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ export const ApiKeyManagementListTable = ({
columns={columns}
count={count}
pageSize={PAGE_SIZE}
orderBy={["title", "created_at", "updated_at", "revoked_at"]}
orderBy={[
{ key: "title", label: t("fields.title") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
{ key: "revoked_at", label: t("fields.revokedAt") },
]}
navigateTo={(row) => row.id}
pagination
search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ export const ApiKeySalesChannelsForm = ({
search="autofocus"
isLoading={isLoading}
queryObject={raw}
orderBy={["name", "created_at", "updated_at"]}
orderBy={[
{ key: "name", label: t("fields.name") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
layout="fill"
noRecords={{
message: t(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod"
import { AdminCampaign, PromotionDTO } from "@medusajs/types"
import { AdminCampaign, HttpTypes } from "@medusajs/types"
import { Button, Checkbox, Hint, Tooltip, toast } from "@medusajs/ui"
import { keepPreviousData } from "@tanstack/react-query"
import {
Expand Down Expand Up @@ -131,7 +131,12 @@ export const AddCampaignPromotionsForm = ({
pageSize={PAGE_SIZE}
isLoading={isLoading}
filters={filters}
orderBy={["title", "status", "created_at", "updated_at"]}
orderBy={[
{ key: "code", label: t("fields.code") },
{ key: "type", label: t("fields.type") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
queryObject={raw}
layout="fill"
pagination
Expand All @@ -158,7 +163,7 @@ export const AddCampaignPromotionsForm = ({
)
}

const columnHelper = createColumnHelper<PromotionDTO>()
const columnHelper = createColumnHelper<HttpTypes.AdminPromotion>()

const useColumns = () => {
const base = usePromotionTableColumns()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ export const CampaignPromotionSection = ({
search
pagination
orderBy={[
"email",
"first_name",
"last_name",
"has_account",
"created_at",
"updated_at",
{ key: "code", label: t("fields.code") },
{ key: "type", label: t("fields.type") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
queryObject={raw}
commands={[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export const CampaignListTable = () => {
navigateTo={(row) => row.id}
isLoading={isLoading}
queryObject={raw}
orderBy={["name", "created_at", "updated_at"]}
orderBy={[
{ key: "name", label: t("fields.name") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
/>
</Container>
)
Expand Down Expand Up @@ -97,7 +101,9 @@ const CampaignActions = ({ campaign }: { campaign: AdminCampaign }) => {

await mutateAsync(undefined, {
onSuccess: () => {
toast.success(t("campaigns.toast.delete"))
toast.success(
t("campaigns.delete.successToast", { name: campaign.name })
)
},
onError: (e) => {
toast.error(e.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ export const CategoryProductSection = ({
table={table}
filters={filters}
columns={columns}
orderBy={["title", "created_at", "updated_at"]}
orderBy={[
{ key: "title", label: t("fields.title") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
pageSize={PAGE_SIZE}
count={count}
navigateTo={(row) => `/products/${row.id}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ export const EditCategoryProductsForm = ({
count={count}
queryObject={raw}
filters={filters}
orderBy={["title", "created_at", "updated_at"]}
orderBy={[
{ key: "title", label: t("fields.title") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
prefix={PREFIX}
isLoading={isPending}
layout="fill"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ export const AddProductsToCollectionForm = ({
count={count}
queryObject={raw}
filters={filters}
orderBy={["title", "created_at", "updated_at"]}
orderBy={[
{ key: "title", label: t("fields.title") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
prefix={PREFIX}
isLoading={isLoading}
layout="fill"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ export const CollectionProductSection = ({
count={count}
filters={filters}
isLoading={isLoading}
orderBy={["title", "created_at", "updated_at"]}
orderBy={[
{ key: "title", label: t("fields.title") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
queryObject={raw}
commands={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ export const CollectionListTable = () => {
pageSize={PAGE_SIZE}
count={count}
filters={filters}
orderBy={["title", "handle", "created_at", "updated_at"]}
orderBy={[
{ key: "title", label: t("fields.title") },
{ key: "handle", label: t("fields.handle") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
search
navigateTo={(row) => `/collections/${row.original.id}`}
queryObject={raw}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ export const AddCustomersForm = ({
count={count}
filters={filters}
orderBy={[
"email",
"first_name",
"last_name",
"has_account",
"created_at",
"updated_at",
{ key: "email", label: t("fields.email") },
{ key: "first_name", label: t("fields.firstName") },
{ key: "last_name", label: t("fields.lastName") },
{ key: "has_account", label: t("customers.hasAccount") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
isLoading={isLoading}
layout="fill"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ export const CustomerGroupCustomerSection = ({
search
pagination
orderBy={[
"email",
"first_name",
"last_name",
"has_account",
"created_at",
"updated_at",
{ key: "email", label: t("fields.email") },
{ key: "first_name", label: t("fields.firstName") },
{ key: "last_name", label: t("fields.lastName") },
{ key: "has_account", label: t("customers.hasAccount") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
queryObject={raw}
commands={[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export const CustomerGroupListTable = () => {
search
pagination
navigateTo={(row) => `/customer-groups/${row.original.id}`}
orderBy={["name", "created_at", "updated_at"]}
orderBy={[
{ key: "name", label: t("fields.name") },
{ key: "created_at", label: t("fields.createdAt") },
{ key: "updated_at", label: t("fields.updatedAt") },
]}
queryObject={raw}
isLoading={isLoading}
/>
Expand Down
Loading

0 comments on commit 4d59580

Please sign in to comment.