fix(dashboard): product create - ignored variants in datagrid (#9087)
* wip: fix mismatch in indexes * fix: refactor
This commit is contained in:
1 parent
24704f420a
commit
42cedd073b
1 file changed
+23
-11
+23
-11
@@ -57,10 +57,17 @@ export const ProductCreateVariantsForm = ({
|
|||||||
pricePreferences,
|
pricePreferences,
|
||||||
})
|
})
|
||||||
|
|
||||||
const variantData = useMemo(
|
const variantData = useMemo(() => {
|
||||||
() => variants.filter((v) => v.should_create),
|
const ret = []
|
||||||
[variants]
|
|
||||||
)
|
variants.forEach((v, i) => {
|
||||||
|
if (v.should_create) {
|
||||||
|
ret.push({ ...v, originalIndex: i })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}, [variants])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex size-full flex-col divide-y overflow-hidden">
|
<div className="flex size-full flex-col divide-y overflow-hidden">
|
||||||
@@ -118,7 +125,8 @@ const useColumns = ({
|
|||||||
id: "title",
|
id: "title",
|
||||||
name: t("fields.title"),
|
name: t("fields.title"),
|
||||||
header: t("fields.title"),
|
header: t("fields.title"),
|
||||||
field: (context) => `variants.${context.row.index}.title`,
|
field: (context) =>
|
||||||
|
`variants.${context.row.original.originalIndex}.title`,
|
||||||
type: "text",
|
type: "text",
|
||||||
cell: (context) => {
|
cell: (context) => {
|
||||||
return <DataGrid.TextCell context={context} />
|
return <DataGrid.TextCell context={context} />
|
||||||
@@ -128,7 +136,8 @@ const useColumns = ({
|
|||||||
id: "sku",
|
id: "sku",
|
||||||
name: t("fields.sku"),
|
name: t("fields.sku"),
|
||||||
header: t("fields.sku"),
|
header: t("fields.sku"),
|
||||||
field: (context) => `variants.${context.row.index}.sku`,
|
field: (context) =>
|
||||||
|
`variants.${context.row.original.originalIndex}.sku`,
|
||||||
type: "text",
|
type: "text",
|
||||||
cell: (context) => {
|
cell: (context) => {
|
||||||
return <DataGrid.TextCell context={context} />
|
return <DataGrid.TextCell context={context} />
|
||||||
@@ -138,7 +147,8 @@ const useColumns = ({
|
|||||||
id: "manage_inventory",
|
id: "manage_inventory",
|
||||||
name: t("fields.managedInventory"),
|
name: t("fields.managedInventory"),
|
||||||
header: t("fields.managedInventory"),
|
header: t("fields.managedInventory"),
|
||||||
field: (context) => `variants.${context.row.index}.manage_inventory`,
|
field: (context) =>
|
||||||
|
`variants.${context.row.original.originalIndex}.manage_inventory`,
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
cell: (context) => {
|
cell: (context) => {
|
||||||
return <DataGrid.BooleanCell context={context} />
|
return <DataGrid.BooleanCell context={context} />
|
||||||
@@ -148,7 +158,8 @@ const useColumns = ({
|
|||||||
id: "allow_backorder",
|
id: "allow_backorder",
|
||||||
name: t("fields.allowBackorder"),
|
name: t("fields.allowBackorder"),
|
||||||
header: t("fields.allowBackorder"),
|
header: t("fields.allowBackorder"),
|
||||||
field: (context) => `variants.${context.row.index}.allow_backorder`,
|
field: (context) =>
|
||||||
|
`variants.${context.row.original.originalIndex}.allow_backorder`,
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
cell: (context) => {
|
cell: (context) => {
|
||||||
return <DataGrid.BooleanCell context={context} />
|
return <DataGrid.BooleanCell context={context} />
|
||||||
@@ -159,7 +170,8 @@ const useColumns = ({
|
|||||||
id: "inventory_kit",
|
id: "inventory_kit",
|
||||||
name: t("fields.inventoryKit"),
|
name: t("fields.inventoryKit"),
|
||||||
header: t("fields.inventoryKit"),
|
header: t("fields.inventoryKit"),
|
||||||
field: (context) => `variants.${context.row.index}.inventory_kit`,
|
field: (context) =>
|
||||||
|
`variants.${context.row.original.originalIndex}.inventory_kit`,
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
cell: (context) => {
|
cell: (context) => {
|
||||||
return (
|
return (
|
||||||
@@ -180,9 +192,9 @@ const useColumns = ({
|
|||||||
pricePreferences,
|
pricePreferences,
|
||||||
getFieldName: (context, value) => {
|
getFieldName: (context, value) => {
|
||||||
if (context.column.id?.startsWith("currency_prices")) {
|
if (context.column.id?.startsWith("currency_prices")) {
|
||||||
return `variants.${context.row.index}.prices.${value}`
|
return `variants.${context.row.original.originalIndex}.prices.${value}`
|
||||||
}
|
}
|
||||||
return `variants.${context.row.index}.prices.${value}`
|
return `variants.${context.row.original.originalIndex}.prices.${value}`
|
||||||
},
|
},
|
||||||
t,
|
t,
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in new issue
Block a user