From 5c762f3583dc0c33d8dac0d460af1e627f7bda3d Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Thu, 21 Dec 2023 11:59:17 +0530 Subject: [PATCH] Implement filtering repositories by name and account (#18) * Filter repositories according to title * Add style to project repo card * Filter repositories through title and user * Update project repository card for user --------- Co-authored-by: neeraj --- .../frontend/src/assets/repositories.json | 30 ++++--- .../projects/create/ProjectRepoCard.tsx | 16 +++- .../projects/create/RepositoryList.tsx | 87 +++++++++++++++---- .../projects/create/TemplateCard.tsx | 22 +++-- .../project/deployments/FilterForm.tsx | 1 - 5 files changed, 114 insertions(+), 42 deletions(-) diff --git a/packages/frontend/src/assets/repositories.json b/packages/frontend/src/assets/repositories.json index a1f5d644..f9364789 100644 --- a/packages/frontend/src/assets/repositories.json +++ b/packages/frontend/src/assets/repositories.json @@ -1,26 +1,32 @@ [ { - "title": "Project-101", - "updatedTime": "2023-05-15T08:30:00" + "title": "project-101", + "updatedAt": "2023-12-21T08:30:00", + "user": "bob" }, { - "title": "Project-102", - "updatedTime": "2023-05-15T08:30:00" + "title": "project-102", + "updatedAt": "2023-12-21T08:30:00", + "user": "alice" }, { - "title": "Project-103", - "updatedTime": "2023-12-11T04:20:00" + "title": "project-103", + "updatedAt": "2023-12-21T04:20:00", + "user": "charlie" }, { - "title": "Project-104", - "updatedTime": "2023-12-11T04:27:00" + "title": "project-104", + "updatedAt": "2023-12-21T04:27:00", + "user": "alice" }, { - "title": "Project-105", - "updatedTime": "2023-12-11T04:41:00" + "title": "project-105", + "updatedAt": "2023-12-21T04:41:00", + "user": "ivan" }, { - "title": "Project-106", - "updatedTime": "2023-12-11T04:32:00" + "title": "project-106", + "updatedAt": "2023-12-21T04:32:00", + "user": "david" } ] diff --git a/packages/frontend/src/components/projects/create/ProjectRepoCard.tsx b/packages/frontend/src/components/projects/create/ProjectRepoCard.tsx index 3aa1b305..3b06ac3e 100644 --- a/packages/frontend/src/components/projects/create/ProjectRepoCard.tsx +++ b/packages/frontend/src/components/projects/create/ProjectRepoCard.tsx @@ -1,10 +1,13 @@ import React from 'react'; +import { IconButton } from '@material-tailwind/react'; + import { relativeTime } from '../../../utils/time'; interface RepositoryDetails { title: string; - updatedTime: string; + updatedAt: string; + user: string; } interface ProjectRepoCardProps { @@ -13,11 +16,16 @@ interface ProjectRepoCardProps { const ProjectRepoCard: React.FC = ({ repository }) => { return ( -
+
^
-

{repository.title}

-

{relativeTime(repository.updatedTime)}

+

+ {repository.user}/{repository.title} +

+

{relativeTime(repository.updatedAt)}

+
+
+ {'>'}
); diff --git a/packages/frontend/src/components/projects/create/RepositoryList.tsx b/packages/frontend/src/components/projects/create/RepositoryList.tsx index cecd0fa8..63a8e783 100644 --- a/packages/frontend/src/components/projects/create/RepositoryList.tsx +++ b/packages/frontend/src/components/projects/create/RepositoryList.tsx @@ -1,34 +1,87 @@ -import React from 'react'; +import React, { useCallback, useMemo, useState } from 'react'; + +import { Button, Typography, Option, Select } from '@material-tailwind/react'; import SearchBar from '../../SearchBar'; import ProjectRepoCard from './ProjectRepoCard'; import repositoryDetails from '../../../assets/repositories.json'; -import Dropdown from '../../Dropdown'; -const ACCOUNT_OPTIONS = [ - { value: 'alice', label: 'Alice' }, - { value: 'bob', label: 'Bob' }, - { value: 'charlie', label: 'Charlie' }, -]; +const DEFAULT_SEARCHED_REPO = ''; +const DEFAULT_SELECTED_USER = 'All accounts'; const RepositoryList = () => { + const [searchedRepo, setSearchedRepo] = useState(DEFAULT_SEARCHED_REPO); + const [selectedUser, setSelectedUser] = useState(DEFAULT_SELECTED_USER); + + const filteredRepos = useMemo(() => { + return repositoryDetails.filter((repo) => { + const titleMatch = + !searchedRepo || + repo.title.toLowerCase().includes(searchedRepo.toLowerCase()); + const userMatch = + selectedUser === DEFAULT_SELECTED_USER || selectedUser === repo.user; + return titleMatch && userMatch; + }); + }, [searchedRepo, selectedUser]); + + const handleResetFilters = useCallback(() => { + setSearchedRepo(DEFAULT_SEARCHED_REPO); + setSelectedUser(DEFAULT_SELECTED_USER); + }, []); + + const users = useMemo(() => { + return [ + DEFAULT_SELECTED_USER, + ...Array.from(new Set(repositoryDetails.map((repo) => repo.user))), + ]; + }, []); + return (
-
+
- {}} - /> +
- {}} placeholder="Search for repository" /> + setSearchedRepo(event.target.value)} + placeholder="Search for repository" + />
- {repositoryDetails.map((repo, key) => { - return ; - })} + {Boolean(filteredRepos.length) ? ( + filteredRepos.map((repo, key) => { + return ; + }) + ) : ( +
+
+ No repository found + +
+
+ )}
); }; diff --git a/packages/frontend/src/components/projects/create/TemplateCard.tsx b/packages/frontend/src/components/projects/create/TemplateCard.tsx index 30feaec5..6033da1f 100644 --- a/packages/frontend/src/components/projects/create/TemplateCard.tsx +++ b/packages/frontend/src/components/projects/create/TemplateCard.tsx @@ -1,5 +1,7 @@ import React from 'react'; +import { IconButton } from '@material-tailwind/react'; + import { Link } from 'react-router-dom'; interface TemplateDetails { @@ -12,15 +14,19 @@ interface TemplateCardProps { const TemplateCard: React.FC = ({ framework }) => { return ( -
-
- {framework.icon} - {framework.framework} + +
+
+ {framework.icon} + {framework.framework} +
+
+ + {'>'} + +
- - - -
+ ); }; diff --git a/packages/frontend/src/components/projects/project/deployments/FilterForm.tsx b/packages/frontend/src/components/projects/project/deployments/FilterForm.tsx index 26366ab7..f4fec28f 100644 --- a/packages/frontend/src/components/projects/project/deployments/FilterForm.tsx +++ b/packages/frontend/src/components/projects/project/deployments/FilterForm.tsx @@ -57,7 +57,6 @@ const FilterForm = ({ value, onChange }: FilterFormProps) => {