Skip to content

Commit

Permalink
fix merge of variables and input for datagrid filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
rdonigian committed Oct 31, 2024
1 parent 63809e2 commit 8efcaee
Showing 1 changed file with 5 additions and 34 deletions.
39 changes: 5 additions & 34 deletions src/components/Grid/useDataGridSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) => {
Expand All @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 8efcaee

Please sign in to comment.