fix(dashboard): export with filters not working (#13711)
* fix(dashboard): export with filters not working * page size * own cr * Create tiny-beans-poke.md
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/dashboard": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(dashboard): export with filters not working
|
||||||
@@ -4,6 +4,7 @@ import { Path, useLocation } from "react-router-dom"
|
|||||||
/**
|
/**
|
||||||
* Checks if the current location has a restore_params property.
|
* Checks if the current location has a restore_params property.
|
||||||
* If it does, it will return a new path with the params added to it.
|
* If it does, it will return a new path with the params added to it.
|
||||||
|
* Otherwise, it will check if the current location has search params and preserve them.
|
||||||
* Otherwise, it will return the previous path.
|
* Otherwise, it will return the previous path.
|
||||||
*
|
*
|
||||||
* This is useful if the modal needs to return to the original path, with
|
* This is useful if the modal needs to return to the original path, with
|
||||||
@@ -15,12 +16,17 @@ export const useStateAwareTo = (prev: string | Partial<Path>) => {
|
|||||||
const to = useMemo(() => {
|
const to = useMemo(() => {
|
||||||
const params = location.state?.restore_params
|
const params = location.state?.restore_params
|
||||||
|
|
||||||
if (!params) {
|
if (params) {
|
||||||
return prev
|
return `${prev}?${params.toString()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${prev}?${params.toString()}`
|
// If no restore_params in state, check if the current URL has search params
|
||||||
}, [location.state, prev])
|
if (location.search) {
|
||||||
|
return `${prev}${location.search}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return prev
|
||||||
|
}, [location.state, location.search, prev])
|
||||||
|
|
||||||
return to
|
return to
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { RouteDrawer, useRouteModal } from "../../../components/modals"
|
|||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { ExportFilters } from "./components/export-filters"
|
import { ExportFilters } from "./components/export-filters"
|
||||||
import { useExportProducts } from "../../../hooks/api"
|
import { useExportProducts } from "../../../hooks/api"
|
||||||
|
import { useProductTableQuery } from "../../../hooks/table/query"
|
||||||
|
|
||||||
export const ProductExport = () => {
|
export const ProductExport = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@@ -24,24 +25,23 @@ export const ProductExport = () => {
|
|||||||
|
|
||||||
const ProductExportContent = () => {
|
const ProductExportContent = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { mutateAsync } = useExportProducts()
|
const { searchParams } = useProductTableQuery({})
|
||||||
|
|
||||||
|
const { mutateAsync } = useExportProducts({ ...searchParams })
|
||||||
const { handleSuccess } = useRouteModal()
|
const { handleSuccess } = useRouteModal()
|
||||||
|
|
||||||
const handleExportRequest = async () => {
|
const handleExportRequest = async () => {
|
||||||
await mutateAsync(
|
await mutateAsync(searchParams, {
|
||||||
{},
|
onSuccess: () => {
|
||||||
{
|
toast.info(t("products.export.success.title"), {
|
||||||
onSuccess: () => {
|
description: t("products.export.success.description"),
|
||||||
toast.info(t("products.export.success.title"), {
|
})
|
||||||
description: t("products.export.success.description"),
|
handleSuccess()
|
||||||
})
|
},
|
||||||
handleSuccess()
|
onError: (err) => {
|
||||||
},
|
toast.error(err.message)
|
||||||
onError: (err) => {
|
},
|
||||||
toast.error(err.message)
|
})
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
+3
-3
@@ -16,11 +16,11 @@ export const ConfigurableProductListTable = () => {
|
|||||||
heading={t("products.domain")}
|
heading={t("products.domain")}
|
||||||
actions={[
|
actions={[
|
||||||
{ label: t("actions.export"), to: `export${location.search}` },
|
{ label: t("actions.export"), to: `export${location.search}` },
|
||||||
{ label: t("actions.import"), to: "import" },
|
{ label: t("actions.import"), to: `import${location.search}` },
|
||||||
{ label: t("actions.create"), to: "create" }
|
{ label: t("actions.create"), to: "create" },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -74,7 +74,7 @@ export const ProductListTable = () => {
|
|||||||
<Link to={`export${location.search}`}>{t("actions.export")}</Link>
|
<Link to={`export${location.search}`}>{t("actions.export")}</Link>
|
||||||
</Button>
|
</Button>
|
||||||
<Button size="small" variant="secondary" asChild>
|
<Button size="small" variant="secondary" asChild>
|
||||||
<Link to="import">{t("actions.import")}</Link>
|
<Link to={`import${location.search}`}>{t("actions.import")}</Link>
|
||||||
</Button>
|
</Button>
|
||||||
<Button size="small" variant="secondary" asChild>
|
<Button size="small" variant="secondary" asChild>
|
||||||
<Link to="create">{t("actions.create")}</Link>
|
<Link to="create">{t("actions.create")}</Link>
|
||||||
|
|||||||
Reference in New Issue
Block a user