Skip to content

Commit

Permalink
fix(dashboard): Add Breadcrumb components
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperkristensen committed Nov 13, 2024
1 parent 89e26ac commit c3b1e21
Show file tree
Hide file tree
Showing 83 changed files with 1,137 additions and 319 deletions.
1 change: 1 addition & 0 deletions packages/admin/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@medusajs/ui": "4.0.1",
"@radix-ui/react-collapsible": "1.1.0",
"@tanstack/react-query": "^5.28.14",
"@tanstack/react-query-devtools": "^5.59.20",
"@tanstack/react-table": "8.20.5",
"@tanstack/react-virtual": "^3.8.3",
"@uiw/react-json-view": "^2.0.0-alpha.17",
Expand Down
14 changes: 8 additions & 6 deletions packages/admin/dashboard/src/components/layout/shell/shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Dialog from "@radix-ui/react-dialog"

import { SidebarLeft, TriangleRightMini, XMark } from "@medusajs/icons"
import { IconButton, clx } from "@medusajs/ui"
import { PropsWithChildren } from "react"
import { PropsWithChildren, ReactNode } from "react"
import { useTranslation } from "react-i18next"
import { Link, Outlet, UIMatch, useMatches } from "react-router-dom"

Expand Down Expand Up @@ -45,18 +45,20 @@ const Gutter = ({ children }: PropsWithChildren) => {
const Breadcrumbs = () => {
const matches = useMatches() as unknown as UIMatch<
unknown,
{ crumb?: (data?: unknown) => string }
{
breadcrumb?: (match?: UIMatch) => string | ReactNode
}
>[]

const crumbs = matches
.filter((match) => Boolean(match.handle?.crumb))
.filter((match) => match.handle?.breadcrumb)
.map((match) => {
const handle = match.handle

let label: string | null = null
let label: string | ReactNode | undefined = undefined

try {
label = handle.crumb!(match.data)
label = handle.breadcrumb?.(match)
} catch (error) {
// noop
}
Expand All @@ -70,7 +72,7 @@ const Breadcrumbs = () => {
path: match.pathname,
}
})
.filter(Boolean) as { label: string; path: string }[]
.filter(Boolean) as { label: string | ReactNode; path: string }[]

return (
<ol
Expand Down
17 changes: 13 additions & 4 deletions packages/admin/dashboard/src/hooks/api/products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ export const useProduct = (
id: string,
query?: Record<string, any>,
options?: Omit<
UseQueryOptions<any, FetchError, any, QueryKey>,
UseQueryOptions<
HttpTypes.AdminProductResponse,
FetchError,
HttpTypes.AdminProductResponse,
QueryKey
>,
"queryFn" | "queryKey"
>
) => {
Expand Down Expand Up @@ -302,9 +307,13 @@ export const useUpdateProduct = (
) => {
return useMutation({
mutationFn: (payload) => sdk.admin.product.update(id, payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({ queryKey: productsQueryKeys.lists() })
queryClient.invalidateQueries({ queryKey: productsQueryKeys.detail(id) })
onSuccess: async (data, variables, context) => {
await queryClient.invalidateQueries({
queryKey: productsQueryKeys.lists(),
})
await queryClient.invalidateQueries({
queryKey: productsQueryKeys.detail(id),
})

options?.onSuccess?.(data, variables, context)
},
Expand Down
13 changes: 8 additions & 5 deletions packages/admin/dashboard/src/hooks/api/shipping-profiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ export const useCreateShippingProfile = (
export const useShippingProfile = (
id: string,
query?: Record<string, any>,
options?: UseQueryOptions<
HttpTypes.AdminShippingProfileResponse,
FetchError,
HttpTypes.AdminShippingProfileResponse,
QueryKey
options?: Omit<
UseQueryOptions<
HttpTypes.AdminShippingProfileResponse,
FetchError,
HttpTypes.AdminShippingProfileResponse,
QueryKey
>,
"queryFn" | "queryKey"
>
) => {
const { data, ...rest } = useQuery({
Expand Down
3 changes: 2 additions & 1 deletion packages/admin/dashboard/src/providers/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Toaster, TooltipProvider } from "@medusajs/ui"
import { QueryClientProvider } from "@tanstack/react-query"
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"
import type { PropsWithChildren } from "react"
import { HelmetProvider } from "react-helmet-async"

import { I18n } from "../components/utilities/i18n"
import {
DashboardExtensionManager,
Expand All @@ -27,6 +27,7 @@ export const Providers = ({ api, children }: ProvidersProps) => {
<I18nProvider>{children}</I18nProvider>
<Toaster />
</ThemeProvider>
<ReactQueryDevtools initialIsOpen={false} position="bottom" />
</QueryClientProvider>
</HelmetProvider>
</DashboardExtensionProvider>
Expand Down
Loading

0 comments on commit c3b1e21

Please sign in to comment.