From 55de43ad072b4a42ac5d11d721bb8110b07230bc Mon Sep 17 00:00:00 2001 From: Youssef Date: Mon, 28 Feb 2022 17:00:12 +0100 Subject: [PATCH] feat: add search in projects --- frontend/src/component/menu/routes.js | 2 +- .../project/ProjectList/ProjectList.styles.ts | 16 ++++++ .../project/ProjectList/ProjectList.tsx | 56 ++++++++++++------- 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/frontend/src/component/menu/routes.js b/frontend/src/component/menu/routes.js index 7f87060541..f44e2451b8 100644 --- a/frontend/src/component/menu/routes.js +++ b/frontend/src/component/menu/routes.js @@ -15,7 +15,7 @@ import { P, C, E, EEA, RE } from '../common/flags'; import { NewUser } from '../user/NewUser/NewUser'; import ResetPassword from '../user/ResetPassword/ResetPassword'; import ForgottenPassword from '../user/ForgottenPassword/ForgottenPassword'; -import ProjectListNew from '../project/ProjectList/ProjectList'; +import { ProjectListNew } from '../project/ProjectList/ProjectList'; import Project from '../project/Project/Project'; import RedirectArchive from '../archive/RedirectArchive'; import EnvironmentList from '../environments/EnvironmentList/EnvironmentList'; diff --git a/frontend/src/component/project/ProjectList/ProjectList.styles.ts b/frontend/src/component/project/ProjectList/ProjectList.styles.ts index 2b3bfb963e..9fcd2f1980 100644 --- a/frontend/src/component/project/ProjectList/ProjectList.styles.ts +++ b/frontend/src/component/project/ProjectList/ProjectList.styles.ts @@ -21,4 +21,20 @@ export const useStyles = makeStyles(theme => ({ fontFamily: theme.typography.fontFamily, pointer: 'cursor', }, + searchBarContainer: { + marginBottom: '2rem', + display: 'flex', + gap: '1rem', + justifyContent: 'space-between', + alignItems: 'center', + [theme.breakpoints.down('xs')]: { + display: 'block', + }, + }, + searchBar: { + minWidth: '450px', + [theme.breakpoints.down('xs')]: { + minWidth: '100%', + }, + }, })); diff --git a/frontend/src/component/project/ProjectList/ProjectList.tsx b/frontend/src/component/project/ProjectList/ProjectList.tsx index d4afcb3bcd..18d92d79c7 100644 --- a/frontend/src/component/project/ProjectList/ProjectList.tsx +++ b/frontend/src/component/project/ProjectList/ProjectList.tsx @@ -1,24 +1,24 @@ -import { useContext, useState } from 'react'; +import { useContext, useMemo, useState } from 'react'; import { Link, useHistory } from 'react-router-dom'; import { mutate } from 'swr'; -import { getProjectFetcher } from '../../../hooks/api/getters/useProject/getProjectFetcher'; -import useProjects from '../../../hooks/api/getters/useProjects/useProjects'; -import ConditionallyRender from '../../common/ConditionallyRender'; +import { getProjectFetcher } from 'hooks/api/getters/useProject/getProjectFetcher'; +import useProjects from 'hooks/api/getters/useProjects/useProjects'; +import ConditionallyRender from 'component/common/ConditionallyRender/ConditionallyRender'; import ProjectCard from '../ProjectCard/ProjectCard'; import { useStyles } from './ProjectList.styles'; -import { IProjectCard } from '../../../interfaces/project'; - +import { IProjectCard } from 'interfaces/project'; import loadingData from './loadingData'; -import useLoading from '../../../hooks/useLoading'; -import PageContent from '../../common/PageContent'; -import AccessContext from '../../../contexts/AccessContext'; -import HeaderTitle from '../../common/HeaderTitle'; -import ResponsiveButton from '../../common/ResponsiveButton/ResponsiveButton'; -import { CREATE_PROJECT } from '../../providers/AccessProvider/permissions'; - +import useLoading from 'hooks/useLoading'; +import PageContent from 'component/common/PageContent'; +import AccessContext from 'contexts/AccessContext'; +import HeaderTitle from 'component/common/HeaderTitle'; +import ResponsiveButton from 'component/common/ResponsiveButton/ResponsiveButton'; +import { CREATE_PROJECT } from 'component/providers/AccessProvider/permissions'; import { Add } from '@material-ui/icons'; -import ApiError from '../../common/ApiError/ApiError'; -import useUiConfig from '../../../hooks/api/getters/useUiConfig/useUiConfig'; +import ApiError from 'component/common/ApiError/ApiError'; +import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; +import { SearchField } from 'component/common/SearchField/SearchField'; +import classnames from 'classnames'; type projectMap = { [index: string]: boolean; @@ -43,7 +43,7 @@ function resolveCreateButtonData(isOss: boolean, hasAccess: boolean) { } } -const ProjectListNew = () => { +export const ProjectListNew = () => { const { hasAccess } = useContext(AccessContext); const history = useHistory(); const styles = useStyles(); @@ -51,6 +51,14 @@ const ProjectListNew = () => { const [fetchedProjects, setFetchedProjects] = useState({}); const ref = useLoading(loading); const { isOss } = useUiConfig(); + const [filter, setFilter] = useState(''); + + const filteredProjects = useMemo(() => { + const regExp = new RegExp(filter, 'i'); + return filter + ? projects?.filter(project => regExp.test(project?.name)) + : projects; + }, [projects, filter]); const handleHover = (projectId: string) => { if (fetchedProjects[projectId]) { @@ -82,7 +90,7 @@ const ProjectListNew = () => { return renderLoading(); } - return projects.map((project: IProjectCard) => { + return filteredProjects?.map((project: IProjectCard) => { return ( { return (
+
+ +
{
No projects available.
} elseShow={renderProjects()} /> @@ -157,5 +175,3 @@ const ProjectListNew = () => {
); }; - -export default ProjectListNew;