From 887677140dc953e0aa11a673087c1e2d79f9b12e Mon Sep 17 00:00:00 2001 From: rdonigian <167127316+rdonigian@users.noreply.github.com> Date: Thu, 31 Oct 2024 10:35:46 -0400 Subject: [PATCH] Deep merge User & System Filters for DataGrid (#1616) Co-authored-by: Carson Full Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- 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..cb6486f03 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) => {