From 8efcaee292542ba9f6f4a36df11d17d2d6df4954 Mon Sep 17 00:00:00 2001 From: Rob Donigian Date: Thu, 31 Oct 2024 10:20:29 -0400 Subject: [PATCH 1/2] fix merge of variables and input for datagrid filtering --- src/components/Grid/useDataGridSource.tsx | 39 +++-------------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/src/components/Grid/useDataGridSource.tsx b/src/components/Grid/useDataGridSource.tsx index 011183146..7a531e88f 100644 --- a/src/components/Grid/useDataGridSource.tsx +++ b/src/components/Grid/useDataGridSource.tsx @@ -33,7 +33,7 @@ import { OperationDefinitionNode, type SelectionSetNode, } from 'graphql'; -import { get, pick, set, uniqBy } from 'lodash'; +import { get, merge, pick, set, uniqBy } from 'lodash'; import { MutableRefObject, useEffect, useMemo, useState } from 'react'; import type { Get, Paths, SetNonNullable } from 'type-fest'; import { type PaginatedListInput, type SortableListInput } from '~/api'; @@ -275,17 +275,8 @@ export const useDataGridSource = < ); const variablesWithFilter = useMemo(() => { const { count, sort, order, ...rest } = input; - return { - ...variables, - input: { - ...rest, - ...variables.input, - filter: { - ...rest.filter, - ...variables.input?.filter, - }, - }, - }; + + return merge({}, variables, { input: rest }); }, [variables, input]); const addToAllPagesCache = (next: Output) => { @@ -309,18 +300,7 @@ export const useDataGridSource = < const { data: firstPage, loading } = useQuery(query, { skip: isCacheComplete, variables: useMemo( - () => ({ - ...variables, - input: { - ...input, - page: 1, - ...variables.input, - filter: { - ...input.filter, - ...variables.input?.filter, - }, - }, - }), + () => merge({}, variables, { input }, { input: { page: 1 } }), [variables, input] ), onCompleted: addToAllPagesCache, @@ -361,16 +341,7 @@ export const useDataGridSource = < .query({ query, variables: { - ...variables, - input: { - ...input, - page, - ...variables.input, - filter: { - ...input.filter, - ...variables.input?.filter, - }, - }, + ...merge({}, variables, input, { input: page }), }, }) .then((res) => { From f5b103935ae7800b964cdbbd6ae5fb72d20d40a0 Mon Sep 17 00:00:00 2001 From: Carson Full Date: Thu, 31 Oct 2024 09:32:51 -0500 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/components/Grid/useDataGridSource.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Grid/useDataGridSource.tsx b/src/components/Grid/useDataGridSource.tsx index 7a531e88f..cb6486f03 100644 --- a/src/components/Grid/useDataGridSource.tsx +++ b/src/components/Grid/useDataGridSource.tsx @@ -300,7 +300,7 @@ export const useDataGridSource = < const { data: firstPage, loading } = useQuery(query, { skip: isCacheComplete, variables: useMemo( - () => merge({}, variables, { input }, { input: { page: 1 } }), + () => merge({}, variables, { input: { ...input, page: 1 } }), [variables, input] ), onCompleted: addToAllPagesCache, @@ -341,7 +341,7 @@ export const useDataGridSource = < .query({ query, variables: { - ...merge({}, variables, input, { input: page }), + ...merge({}, variables, { input: { ...input, page } }), }, }) .then((res) => {