Преглед изворни кода

fix(dashboard): Fix tax rate faceted filtering

Michael Bromley пре 3 месеци
родитељ
комит
341085cf7b

+ 21 - 0
packages/dashboard/src/app/common/map-faceted-filter-fields.ts

@@ -0,0 +1,21 @@
+/**
+ * Maps filter fields to their corresponding ID fields in faceted filters.
+ * For example, transforms { category: '5' } to { categoryId: { eq: '5' } }
+ *
+ * @param facetedFilters - Array of filter objects to transform
+ * @param fieldMapping - Record mapping source field names to target field names
+ */
+export function mapFacetedFilterFields(
+    facetedFilters: Array<Record<string, any>>,
+    fieldMapping: Record<string, string>,
+) {
+    for (const [index, filter] of Object.entries(facetedFilters)) {
+        for (const [sourceField, targetField] of Object.entries(fieldMapping)) {
+            if (filter[sourceField]) {
+                facetedFilters[index as unknown as number] = {
+                    [targetField]: filter[sourceField],
+                };
+            }
+        }
+    }
+}

+ 9 - 0
packages/dashboard/src/app/routes/_authenticated/_tax-rates/tax-rates.tsx

@@ -8,6 +8,7 @@ import { api } from '@/vdb/graphql/api.js';
 import { Trans, useLingui } from '@lingui/react/macro';
 import { createFileRoute, Link } from '@tanstack/react-router';
 import { PlusIcon } from 'lucide-react';
+import { mapFacetedFilterFields } from '../../../common/map-faceted-filter-fields.js';
 import { taxCategoryListQuery } from '../_tax-categories/tax-categories.graphql.js';
 import { zoneListQuery } from '../_zones/zones.graphql.js';
 import { DeleteTaxRatesBulkAction } from './components/tax-rate-bulk-actions.js';
@@ -42,6 +43,14 @@ function TaxRateListPage() {
                     name: { contains: searchTerm },
                 };
             }}
+            transformVariables={input => {
+                const facetedFilters = input.options?.filter?._and ?? [];
+                mapFacetedFilterFields(facetedFilters, {
+                    category: 'categoryId',
+                    zone: 'zoneId',
+                });
+                return input;
+            }}
             facetedFilters={{
                 enabled: {
                     title: t`Enabled`,