Skip to content

Commit

Permalink
Fix/change request search (#2647)
Browse files Browse the repository at this point in the history
<!-- 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>
  • Loading branch information
andreas-unleash committed Dec 9, 2022
1 parent f424044 commit 58622bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
Expand Up @@ -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();
Expand All @@ -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 =>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
@@ -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);
Expand All @@ -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' }}>
Expand All @@ -37,8 +27,6 @@ export const ProjectChangeRequests = () => {
return (
<ChangeRequestsTabs
changeRequests={changeRequests}
storedParams={value}
setStoredParams={setValue}
projectId={projectId}
loading={loading}
/>
Expand Down

0 comments on commit 58622bb

Please sign in to comment.