Skip to content

Commit 5e3cafb

Browse files
authored
Allow passing any filter to relationship combobox list (#5977)
1 parent 9d97cac commit 5e3cafb

File tree

8 files changed

+56
-36
lines changed

8 files changed

+56
-36
lines changed

frontend/app/src/entities/nodes/api/generateRelationshipListQuery.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import { PaginationParams } from "@/shared/api/types";
22
import { jsonToGraphQLQuery } from "json-to-graphql-query";
33

4+
export type GenerateRelationshipListQueryParams = PaginationParams & {
5+
peer: string;
6+
parent?: { name: string; value: string };
7+
search?: string;
8+
filterQuery?: Record<string, string | number | boolean | string[]>;
9+
};
10+
411
export const generateRelationshipListQuery = ({
512
peer,
613
parent,
714
limit = 0,
815
offset = 0,
916
search = "",
10-
}: PaginationParams & {
11-
peer: string;
12-
parent?: { name?: string; value?: string };
13-
search?: string;
14-
}): string => {
17+
filterQuery = {},
18+
}: GenerateRelationshipListQueryParams): string => {
1519
const defaultArgs = { limit, offset, any__value: search, partial_match: true };
1620

1721
const args = parent?.value
@@ -24,6 +28,7 @@ export const generateRelationshipListQuery = ({
2428
[peer]: {
2529
__args: {
2630
...args,
31+
...filterQuery,
2732
},
2833
count: true,
2934
edges: {

frontend/app/src/entities/nodes/relationships/api/get-relationships-from-api.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { generateRelationshipListQuery } from "@/entities/nodes/api/generateRelationshipListQuery";
1+
import {
2+
GenerateRelationshipListQueryParams,
3+
generateRelationshipListQuery,
4+
} from "@/entities/nodes/api/generateRelationshipListQuery";
25
import graphqlClient from "@/shared/api/graphql/graphqlClientApollo";
3-
import { ContextParams, PaginationParams } from "@/shared/api/types";
6+
import { ContextParams } from "@/shared/api/types";
47
import { gql } from "@apollo/client";
58

69
export type getRelationshipsFromApiParams = ContextParams &
7-
PaginationParams & {
8-
peer: string;
9-
search?: string;
10-
parent?: { name: string; value: string };
11-
};
10+
Omit<GenerateRelationshipListQueryParams, "parent">;
1211

1312
export const getRelationshipsFromApi = async ({
1413
peer,
@@ -17,9 +16,9 @@ export const getRelationshipsFromApi = async ({
1716
search,
1817
branchName,
1918
atDate,
20-
parent,
19+
filterQuery,
2120
}: getRelationshipsFromApiParams) => {
22-
const query = gql(generateRelationshipListQuery({ peer, limit, offset, search, parent }));
21+
const query = gql(generateRelationshipListQuery({ peer, limit, offset, search, filterQuery }));
2322

2423
return graphqlClient.query({
2524
query,

frontend/app/src/entities/nodes/relationships/domain/get-relationships/get-relationships.query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ export type GetRelationshipsQueryParams = Omit<GetRelationshipsParams, keyof Pag
1414
export function getRelationshipsInfiniteQueryOptions({
1515
peer,
1616
search,
17-
parentId,
1817
branchName,
1918
atDate,
19+
filterQuery,
2020
}: GetRelationshipsQueryParams) {
2121
return infiniteQueryOptions({
22-
queryKey: [branchName, atDate, "relationships", peer, search, parentId],
22+
queryKey: [branchName, atDate, "relationships", peer, search, filterQuery],
2323
queryFn: ({ pageParam }) => {
24-
return getRelationships({ peer, offset: pageParam, search, parentId, branchName, atDate });
24+
return getRelationships({ peer, offset: pageParam, search, filterQuery, branchName, atDate });
2525
},
2626
initialPageParam: 0,
2727
getNextPageParam: (lastPage, _, lastPageParam) => {

frontend/app/src/entities/nodes/relationships/domain/get-relationships/get-relationships.test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ describe("getRelationships", () => {
3838
vi.mocked(getRelationshipsFromApi).mockResolvedValue(mockResponse);
3939

4040
// WHEN
41-
const result = await getRelationships({ peer, offset, search, parentId, branchName, atDate });
41+
const result = await getRelationships({
42+
peer,
43+
offset,
44+
search,
45+
filterQuery: {
46+
parent__ids: [parentId],
47+
},
48+
branchName,
49+
atDate,
50+
});
4251

4352
// THEN
4453
expect(getRelationshipsFromApi).toHaveBeenCalledWith({
@@ -48,7 +57,9 @@ describe("getRelationships", () => {
4857
limit: 20,
4958
offset,
5059
search,
51-
parent: { name: "parent", value: parentId },
60+
filterQuery: {
61+
parent__ids: [parentId],
62+
},
5263
});
5364
expect(result).toEqual([
5465
{
@@ -87,7 +98,7 @@ describe("getRelationships", () => {
8798
limit: 20,
8899
offset: undefined,
89100
search: undefined,
90-
parent: undefined,
101+
filterQuery: undefined,
91102
});
92103
expect(result).toEqual([]);
93104
});

frontend/app/src/entities/nodes/relationships/domain/get-relationships/get-relationships.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
import { getRelationshipsFromApi } from "@/entities/nodes/relationships/api/get-relationships-from-api";
1+
import {
2+
getRelationshipsFromApi,
3+
getRelationshipsFromApiParams,
4+
} from "@/entities/nodes/relationships/api/get-relationships-from-api";
25
import { RelationshipNode } from "@/entities/nodes/relationships/domain/types";
3-
import { ContextParams, PaginationParams } from "@/shared/api/types";
46

57
////////////////////////////////////////////////////////////////////////////////////////////////////
68

79
export const RELATIONSHIPS_PER_PAGE = 20;
810

911
////////////////////////////////////////////////////////////////////////////////////////////////////
1012

11-
export type GetRelationshipsParams = ContextParams &
12-
PaginationParams & {
13-
peer: string;
14-
search?: string;
15-
parentId?: string;
16-
};
13+
export type GetRelationshipsParams = getRelationshipsFromApiParams;
1714

1815
export type GetRelationships = (params: GetRelationshipsParams) => Promise<Array<RelationshipNode>>;
1916

@@ -24,7 +21,7 @@ export const getRelationships: GetRelationships = async ({
2421
offset,
2522
peer,
2623
search,
27-
parentId,
24+
filterQuery,
2825
}) => {
2926
const { data } = await getRelationshipsFromApi({
3027
peer,
@@ -33,7 +30,7 @@ export const getRelationships: GetRelationships = async ({
3330
search,
3431
branchName,
3532
atDate,
36-
parent: parentId ? { name: "parent", value: parentId } : undefined,
33+
filterQuery,
3734
});
3835

3936
const relationshipsData = data[peer];

frontend/app/src/entities/nodes/relationships/ui/relationship-combobox-list.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,31 @@ import { useRelationships } from "@/entities/nodes/relationships/domain/get-rela
22
import { RelationshipNode } from "@/entities/nodes/relationships/domain/types";
33
import { useSchema } from "@/entities/schema/ui/hooks/useSchema";
44
import ErrorScreen from "@/shared/components/errors/error-screen";
5-
import { ComboboxEmpty, ComboboxItem, ComboboxList } from "@/shared/components/ui/combobox";
5+
import {
6+
ComboboxEmpty,
7+
ComboboxItem,
8+
ComboboxList,
9+
ComboboxListProps,
10+
} from "@/shared/components/ui/combobox";
611
import { Spinner } from "@/shared/components/ui/spinner";
712
import { debounce } from "@/shared/utils/common";
813
import React, { forwardRef } from "react";
914

10-
export interface RelationshipComboboxListProps {
15+
export interface RelationshipComboboxListProps
16+
extends Omit<ComboboxListProps, "value" | "onSelect"> {
1117
peer: string;
1218
onSelect: (value: RelationshipNode) => void;
1319
value?: RelationshipNode | null;
1420
filterItem?: (relationshipNode: RelationshipNode) => boolean;
21+
filterQuery?: Record<string, string | number | boolean | string[]>;
1522
}
1623

1724
export const RelationshipComboboxList = forwardRef<HTMLDivElement, RelationshipComboboxListProps>(
18-
({ peer, value, onSelect, filterItem }, ref) => {
25+
({ peer, value, onSelect, filterItem, filterQuery, ...props }, ref) => {
1926
const [search, setSearch] = React.useState("");
2027
const { schema } = useSchema(peer);
2128
const { isPending, data, error, fetchNextPage, hasNextPage, isFetchingNextPage } =
22-
useRelationships({ peer, search });
29+
useRelationships({ peer, search, filterQuery });
2330

2431
if (error) return <ErrorScreen message={error.message} />;
2532

@@ -30,6 +37,7 @@ export const RelationshipComboboxList = forwardRef<HTMLDivElement, RelationshipC
3037
ref={ref}
3138
onValueChange={(newValue) => setSearchDebounced(newValue)}
3239
shouldFilter={false}
40+
{...props}
3341
>
3442
{isPending ? (
3543
<Spinner className="flex justify-center m-2" />

frontend/app/src/entities/nodes/relationships/ui/relationship-hierarchical-combobox-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ const HierarchicalExplorer = ({
8181
})
8282
: getRelationshipsInfiniteQueryOptions({
8383
peer: peer as string,
84-
parentId: topLevelNode?.id,
8584
branchName,
85+
...(topLevelNode ? { filterQuery: { parent__ids: [topLevelNode.id] } } : {}),
8686
});
8787

8888
const { isPending, data, error, fetchNextPage, hasNextPage, isFetchingNextPage } =

frontend/app/tests/e2e/role-management/read.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test.describe("Role management - READ", () => {
1010
});
1111

1212
await test.step("check counts", async () => {
13-
await expect(page.getByRole("link", { name: "Accounts 12" })).toBeVisible();
13+
await expect(page.getByRole("link", { name: "Accounts 13" })).toBeVisible();
1414
await expect(page.getByRole("link", { name: "Groups 6" })).toBeVisible();
1515
await expect(page.getByRole("link", { name: "Roles 7" })).toBeVisible();
1616
await expect(page.getByRole("link", { name: "Global Permissions 8" })).toBeVisible();

0 commit comments

Comments
 (0)