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 (