1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Fix/change request search (#2647)

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
Fixes bug in Project Change Requests Tab Search
## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
andreas-unleash 2022-12-09 11:34:26 +02:00 committed by GitHub
parent f42404405d
commit 58622bbf99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 22 deletions

View File

@ -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<string>;
setStoredParams: (
newValue:
| SortingRule<string>
| ((prev: SortingRule<string>) => SortingRule<string>)
) => SortingRule<string>;
projectId: string;
}
const defaultSort: SortingRule<string> & {
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 (
<PageContent

View File

@ -1,17 +1,12 @@
import { usePageTitle } from 'hooks/usePageTitle';
import { createLocalStorage } from 'utils/createLocalStorage';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
import { useProjectNameOrId } from 'hooks/api/getters/useProject/useProject';
import { ChangeRequestsTabs } from './ChangeRequestsTabs/ChangeRequestsTabs';
import { SortingRule } from 'react-table';
import { useProjectChangeRequests } from 'hooks/api/getters/useProjectChangeRequests/useProjectChangeRequests';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { PageContent } from 'component/common/PageContent/PageContent';
import { PageHeader } from 'component/common/PageHeader/PageHeader';
import { PremiumFeature } from 'component/common/PremiumFeature/PremiumFeature';
const defaultSort: SortingRule<string> = { 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 (
<PageContent sx={{ justifyContent: 'center' }}>
@ -37,8 +27,6 @@ export const ProjectChangeRequests = () => {
return (
<ChangeRequestsTabs
changeRequests={changeRequests}
storedParams={value}
setStoredParams={setValue}
projectId={projectId}
loading={loading}
/>