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:
1 parent
ef798160ea
commit
9f154c308e
2 files changed
+19
-19
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/dashboard": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(dashboard): Limit number of ids passed in tax region override queries to avoid PayloadTooLargeError
|
||||||
+14
-19
@@ -25,6 +25,7 @@ import { formatPercentage } from "../../../../../lib/percentage-helpers"
|
|||||||
import { TaxRateRuleReferenceType } from "../../constants"
|
import { TaxRateRuleReferenceType } from "../../constants"
|
||||||
import { useDeleteTaxRateAction } from "../../hooks"
|
import { useDeleteTaxRateAction } from "../../hooks"
|
||||||
import { useShippingOptions } from "../../../../../hooks/api"
|
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"> {
|
interface TaxOverrideCardProps extends ComponentPropsWithoutRef<"div"> {
|
||||||
taxRate: HttpTypes.AdminTaxRate
|
taxRate: HttpTypes.AdminTaxRate
|
||||||
@@ -279,8 +280,8 @@ const useReferenceValues = (
|
|||||||
} => {
|
} => {
|
||||||
const products = useProducts(
|
const products = useProducts(
|
||||||
{
|
{
|
||||||
id: ids,
|
id: ids.slice(0, DISPLAY_OVERRIDE_ITEMS_LIMIT),
|
||||||
limit: 10,
|
limit: DISPLAY_OVERRIDE_ITEMS_LIMIT,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: !!ids.length && type === TaxRateRuleReferenceType.PRODUCT,
|
enabled: !!ids.length && type === TaxRateRuleReferenceType.PRODUCT,
|
||||||
@@ -299,8 +300,8 @@ const useReferenceValues = (
|
|||||||
|
|
||||||
const productTypes = useProductTypes(
|
const productTypes = useProductTypes(
|
||||||
{
|
{
|
||||||
id: ids,
|
id: ids.slice(0, DISPLAY_OVERRIDE_ITEMS_LIMIT),
|
||||||
limit: 10,
|
limit: DISPLAY_OVERRIDE_ITEMS_LIMIT,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: !!ids.length && type === TaxRateRuleReferenceType.PRODUCT_TYPE,
|
enabled: !!ids.length && type === TaxRateRuleReferenceType.PRODUCT_TYPE,
|
||||||
@@ -309,8 +310,8 @@ const useReferenceValues = (
|
|||||||
|
|
||||||
const shippingOptions = useShippingOptions(
|
const shippingOptions = useShippingOptions(
|
||||||
{
|
{
|
||||||
id: ids,
|
id: ids.slice(0, DISPLAY_OVERRIDE_ITEMS_LIMIT),
|
||||||
limit: 10,
|
limit: DISPLAY_OVERRIDE_ITEMS_LIMIT,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled:
|
enabled:
|
||||||
@@ -337,16 +338,16 @@ const useReferenceValues = (
|
|||||||
// enabled: !!ids.length && type === TaxRateRuleReferenceType.CUSTOMER_GROUP,
|
// enabled: !!ids.length && type === TaxRateRuleReferenceType.CUSTOMER_GROUP,
|
||||||
// }
|
// }
|
||||||
// )
|
// )
|
||||||
|
const additionalCount =
|
||||||
|
ids.length > DISPLAY_OVERRIDE_ITEMS_LIMIT
|
||||||
|
? ids.length - DISPLAY_OVERRIDE_ITEMS_LIMIT
|
||||||
|
: 0
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TaxRateRuleReferenceType.PRODUCT:
|
case TaxRateRuleReferenceType.PRODUCT:
|
||||||
return {
|
return {
|
||||||
labels: products.products?.map((product) => product.title),
|
labels: products.products?.map((product) => product.title),
|
||||||
isPending: products.isPending,
|
isPending: products.isPending,
|
||||||
additional:
|
additional: additionalCount,
|
||||||
products.products && products.count
|
|
||||||
? products.count - products.products.length
|
|
||||||
: 0,
|
|
||||||
isError: products.isError,
|
isError: products.isError,
|
||||||
error: products.error,
|
error: products.error,
|
||||||
}
|
}
|
||||||
@@ -365,10 +366,7 @@ const useReferenceValues = (
|
|||||||
return {
|
return {
|
||||||
labels: productTypes.product_types?.map((type) => type.value),
|
labels: productTypes.product_types?.map((type) => type.value),
|
||||||
isPending: productTypes.isPending,
|
isPending: productTypes.isPending,
|
||||||
additional:
|
additional: additionalCount,
|
||||||
productTypes.product_types && productTypes.count
|
|
||||||
? productTypes.count - productTypes.product_types.length
|
|
||||||
: 0,
|
|
||||||
isError: productTypes.isError,
|
isError: productTypes.isError,
|
||||||
error: productTypes.error,
|
error: productTypes.error,
|
||||||
}
|
}
|
||||||
@@ -376,10 +374,7 @@ const useReferenceValues = (
|
|||||||
return {
|
return {
|
||||||
labels: shippingOptions.shipping_options?.map((option) => option.name),
|
labels: shippingOptions.shipping_options?.map((option) => option.name),
|
||||||
isPending: shippingOptions.isPending,
|
isPending: shippingOptions.isPending,
|
||||||
additional: shippingOptions.count
|
additional: additionalCount,
|
||||||
? shippingOptions.count -
|
|
||||||
(shippingOptions.shipping_options?.length || 0)
|
|
||||||
: 0,
|
|
||||||
isError: shippingOptions.isError,
|
isError: shippingOptions.isError,
|
||||||
error: shippingOptions.error,
|
error: shippingOptions.error,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user