From 58622bbf99291841316d80a94f44c5c11f8ce1e7 Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Fri, 9 Dec 2022 11:34:26 +0200 Subject: [PATCH] Fix/change request search (#2647) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes bug in Project Change Requests Tab Search ## About the changes Closes # ### Important files ## Discussion points Signed-off-by: andreas-unleash --- .../ChangeRequestsTabs/ChangeRequestsTabs.tsx | 27 ++++++++++++------- .../ProjectChangeRequests.tsx | 12 --------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/frontend/src/component/changeRequest/ProjectChangeRequests/ChangeRequestsTabs/ChangeRequestsTabs.tsx b/frontend/src/component/changeRequest/ProjectChangeRequests/ChangeRequestsTabs/ChangeRequestsTabs.tsx index 8e58404db4..275cd686ab 100644 --- a/frontend/src/component/changeRequest/ProjectChangeRequests/ChangeRequestsTabs/ChangeRequestsTabs.tsx +++ b/frontend/src/component/changeRequest/ProjectChangeRequests/ChangeRequestsTabs/ChangeRequestsTabs.tsx @@ -24,24 +24,21 @@ import { AvatarCell } from './AvatarCell/AvatarCell'; import { ChangeRequestTitleCell } from './ChangeRequestTitleCell/ChangeRequestTitleCell'; import { TableBody, TableRow } from '../../../common/Table'; import { useStyles } from './ChangeRequestsTabs.styles'; +import { createLocalStorage } from '../../../../utils/createLocalStorage'; export interface IChangeRequestTableProps { changeRequests: any[]; loading: boolean; - storedParams: SortingRule; - setStoredParams: ( - newValue: - | SortingRule - | ((prev: SortingRule) => SortingRule) - ) => SortingRule; projectId: string; } +const defaultSort: SortingRule & { + columns?: string[]; +} = { id: 'createdAt' }; + export const ChangeRequestsTabs = ({ changeRequests = [], loading, - storedParams, - setStoredParams, projectId, }: IChangeRequestTableProps) => { const { classes } = useStyles(); @@ -52,6 +49,9 @@ export const ChangeRequestsTabs = ({ searchParams.get('search') || '' ); + const { value: storedParams, setValue: setStoredParams } = + createLocalStorage(`${projectId}:ProjectChangeRequest`, defaultSort); + const [openChangeRequests, closedChangeRequests] = useMemo(() => { const open = changeRequests.filter( changeRequest => @@ -109,12 +109,14 @@ export const ChangeRequestsTabs = ({ { Header: 'Environment', accessor: 'environment', + searchable: true, maxWidth: 100, Cell: TextCell, }, { Header: 'Status', accessor: 'state', + searchable: true, minWidth: 150, width: 150, Cell: ChangeRequestStatusCell, @@ -194,8 +196,13 @@ export const ChangeRequestsTabs = ({ setSearchParams(tableState, { replace: true, }); - setStoredParams({ id: sortBy[0].id, desc: sortBy[0].desc || false }); - }, [loading, sortBy, searchValue]); // eslint-disable-line react-hooks/exhaustive-deps + setStoredParams(params => ({ + ...params, + id: sortBy[0].id, + desc: sortBy[0].desc || false, + })); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [loading, sortBy, searchValue, setSearchParams]); return ( = { id: 'updatedAt', desc: true }; - export const ProjectChangeRequests = () => { const projectId = useRequiredPathParam('projectId'); const projectName = useProjectNameOrId(projectId); @@ -21,11 +16,6 @@ export const ProjectChangeRequests = () => { const { changeRequests, loading } = useProjectChangeRequests(projectId); - const { value, setValue } = createLocalStorage( - `${projectId}:ProjectChangeRequest`, - defaultSort - ); - if (isOss() || isPro()) { return ( @@ -37,8 +27,6 @@ export const ProjectChangeRequests = () => { return (