fix(dashboard): tax region override too large payload (#13860)
* Limit the number of ids passed to the different queries to render the tooltip details to 10, for products, product types and shipping options * Add changeset * Extract common additional field computation into variable
This commit is contained in:
5
.changeset/breezy-walls-film.md
Normal file
5
.changeset/breezy-walls-film.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/dashboard": patch
|
||||
---
|
||||
|
||||
fix(dashboard): Limit number of ids passed in tax region override queries to avoid PayloadTooLargeError
|
||||
@@ -25,6 +25,7 @@ import { formatPercentage } from "../../../../../lib/percentage-helpers"
|
||||
import { TaxRateRuleReferenceType } from "../../constants"
|
||||
import { useDeleteTaxRateAction } from "../../hooks"
|
||||
import { useShippingOptions } from "../../../../../hooks/api"
|
||||
import { DISPLAY_OVERRIDE_ITEMS_LIMIT } from "../../../tax-region-tax-override-edit/components/tax-region-tax-override-edit-form"
|
||||
|
||||
interface TaxOverrideCardProps extends ComponentPropsWithoutRef<"div"> {
|
||||
taxRate: HttpTypes.AdminTaxRate
|
||||
@@ -279,8 +280,8 @@ const useReferenceValues = (
|
||||
} => {
|
||||
const products = useProducts(
|
||||
{
|
||||
id: ids,
|
||||
limit: 10,
|
||||
id: ids.slice(0, DISPLAY_OVERRIDE_ITEMS_LIMIT),
|
||||
limit: DISPLAY_OVERRIDE_ITEMS_LIMIT,
|
||||
},
|
||||
{
|
||||
enabled: !!ids.length && type === TaxRateRuleReferenceType.PRODUCT,
|
||||
@@ -299,8 +300,8 @@ const useReferenceValues = (
|
||||
|
||||
const productTypes = useProductTypes(
|
||||
{
|
||||
id: ids,
|
||||
limit: 10,
|
||||
id: ids.slice(0, DISPLAY_OVERRIDE_ITEMS_LIMIT),
|
||||
limit: DISPLAY_OVERRIDE_ITEMS_LIMIT,
|
||||
},
|
||||
{
|
||||
enabled: !!ids.length && type === TaxRateRuleReferenceType.PRODUCT_TYPE,
|
||||
@@ -309,8 +310,8 @@ const useReferenceValues = (
|
||||
|
||||
const shippingOptions = useShippingOptions(
|
||||
{
|
||||
id: ids,
|
||||
limit: 10,
|
||||
id: ids.slice(0, DISPLAY_OVERRIDE_ITEMS_LIMIT),
|
||||
limit: DISPLAY_OVERRIDE_ITEMS_LIMIT,
|
||||
},
|
||||
{
|
||||
enabled:
|
||||
@@ -337,16 +338,16 @@ const useReferenceValues = (
|
||||
// enabled: !!ids.length && type === TaxRateRuleReferenceType.CUSTOMER_GROUP,
|
||||
// }
|
||||
// )
|
||||
|
||||
const additionalCount =
|
||||
ids.length > DISPLAY_OVERRIDE_ITEMS_LIMIT
|
||||
? ids.length - DISPLAY_OVERRIDE_ITEMS_LIMIT
|
||||
: 0
|
||||
switch (type) {
|
||||
case TaxRateRuleReferenceType.PRODUCT:
|
||||
return {
|
||||
labels: products.products?.map((product) => product.title),
|
||||
isPending: products.isPending,
|
||||
additional:
|
||||
products.products && products.count
|
||||
? products.count - products.products.length
|
||||
: 0,
|
||||
additional: additionalCount,
|
||||
isError: products.isError,
|
||||
error: products.error,
|
||||
}
|
||||
@@ -365,10 +366,7 @@ const useReferenceValues = (
|
||||
return {
|
||||
labels: productTypes.product_types?.map((type) => type.value),
|
||||
isPending: productTypes.isPending,
|
||||
additional:
|
||||
productTypes.product_types && productTypes.count
|
||||
? productTypes.count - productTypes.product_types.length
|
||||
: 0,
|
||||
additional: additionalCount,
|
||||
isError: productTypes.isError,
|
||||
error: productTypes.error,
|
||||
}
|
||||
@@ -376,10 +374,7 @@ const useReferenceValues = (
|
||||
return {
|
||||
labels: shippingOptions.shipping_options?.map((option) => option.name),
|
||||
isPending: shippingOptions.isPending,
|
||||
additional: shippingOptions.count
|
||||
? shippingOptions.count -
|
||||
(shippingOptions.shipping_options?.length || 0)
|
||||
: 0,
|
||||
additional: additionalCount,
|
||||
isError: shippingOptions.isError,
|
||||
error: shippingOptions.error,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user