From e90c0a473818e9632543ef2c07ea1b129e331f1c Mon Sep 17 00:00:00 2001 From: Lisa Kim Date: Mon, 17 Jun 2024 23:04:09 -0700 Subject: [PATCH 1/2] Connect: fix access request searching logic --- .../AccessRequests/NewRequest/matcher.ts | 40 +++++++++++++++++++ .../RequestList/RequestList.tsx | 19 +-------- 2 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 web/packages/shared/components/AccessRequests/NewRequest/matcher.ts diff --git a/web/packages/shared/components/AccessRequests/NewRequest/matcher.ts b/web/packages/shared/components/AccessRequests/NewRequest/matcher.ts new file mode 100644 index 0000000000000..2de9a9e0b23db --- /dev/null +++ b/web/packages/shared/components/AccessRequests/NewRequest/matcher.ts @@ -0,0 +1,40 @@ +/** + * Teleport + * Copyright (C) 2024 Gravitational, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import { AccessRequest, Resource } from 'shared/services/accessRequests'; + +export function requestMatcher( + targetValue: any, + searchValue: string, + propName: keyof AccessRequest & string +) { + if (propName === 'roles') { + return targetValue.some((role: string) => + role.toUpperCase().includes(searchValue) + ); + } + + if (propName === 'resources') { + return targetValue.some((r: Resource) => + Object.values(r.id) + .concat(Object.values(r.details.hostname || {})) + .concat(Object.values(r.details.friendlyName || {})) + .some(v => v.toUpperCase().includes(searchValue)) + ); + } +} diff --git a/web/packages/teleterm/src/ui/DocumentAccessRequests/RequestList/RequestList.tsx b/web/packages/teleterm/src/ui/DocumentAccessRequests/RequestList/RequestList.tsx index ea43b8d82b773..a349c5019dcf4 100644 --- a/web/packages/teleterm/src/ui/DocumentAccessRequests/RequestList/RequestList.tsx +++ b/web/packages/teleterm/src/ui/DocumentAccessRequests/RequestList/RequestList.tsx @@ -36,6 +36,7 @@ import { BlockedByStartTimeButton, ButtonPromotedInfo, } from 'shared/components/AccessRequests/Shared/Shared'; +import { requestMatcher } from 'shared/components/AccessRequests/NewRequest/matcher'; export function RequestList({ attempt, @@ -142,24 +143,6 @@ export function RequestList({ ); } -function requestMatcher( - targetValue: any, - searchValue: string, - propName: keyof AccessRequest & string -) { - if (propName === 'roles') { - return targetValue.some((role: string) => - role.toUpperCase().includes(searchValue) - ); - } - - if (propName === 'resources') { - return targetValue.some((r: any) => - Object.keys(r).some(k => r[k].toUpperCase().includes(searchValue)) - ); - } -} - const renderActionCell = ( request: AccessRequest, flags: RequestFlags, From b1c08697b50efa5d18b2d1f6a8721b0df904f359 Mon Sep 17 00:00:00 2001 From: Lisa Kim Date: Mon, 24 Jun 2024 12:16:30 -0700 Subject: [PATCH 2/2] Add TODO comment --- .../shared/components/AccessRequests/NewRequest/matcher.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/packages/shared/components/AccessRequests/NewRequest/matcher.ts b/web/packages/shared/components/AccessRequests/NewRequest/matcher.ts index 2de9a9e0b23db..606a541f60e02 100644 --- a/web/packages/shared/components/AccessRequests/NewRequest/matcher.ts +++ b/web/packages/shared/components/AccessRequests/NewRequest/matcher.ts @@ -18,10 +18,14 @@ import { AccessRequest, Resource } from 'shared/services/accessRequests'; +// TODO +// places that use this need to be replaced with server-side filtering like +// done in RequestList.tsx: +// https://github.com/gravitational/teleport.e/blob/a776b3e65e6e8e11ca6938025e63fc3676238fb2/web/teleport/src/Workflow/ReviewRequests/RequestList/RequestList.tsx#L72 export function requestMatcher( targetValue: any, searchValue: string, - propName: keyof AccessRequest & string + propName: keyof AccessRequest ) { if (propName === 'roles') { return targetValue.some((role: string) =>