Skip to content

Commit ad564ae

Browse files
authored
Allow passing filters to object count query in UI (#6514)
1 parent 6f8253c commit ad564ae

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

changelog/object-count.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
On object list views, The number of objects now changes when you apply filters in list views.

frontend/app/src/entities/nodes/object-header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const ObjectItemsHeader = ({ schema }: ObjectHeaderProps) => {
2929
isPending,
3030
isRefetching,
3131
isError,
32-
} = useObjectsCount({ schemaKind: schema.kind as string, filters });
32+
} = useObjectsCount({ objectKind: schema.kind as string, filters });
3333

3434
const refetchObjects = () => {
3535
queryClient.invalidateQueries({
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import graphqlClient from "@/shared/api/graphql/graphqlClientApollo";
2+
import { addFiltersToRequest } from "@/shared/api/graphql/utils";
23
import { ContextParams } from "@/shared/api/types";
4+
import { Filter } from "@/shared/hooks/useFilters";
35
import { gql } from "@apollo/client";
46
import { jsonToGraphQLQuery } from "json-to-graphql-query";
57

6-
const getObjectsCountQuery = (kind: string) => {
8+
export interface getObjectsCountQueryParams {
9+
objectKind: string;
10+
filters?: Array<Filter>;
11+
}
12+
13+
const getObjectsCountQuery = ({ objectKind, filters }: getObjectsCountQueryParams) => {
714
const query = {
815
query: {
9-
__name: `GetObjectsCount${kind}`,
10-
[kind]: {
16+
__name: `GetObjectsCount${objectKind}`,
17+
[objectKind]: {
18+
__args: {
19+
...(filters ? addFiltersToRequest(filters) : {}),
20+
},
1121
count: true,
1222
},
1323
},
@@ -16,18 +26,24 @@ const getObjectsCountQuery = (kind: string) => {
1626
return gql(jsonToGraphQLQuery(query));
1727
};
1828

19-
export type GetObjectsCountFromApiParams = ContextParams & { schemaKind: string };
29+
export interface GetObjectsCountFromApiParams extends ContextParams {
30+
objectKind: string;
31+
filters?: Array<Filter>;
32+
}
2033

2134
export const getObjectsCountFromApi = async ({
22-
schemaKind,
35+
objectKind,
36+
filters,
2337
branchName,
2438
atDate,
2539
}: GetObjectsCountFromApiParams) => {
2640
return graphqlClient.query({
27-
query: getObjectsCountQuery(schemaKind),
41+
query: getObjectsCountQuery({ objectKind, filters }),
2842
context: {
2943
branch: branchName,
3044
date: atDate,
45+
queryDeduplication: false,
46+
processErrorMessage: () => {},
3147
},
3248
});
3349
};

frontend/app/src/entities/nodes/object/domain/get-objects-count.query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import { useAtomValue } from "jotai";
55
import { GetObjectsCountParams, getObjectsCount } from "./get-objects-count";
66

77
export function getObjectsCountQueryOptions({
8-
schemaKind,
8+
objectKind,
99
filters,
1010
branchName,
1111
atDate,
1212
}: GetObjectsCountParams) {
1313
return queryOptions({
14-
queryKey: [branchName, atDate, "objects", schemaKind, "count", JSON.stringify(filters)],
14+
queryKey: [branchName, atDate, "objects", objectKind, "count", JSON.stringify(filters)],
1515
queryFn: async () => {
1616
return getObjectsCount({
17-
schemaKind,
17+
objectKind,
1818
branchName,
1919
atDate,
2020
filters,
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
import { getObjectsCountFromApi } from "@/entities/nodes/object/api/get-objects-count-from-api";
2-
import { ContextParams } from "@/shared/api/types";
3-
import { Filter } from "@/shared/hooks/useFilters";
1+
import {
2+
GetObjectsCountFromApiParams,
3+
getObjectsCountFromApi,
4+
} from "@/entities/nodes/object/api/get-objects-count-from-api";
45

5-
export type GetObjectsCountParams = ContextParams & {
6-
schemaKind: string;
7-
filters?: Array<Filter>;
8-
};
6+
export type GetObjectsCountParams = GetObjectsCountFromApiParams;
97

108
export type GetObjectsCount = (args: GetObjectsCountParams) => Promise<number>;
119

1210
export const getObjectsCount: GetObjectsCount = async ({
13-
schemaKind,
11+
objectKind,
1412
branchName,
1513
atDate,
1614
filters = [],
1715
}) => {
1816
const kindFilter = filters?.find((filter) => filter.name === "kind__value");
19-
const schemaKindToQuery: string = kindFilter?.value ?? schemaKind;
17+
const schemaKindToQuery: string = kindFilter?.value ?? objectKind;
2018

21-
const { data } = await getObjectsCountFromApi({
22-
schemaKind: schemaKindToQuery,
19+
const { data, errors } = await getObjectsCountFromApi({
20+
objectKind: schemaKindToQuery,
2321
branchName,
2422
atDate,
23+
filters,
2524
});
2625

26+
if (errors?.[0]?.message) {
27+
throw new Error(errors[0].message);
28+
}
29+
2730
return data[schemaKindToQuery].count;
2831
};

0 commit comments

Comments
 (0)